TriggerRegisterUnitStateEvent problem

Magoiche

Member
Reaction score
20
I made this trigger to remove the spell when deactivate the skill.
But now i noticed that if the mana ends the skill is deactivated but the other skill don't get removed. x.x

I tried to the trigger to run too when the unit as 6 mana or less.

JASS:
scope InsanityDeactivation initializer Initial

private function Conditions takes nothing returns boolean
    if ( GetIssuedOrderId() == String2OrderIdBJ("unimmolation") ) then
        return true
    else
        return false
    endif
endfunction

private function Actions takes nothing returns nothing
    call UnitRemoveAbility( GetTriggerUnit(), 'A005' )
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local unit u = GetTriggerUnit()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerRegisterUnitStateEvent( trig, u, UNIT_STATE_MANA, LESS_THAN_OR_EQUAL, 6.00 )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


But it just don't work(The mana part). Why?


Quick Questions

1. String2OrderIdBJ its better use it or inline it?

2. CreateNUnitsAtLoc its better use it or inline it?

3. Whats better/faster?

I.
JASS:

if something then
return true
else
return false
endif


or

II.
JASS:

if something then
return true
endif
return false


Thanks =}
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
But it just don't work(The mana part). Why?
Because GetIssuedOrderId() == 0 with the mana event, so your condition return false, you need to check witch event fire the trigger in your condition, with the function GetTriggerEventId()

1. String2OrderIdBJ its better use it or inline it?
It is one of the useless BJ, so yes use the native one instead

2. CreateNUnitsAtLoc its better use it or inline it?
Most of the time you need to create one unit, so in this case the native one is ofc the best, but if you want to create many i would say why not use this one.
But honestly using locations are in most of cases just useless (need to manage leaks and simply useless since there are the same functions with X/Y arguments witch are faster).
There are only two cases you need a location :

1) GetSpellTargetLoc
2) GetLocationZ

And for the terrain height you can use a global location and the function MoveLocation, instead of create/destroy an other location

3. Whats better/faster?
It should be exactly the same, just choice witch one you prefer.
 

Magoiche

Member
Reaction score
20
I didn't find the native for String2OrderIdBJ.
What is it?

Here shows this:

JASS:
function String2OrderIdBJ takes string orderIdString returns integer
    local integer orderId
    
    // Check to see if it's a generic order.
    set orderId = OrderId(orderIdString)
    if (orderId != 0) then
        return orderId
    endif

    // Check to see if it's a (train) unit order.
    set orderId = UnitId(orderIdString)
    if (orderId != 0) then
        return orderId
    endif

    // Unrecognized - return 0
    return 0
endfunction


About the GetTriggerEventId().
0 will be the first event? In this case TriggerRegisterAnyUnitEventBJ.
Right?
 

Magoiche

Member
Reaction score
20
*autoheadshot*

...
Sorry for that. It was in my face and i don't see it. x.x
Ty

But what about the GetTriggerEventId()?
About the GetTriggerEventId().
0 will be the first event? In this case TriggerRegisterAnyUnitEventBJ.
Right?
 

Azlier

Old World Ghost
Reaction score
461
A serious problem is that the unit you are specifying the event to run for is, for some reason, GetTriggerUnit. In the Initial function. There is no GetTriggerUnit for this function.
 

Magoiche

Member
Reaction score
20
hmmm... lol?

There is no GetTriggerUnit in the initial trigger?
The triggerunit apears where? conditions? x.x

Also thanks Troll-Brain for the GetTriggerEventId help.
 

Azlier

Old World Ghost
Reaction score
461
You use GetTriggerUnit() in the Initial function. No, GetTriggerUnit() does not return the unit that's in your head. In this case, it returns... null?
 

emjlr3

Change can be a good thing
Reaction score
395
your trigger is incomplete, you do nothing if its the mana event, and use some phantom triggerunit

what you need is something like...

JASS:
scope InsanityDeactivation initializer Initial

private struct data
    unit u
    timer t

    method onDestroy takes nothing returns nothing
        call ReleaseTimer(.t)
    endmethod
