Hiring a unit which spawns somewhere else

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
I am making a map where you hire troops that then spawn in a different location. To hire them you click on their icon like a mercenary camp, but instead of them spawning by the mercenary camp they spawn at a region. How do i do this, +rep for the answer :)
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
If you have a Region (Use Region pallette) named 'SomeRect'

Make a trigger that fires "When a unit sells a unit" or "When unit is sold"

Then, conditions can be, like, "Sold unit equal to Hero" "Sold unit equal to Something"

Trigger:
  • Actions:
    • Custom Script: local u = GetSoldUnit()
    • Custom Script: call SetUnitPostion(u, GetRectCenterX(gg_rct_SomeRect), GetRectCenterY(gg_rct_SomeRect))
    • Custom Script: set u = null


You can even select the unit for the player or Pan the camera to the X-Y co-ordinate
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
Would that work if i put something like

Order last sold unit to attack move to X

?
 

Wummi

Just Relax and Smile!
Reaction score
58
Something like this:
Create a region called Region 01 around your mercenary camp then do this trigger:
Events-
A unit enters Region 01
Conditions-
Triggering unit equals to (The Unit you want to move)
Actions-
Unit - Move (triggering unit) instantly to (Your Desired Region)

Or something like this if it fits your situation:
Events-
A unit enters Region 01
Conditions-
Triggering unit belongs to Player Red
Unit type of Triggering Unit not equal to Hero
Actions-
Unit - Move (triggering unit) instantly to (Your Desired Region)
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
mmm not what im looking for

i made this, will this work and is there any leaks?

Trigger:
  • Player1 Hire
    • Events
      • Unit - A unit owned by Player 1 (Red) Sells a unit
    • Conditions
    • Actions
      • Unit - Create 1 (Unit-type of (Sold unit)) for Player 1 (Red) at (Center of Player 1 Spawn Point <gen>) facing Default building facing degrees
      • Set HireUnit[1] = (Last created unit)
      • Unit - Remove (Sold unit) from the game
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Castle 0002 <gen> is alive) Equal to True
        • Then - Actions
          • Unit - Order HireUnit[1] to Attack-Move To (Center of Player 3 Spawn Point <gen>)
        • Else - Actions
          • Unit - Order HireUnit[1] to Attack-Move To (Center of Target[1])


The map is multiplayer so im concerned about the trigger getting mixed up if more then 1 person buys a unit at the same time :S theres 4 people
 

hunterrravyn

TH.net Regular
Reaction score
19
Trigger:
  • Actions
    • Custom Script: set udg_HireUnit[1] = null


This doesn't really matter much depending on how often a unit is hired. If left once, it will cause a single leak, really not much to worry about. Of course this is doe after you declare everything with it.
 

Rathma666

New Member
Reaction score
0
this is much simpler and much faster, works everytime gaurenteed

Untitled Trigger 002
Events
Unit - A unit Sells a unit
Conditions
(Unit-type of (Triggering unit)) Equal to Mercenary Camp (Lordaeron Summer)
Actions
Unit - Move (Sold unit) instantly to (Center of Spawn Region <gen>)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Farm 0049 <gen> is alive) Equal to True
Then - Actions
Unit - Order (Sold unit) to Attack-Move To (Center of (Playable map area))
Else - Actions
Unit - Order (Sold unit) to Attack-Move To (Center of Reigion 2 <gen>)


Then you can just sub the mercenary camp for whatever custom structure you want. its that simple.
 

Seprest

New Member
Reaction score
15
mmm not what im looking for

i made this, will this work and is there any leaks?

Trigger:
  • Player1 Hire
    • Events
      • Unit - A unit owned by Player 1 (Red) Sells a unit
    • Conditions
    • Actions
      • Unit - Create 1 (Unit-type of (Sold unit)) for Player 1 (Red) at (Center of Player 1 Spawn Point &lt;gen&gt;) facing Default building facing degrees
      • Set HireUnit[1] = (Last created unit)
      • Unit - Remove (Sold unit) from the game
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Castle 0002 &lt;gen&gt; is alive) Equal to True
        • Then - Actions
          • Unit - Order HireUnit[1] to Attack-Move To (Center of Player 3 Spawn Point &lt;gen&gt;)
        • Else - Actions
          • Unit - Order HireUnit[1] to Attack-Move To (Center of Target[1])


The map is multiplayer so im concerned about the trigger getting mixed up if more then 1 person buys a unit at the same time :S theres 4 people

Why would it get messed up if more than one player buys a unit at the same time? It should just "bump" one of the two units to the side if they are being created at the same place before the first unit's collision box is out of the way.


Also as stated above, >>>> Unit - Move (Sold unit) instantly to (Center of Spawn Region <gen>) <<<< should clear up your script, unless you want to modify your script to keep a running array of created units ~_o
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Sells a unit
    • Conditions
    • Actions
      • Set TmpPnt = (Center of (Playable map area))
      • Unit - Move (Triggering unit) instantly to TmpPnt
      • Custom script: call RemoveLocation (udg_TmpPnt)

any smaller and you would get memory leaks.

however this is the basic trigger, all you want to add is up to you. (like for example checking the selling/sold units type, the owner of the selling/sold unit, the rect/point. whatever...)
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
I used the one i put, didnt check back so havnt cleared anything up and after multiple play throughs - some lasting for 30 minutes - i couldnt notice any lag to do with this, actually didnt notice lag full stop ^^ Thanks guys
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top