• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

[JASS] adding and removing an ability in this jass trigger

Status
Not open for further replies.
Level 7
Joined
Jan 1, 2005
Messages
133
Ok basically ive got a bug in my sc maps where when you liftoff the cc can still recieve miners/gas whiles its surpose to be flying. Now i had a guy create a slow lifoff/liftdown trigger system and i realised if i could add a remove ability (return lumber&gold) then i would fix this bug from the game but i dunno how towrite the coding in jass. Anyone help

JASS:
function Trig_Terran_Liftoff_Conditions takes nothing returns boolean
    return GetIssuedOrderId()==OrderId("unroot")    
endfunction

function IncreaseHeight takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local unit u=GetHandleUnit(t,"Structure")
    call SetUnitFlyHeight(u,GetUnitFlyHeight(u)+5,0)
    if GetUnitFlyHeight(u)>200 then
      call FlushStoredHandle(t,"Structure")
      call DestroyTimer(t)
    endif
    set t=null
    set u=null
endfunction

function Trig_Terran_Liftoff_Actions takes nothing returns nothing
    local timer t=CreateTimer()
    call UnitRemoveAbility(u,'A00V')
    call SetHandleHandle(t,"Structure",GetTriggerUnit())
    call SetUnitFlyHeight(GetTriggerUnit(),0,0)
    call TimerStart(t,0.05,true,function IncreaseHeight)
endfunction

//===========================================================================
function InitTrig_Terran_Liftoff takes nothing returns nothing
    set gg_trg_Terran_Liftoff=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Terran_Liftoff,EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_Terran_Liftoff,Condition(function Trig_Terran_Liftoff_Conditions))
    call TriggerAddAction(gg_trg_Terran_Liftoff,function Trig_Terran_Liftoff_Actions)
endfunction

I tried to add the line call UnitRemoveAbility(u,'A00V') but keepo getting a varible error so im guessing im not setting it correctly.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You never declared any unit variable that is called "u".
I suppose the building itself does the unroot so instead of that "u" put "GetTriggerUnit()".

And by the way, instead of using a timer to increase the height, you could just use the normal height action, for example you want to raise to a height of 200 at a 1 second rate, you'll make it like this

JASS:
function Trig_Terran_Liftoff_Conditions takes nothing returns boolean
    return GetIssuedOrderId()==OrderId("unroot")
endfunction
function Trig_Terran_Liftoff_Actions takes nothing returns nothing
    call UnitRemoveAbility(GetTriggerUnit(),'A00V')
    call SetUnitFlyHeight(GetTriggerUnit(),200,200)
endfunction
//===========================================================================
function InitTrig_Terran_Liftoff takes nothing returns nothing
    set gg_trg_Terran_Liftoff=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Terran_Liftoff,EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_Terran_Liftoff,Condition(function Trig_Terran_Liftoff_Conditions))
    call TriggerAddAction(gg_trg_Terran_Liftoff,function Trig_Terran_Liftoff_Actions)
endfunction
 
Level 7
Joined
Jan 1, 2005
Messages
133
You never declared any unit variable that is called "u".
I suppose the building itself does the unroot so instead of that "u" put "GetTriggerUnit()".

And by the way, instead of using a timer to increase the height, you could just use the normal height action, for example you want to raise to a height of 200 at a 1 second rate, you'll make it like this

JASS:
function Trig_Terran_Liftoff_Conditions takes nothing returns boolean
    return GetIssuedOrderId()==OrderId("unroot")
endfunction
function Trig_Terran_Liftoff_Actions takes nothing returns nothing
    call UnitRemoveAbility(GetTriggerUnit(),'A00V')
    call SetUnitFlyHeight(GetTriggerUnit(),200,200)
endfunction
//===========================================================================
function InitTrig_Terran_Liftoff takes nothing returns nothing
    set gg_trg_Terran_Liftoff=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Terran_Liftoff,EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_Terran_Liftoff,Condition(function Trig_Terran_Liftoff_Conditions))
    call TriggerAddAction(gg_trg_Terran_Liftoff,function Trig_Terran_Liftoff_Actions)
endfunction

Cheers thanx ghost, it works now appreciate the help again. Now if only i could change the Attacked as ground to air when it lifts off it will be perfect.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Well, the only solution that was ever found for that was the Crow Form with adding and removing it like this.
This basicly makes the unit to be targeted as a air unit, im not sure however if it will ever become ground again.

JASS:
function Trig_Terran_Liftoff_Conditions takes nothing returns boolean
    return GetIssuedOrderId()==OrderId("unroot")
endfunction
function Trig_Terran_Liftoff_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    UnitAddAbility( u , 'Amrf' )
    UnitRemoveAbility( u , 'Amrf' )
    call UnitRemoveAbility( u , 'A00V' )
    call SetUnitFlyHeight( u , 200 , 200 )
endfunction
//===========================================================================
function InitTrig_Terran_Liftoff takes nothing returns nothing
    set gg_trg_Terran_Liftoff=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Terran_Liftoff,EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_Terran_Liftoff,Condition(function Trig_Terran_Liftoff_Conditions))
    call TriggerAddAction(gg_trg_Terran_Liftoff,function Trig_Terran_Liftoff_Actions)
endfunction
 
Level 7
Joined
Jan 1, 2005
Messages
133
ok i just realised this trigger is for all liftoffable buildings not just the command center. So i either need to add a condition/actions for the commmand center into the liftoff trigger or create a separate GUI trigger.

I just tried it with a GUI and it didnt work.
 
Level 7
Joined
Jan 1, 2005
Messages
133
I wonderd why u're doing this in JASS lol.

What do you mean it doesn't work ? and it doesn't need really need any conditions, unless you want to remove diffrent abilities from each building.

Well becuase this trigger also alloows the barracks/factory and starport to liftoff if i was to add the add/remove mins& gas then those builds would recieve the mins&gas ability after they lifted down meaning you could use them to harvest resources. not good. might just leave it. I dont see it being a huge bug juust thought i could fix this bug now before i release any new verisons. My only other idea was to make two separate buildings 1 that was ground and one that was air and trigger it so when i lifted off i would swap the ground unit for a air unit but i dont think it would work. Thanx anyways for the help ghost.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
My only other idea was to make two separate buildings 1 that was ground and one that was air and trigger it so when i lifted off i would swap the ground unit for a air unit but i dont think it would work. Thanx anyways for the help ghost.

I don't see any reason why it won't work.
It will remove selection from players however and its kinda annoying if a player wants to select it, but they can go to hell :xxd:
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Units given crow form are NOT TARGETTED AS AIR. They are NOT air units. It simply allows you to alter their fly height (and have it show). They remain for all real purposes ground units.

Good to know, this clarifies to me some things.

By the way, if thats the case, wouldn't giving all the units that enter or that on the map the ability and then removing it be nicer then adding and removing each usage of a ability that requires it ?

And a offtopic question, would setting a units life to 0.00 be better then calling him to die with the "KillUnit(unit)" ? (by means of efficient code)
 
Status
Not open for further replies.
Top