Help with Code

Shadow

TH.net Regular
Reaction score
23
Hey was learning the basics of vJass but its been 6 months since I last learned it :)

Need some help removing a unit.

Code:
 scope SunQuan initializer onInit
 
public function ChangeOwner takes nothing returns nothing
    call KillUnit(GetTriggerUnit())
    call SetUnitOwner(GetEnumUnit(), GetOwningPlayer(GetTriggerUnit()), true)
    call SetUnitOwner(GateSpawns_GateCaptain[1], GetOwningPlayer(GetTriggerUnit()), false)
endfunction
 
private function Conditions takes nothing returns boolean
    call ForGroup(armies_Army[1], function ChangeOwner)
    call ForGroup(armies_Army[2], function ChangeOwner)
   
        return false
endfunction
 
private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    call CreateUnit(Player(13), 'H006', -5950, 4400, 270)
    call TriggerRegisterUnitInRange(t, CreateUnit(Player(13),'ncop',-6000,4270,90),100,null)
    call TriggerAddCondition(t,Condition(function Conditions))
    endfunction
endscope

Need to remove the unit created in this line

Code:
call TriggerRegisterUnitInRange(t, CreateUnit(Player(13),'ncop',-6000,4270,90),100,null)

After its happened (units entered range) so I assume i'd put it in here

Code:
public function ChangeOwner takes nothing returns nothing
    call KillUnit(GetTriggerUnit())
    call SetUnitOwner(GetEnumUnit(), GetOwningPlayer(GetTriggerUnit()), true)
    call SetUnitOwner(GateSpawns_GateCaptain[1], GetOwningPlayer(GetTriggerUnit()), false)
endfunction

I think i'd have to somehow set the unit to a variable then use the
RemoveUnit function. But how do I set I know its like "set unit t ="
 

DrEvil

FCRI Associate!
Reaction score
111
I don't have WC3 installed but I remember some...
RegisterUnitInRange will fire when a unit comes in range, the unit that came in range will be the triggering unit.
To remove the unit created here
JASS:
call TriggerRegisterUnitInRange(t, CreateUnit(Player(13),'ncop',-6000,4270,90),100,null)

A global variable should be created for it:
JASS:
// this is not the whole trigger, just the changed parts.
globals
private unit mainUnit//this is the 'registered' unit
endglobals
 
public function ChangeOwner takes nothing returns nothing
call KillUnit(GetTriggerUnit())
call SetUnitOwner(GetEnumUnit(), GetOwningPlayer(GetTriggerUnit()), true)
call SetUnitOwner(GateSpawns_GateCaptain[1], GetOwningPlayer(GetTriggerUnit()), false)
call RemoveUnit(mainUnit)// remove the original unit
set mainUnit=null// remove something... long time since w3 days -_-
endfunction
 
private function onInit takes nothing returns nothing
local trigger t =CreateTrigger()
call CreateUnit(Player(13),'H006',-5950,4400,270)
set mainUnit=CreateUnit(Player(13),'ncop',-6000,4270,90)//set the global unit
call TriggerRegisterUnitInRange(t,mainUnit,100,null)// register global unit
call TriggerAddCondition(t,Condition(function Conditions))
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top