endstruct

private function Check takes nothing returns nothing
    local data d = GetCSData(GetExpiredTimer())

    if GetUnitState(d.u,UNIT_STATE_MANA)<=6 then // your mana check
        call UnitRemoveAbility(d.u,'A005')
        call d.destroy()
    elseif GetUnitAbilityLevel(d.u,'A005')<1 then // incase our order trigger removed it
        call d.destroy()
    endif
endfunction
private function Conditions takes nothing returns boolean
    local data d

    if GetIssuedOrder() == "unimmolation"  then
        call UnitRemoveAbility( GetTriggerUnit(), 'A005' )
    elseif GetIssuedOrder() == "immolation"
        // since your removing it at some point and I assume you add it initially, lets do some fun stuff here to run the mana check
        set d = data.create()
        set d.t = NewTimer()
        set d.u = GetTriggerUnit()
        call TimerStart(d.t,.2,true,function Check)
        call SetCSData(d.t,d)

        call UnitAddAbility(d.u,'A005')
    endif

    return false
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
endfunction

endscope
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
@emjlr3 : you have forgotten to say that you are using the library TimerUtils in your example.
And also CS_data, but i dunno about that, i don't use it.
 

Magoiche

Member
Reaction score
20
Hmmm...

Thanks for the trying to help emjlr3
But... Let me say what happened to my brain when i saw your post.

My Brain:

Before: ##
After: &%

x.x
Thanks anyway. I will save it and see if a can learn something later when i finish this trigger.

But now... about the GetTriggerUnit()...
What should i do about that?
A global var(i don't think so i.i)?

Sorry people but i am realy lost at this pont x.x
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
if it's an preplaced unit on the map, you need to select it with a gui action, convert it in jass and copy/paste the global variable.
It will be something like that :

gg_unit_<unitId>_<number>

EDIT : Or you want it for all unit preplaced in the map and will be created after ?
 

Magoiche

Member
Reaction score
20
Right now its a prepaced unit. but its just for testing.
After(in the oficial map) it will be created later.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Right now its a prepaced unit. but its just for testing.
After(in the oficial map) it will be crated later.
Then you have to add the event later in game, since it is a specific unit event.
You can copy the gui fonction to have an idea of how to do it.

And so you need to refer your trigger with a global variable.
 

Magoiche

Member
Reaction score
20
How do i add a event "later"?
copy the gui function... ok... but... what function? the specifc unit event?
 

Magoiche

Member
Reaction score
20
Thanks people you helped me alot.
I learned some things but there still more to learn.

Like:

Why this trigger don't work?

JASS:
scope InsanityShoutDeath initializer Initial

private function Conditions takes nothing returns boolean
    return GetUnitTypeId( GetTriggerUnit() ) == &#039;H000&#039; and GetUnitAbilityLevel( GetTriggerUnit(), &#039;A004&#039; ) &gt; 0
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX( u )
    local real y = GetUnitY( u )
    call CreateUnit( GetOwningPlayer( u ), &#039;u001&#039;, x, y, 0.00 )
    call UnitApplyTimedLife( bj_lastCreatedUnit, &#039;BTLF&#039;, 5.00 )
    call UnitAddAbility( bj_lastCreatedUnit, &#039;A006&#039; )
    call SetUnitAbilityLevel( bj_lastCreatedUnit, &#039;A006&#039;, 2 )
    call IssueImmediateOrder( bj_lastCreatedUnit, &quot;stomp&quot; )
    call AddSpecialEffectLoc( &quot;Abilities\\Spells\\Other\\HowlOfTerror\\HowlCaster.mdl&quot;, GetUnitLoc( bj_lastCreatedUnit ) )
    call DestroyEffect( bj_lastCreatedEffect )
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


when it reach the Timedlife it "stops".

Why?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
bj_ are globals variables using by gui functions.
But the native CreateUnit returns an unit.

So you can do it :

JASS:
local unit u
set u = CreateUnit(...)


or a global unit variable ofc.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top