• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Need help-trogger is not working

Status
Not open for further replies.
Level 9
Joined
Aug 21, 2008
Messages
533
Just started using hashtables but suddenly trigger doesnt works anymore...

JASS:
function Trig_Schootimg_Actions takes nothing returns nothing
local unit u
local unit u2
local real r
local real r2
local location l
local location l2
set u = GetEventDamageSource()
if ( not ( IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) == false) ) then
set u2 = GetTriggerUnit()
set l = GetUnitLoc(u)
set l2 = GetUnitLoc(u2)
set r2 = AngleBetweenPoints(l,l2)
//set r = LoadRealBJ(StringHashBJ("misslespeed"), StringHashBJ(GetUnitName(GetEventDamageSource())), udg_hashTable)
call CreateUnitAtLoc(GetOwningPlayer(u),LoadIntegerBJ((StringHashBJ("missle")), StringHashBJ(GetUnitName(GetEventDamageSource())), udg_hashTable),l,r2)
set u = GetLastCreatedUnit()
call DisplayTextToForce( GetPlayersAll(), GetUnitName(u) )
call GroupAddUnit(udg_misslegroup,u)
call SaveRealBJ( r, StringHash("missleangle"), GetHandleId(u), udg_hashTable )
call SaveRealBJ( 2.10, StringHash("time"), GetHandleId(u), udg_hashTable )
endif
set u = null
endfunction

//===========================================================================
function InitTrig_Schootimg takes nothing returns nothing
    set gg_trg_Schootimg = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Schootimg, function Trig_Schootimg_Actions )
endfunction

The trigger works till the unit is created, the following lines arent working
 
This is better version of what you have (removed almost all BJ's)
JASS:
function Trig_Schootimg_Actions takes nothing returns nothing
    local unit u = GetEventDamageSource()
    local unit u2 = GetTriggerUnit()
    local unit u3
    local real r //= LoadReal(udg_hashTable, StringHash(GetUnitName(u)), StringHash("misslespeed"))
    local location l = GetUnitLoc(u)
    local location l2 = GetUnitLoc(u2)
    local real r2 = AngleBetweenPoints(l,l2)

    set u3 = CreateUnitAtLoc(GetOwningPlayer(u), LoadInteger( udg_hashTable , StringHash(GetUnitName(u)), StringHash("missle") ), l, r2)
    call DisplayTextToForce( GetPlayersAll(), GetUnitName(u3) )
    call GroupAddUnit(udg_misslegroup,u3)
    call SaveReal( udg_hashTable, GetHandleId(u3), StringHash("missleangle"), r )
    call SaveReal( udg_hashTable, GetHandleId(u3), StringHash("time"), 2.10 )
    
    call RemoveLocation(l)
    call RemoveLocation(l2)
    
    set l = null
    set l2 = null
    set u = null
    set u2 = null
    set u3 = null
endfunction

function Trig_Schootimg_Conditions takes nothing returns boolean
    return IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) == true
endfunction

//===========================================================================
function InitTrig_Schootimg takes nothing returns nothing
    set gg_trg_Schootimg = CreateTrigger( )
    call TriggerAddAction( gg_trg_Schootimg, function Trig_Schootimg_Actions )
    call TriggerAddCondition( gg_trg_Shootimg, Condition(function Trig_Schootimg_Conditions))
endfunction
2 tips, btw:

A) Don't use those ugly whitespaces around parenthesis, like call A( B )B) Use a better variable/trigger naming policy.
C) Read a few tutorials (more), and have a look at some well made spells from members of this community.

EDIT: THe bug was that
JASS:
call CreateUnitAtLoc(GetOwningPlayer(u),LoadIntegerBJ((StringHashBJ("missle")), StringHashBJ(GetUnitName(GetEventDamageSource())), udg_hashTable),l,r2)
set u = GetLastCreatedUnit()
CreateUnitAtLoc & GetLastCreatedUnit don't work. Use what I did instead:
set u = CreateUnitAtLoc(...)
 
cut the condition and just put all of the the actions inside an If-Then(except for the locals), and paste the condition as the condition of the If-Then... because even if you set the variable u into something it still wont work since the trigger condition will run first before the actions...... and BTW I just noticed... the trigger dont have an event....
 
Status
Not open for further replies.
Back
Top