Help with Code

Shadow

TH.net Regular
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!
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
  • The Helper The Helper:
    his mom is my age
  • The Helper The Helper:
    i know right it was pretty funny
  • thewrongvine thewrongvine:
    its pretty funny
    +1
  • tom_mai78101 tom_mai78101:
    Thanks for the context.
    +1
  • The Helper The Helper:
    Happy Hump Day!!!
  • Blackveiled Blackveiled:
    TH old fart gotta have a beer with me one of these days
  • The Helper The Helper:
    I am down anytime Blackveiled
  • Blackveiled Blackveiled:
    count on it then cause you don't live that far from me hah
  • The Helper The Helper:
    really that is cool!
  • The Helper The Helper:
    Hey Tom I added a new Weird tag to the News Prefixes
  • The Helper The Helper:
    What is up Blackveiled?
  • Blackveiled Blackveiled:
    Chillin', lurkin'. :D
  • The Helper The Helper:
    I am working on a bunch of site projects right now doing a bunch of behind the scenes stuff and trying to clean up some stuff that I let slide when I got lazy with the site for a few years...
  • The Helper The Helper:
    Are you in Houston Blackveiled or just in Texas?
  • Blackveiled Blackveiled:
    Houston
  • Blackveiled Blackveiled:
    I've been living here since 2014.
  • The Helper The Helper:
    OK banlord we need to get together soon! The only other member of the site I know in Houston is XXX Conan
  • The Helper The Helper:
    and he does not want none lol
  • The Helper The Helper:
    he put up a picture of his mom one time and she was HOT!
  • The Helper The Helper:
    I wish we still had that
  • Blackveiled Blackveiled:
    Lmao you scared him off I see.
  • The Helper The Helper:
    he will be back
  • The Helper The Helper:
    Conan was like 12 when he started here
  • The Helper The Helper:
    I literally think I was his male role model

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top