• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Detecting and storing a specific unit on creation

Status
Not open for further replies.
Level 5
Joined
Aug 15, 2007
Messages
145
How do I do this I would like to make a unit in a rect, then order it to move into another rect and when that specific unit enters the rect actions follow. Do i store the unit as a global, if so how because globals are stored at the beginning of the trigger and when it is created i have no knowledge of linking it to a global inside of the action.
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
  • Unit Creation
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of UnitRegion <gen>) facing Default building facing degrees
      • Set UnitVeriable = (Last created unit)
      • Unit - Order UnitVeriable to Move To (Center of (Playable map area))
UnitVeriable is a global veriable that stores the last created unit (eg. Footman) and then actions can be send to the veriable instead of using locals (eg. Triggering Unit, Last Created Unit .. etc)
 
AutoIndex detects out of scope unit events (when a unit enters the map or is created) and gives them a unique id. It's very useful. It also has an addon called StatusEvents that gives you events for "when units resurrect, when units are raised with Animate Dead, when units begin reincarnating, when units finish reincarnatinging, and when transports load and unload units".

They requires vJass.
 
Level 5
Joined
Aug 15, 2007
Messages
145
maybe i post my code it should be more simple.
Here the unit that moves is created, I need to find a way of detecting this unit when it enters another rect to start actions when it is inside it.
JASS:
scope TANKSPAWNWEST initializer Init 


private function Actions takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_Tank_Create)
    local real y = GetRectCenterY(gg_rct_Tank_Create)
    local real x2 = GetRectCenterX(gg_rct_Region_066) 
    local real y2 = GetRectCenterY(gg_rct_Region_066)
    local unit u =CreateUnit(Player(6), 'hmtt',x,y,0.00)// this is the unit name it 'tank'
    call SetUnitInvulnerable( u, true )
    call SetUnitColor( u, ConvertPlayerColor(12) )
    call UnitApplyTimedLife(u, 'BTLF', 40.00)
    call IssuePointOrder (u, "move", x2, y2)
    call EnableTrigger( gg_trg_Tank_Move_Action )
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )

    //call DisableTrigger( t )
    call TriggerRegisterTimerEvent(t, 30.00, true)
   
    call TriggerAddAction( t, function Actions )
    set t = null
endfunction

endscope


Now I need to store that unit so i can use it in this trigger

  • Tank Move Action
    • Events
      • Unit - A unit enters Region 066 <gen>
    • Conditions
      • (Triggering unit) Equal to (Unit from trigger before 'Tank')
    • Actions
      • Unit - Order Tank to Stop
      • Animation - Play Tank's attack animation
      • Special Effect - Create a special effect attached to the origin of Tank using Abilities\Spells\Human\Flare\FlareCaster.mdl
      • Special Effect - Destroy (Last created special effect)
      • Wait 0.40 seconds
      • Set SentinalSpawnCount = (SpawnCount + 1)
      • Set PointPurifier = (Center of WestSpwnBot <gen>)
      • Unit - Create 2 Force for Neutral Passive at PointPurifier facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_PointPurifier)
      • Set PointPurifier = (Center of WestSpwnBot <gen>)
      • Unit - Create 2 Force Ranged for Neutral Passive at PointPurifier facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_PointPurifier)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SentinalSpawnCount Equal to 2
        • Then - Actions
          • Set PointPurifier = (Center of WestSpwnBot <gen>)
          • Unit - Create 1 Mech for Neutral Passive at PointPurifier facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_PointPurifier)
        • Else - Actions
      • Set PointPurifier = (Center of WestSpwnTop <gen>)
      • Unit - Create 2 Force for Neutral Passive at PointPurifier facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_PointPurifier)
      • Set PointPurifier = (Center of WestSpwnTop <gen>)
      • Unit - Create 2 Force Ranged for Neutral Passive at PointPurifier facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_PointPurifier)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SentinalSpawnCount Equal to 2
        • Then - Actions
          • Set PointPurifier = (Center of WestSpwnTop <gen>)
          • Unit - Create 1 Mech for Neutral Passive at PointPurifier facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_PointPurifier)
        • Else - Actions
      • Set TankPoint = (Center of Region 067 <gen>)
      • Unit - Order Tank to Move To TankPoint
      • Custom script: call RemoveLocation(udg_TankPoint)
      • Trigger - Turn on Tank Destroy <gen>
      • Trigger - Turn off (This trigger)
 
Level 11
Joined
Apr 6, 2008
Messages
760
create a unit var (gui one) and save it in jass like this

JASS:
udg_Tank = CreateUnit(...)

then you can use it like this

  • Tank Move Action
  • Events
    • Unit - A unit enters Region 066 <gen>
  • Conditions
    • (Triggering unit) Equal to (Unit from trigger before 'Tank')
  • Actions
    • Unit - Order Tank to Stop
 
Level 5
Joined
Aug 15, 2007
Messages
145
but im converting the trigger to jass, so I just need to detect the unit in jass in the second trigger, or make it into 1 trigger all in jass but i would not know how to check evry .50 seconds if unit is in region in jass.
 
If I set it to a Global, like integer unit = "H353" , will i be able to use it in another trigger?

I have no idea, I thought they "Privatized" them.

Me said:
Globals can be used anywhere... so what he said would work.

They are only made private if you make them private..

private type name = initialize


You should probably try it first before making these assumptions, it would take a minute.
 
Status
Not open for further replies.
Top