• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

TRIGGER request

Status
Not open for further replies.
Level 4
Joined
Feb 25, 2010
Messages
73
Hello people! Someone can do for me a trigger that allow me limit the max number of a specific existing unit in the map (eliminating the oldest one when the limit is break)

Basically, i have a unit in my map that can build little attacking turrets, however, i want limit this turrets, so, the player only can have X of them in the map at the same time. When he build another turret in other place, the oldest turret is destroyed.

Somebody can do it? Thanks. :)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Heres my first shot shot, but it will work for all players at the same time, not for each player. That would need the use of Hashtables and I don't know how.

Unit Type Array: Turrets
Integer variable: TurretQ (Turrent Quantity)

1) A unit builds a Turret
-> Set TurretQ = TurrestQ + 1
-> Set Turrets[TurretQ] = last created turret.
2) If/Then Else
-> If: TurretQ = 10
-> Set TurretQ =TurretsQ - 1
-> Unit - Remove Turrets[1]
-> For each integer A from 2 to 10 do:
-> Set Turrets[Integer A] = Turrets[Integer A - 1]


3) A unit Dies
If: Unit-Type of Triggering Unit = Turret
-> Set TurretQ = TurretQ - 1

- However, maybe the tower that died wasn't the Turret[1] so, this doesn't work =)
------------------------------------------
Example:

When you build the Turret #10, the Turret[1] Will be destroyed, and Turret[2, 3, 4, 5, 6, 7, 8, 9 10] will be reduced by 1, making their values to Turret[1, 2, 3, 4, 5, 6, 7, 8, 9]. And will loop over and over.


My second Shot: Using Custom Value.

I'm thinking about it :) <- I have no idea xD
 
Level 4
Joined
Nov 24, 2010
Messages
62
Heres my first shot shot, but it will work for all players at the same time, not for each player. That would need the use of Hashtables and I don't know how.

Unit Type Array: Turrets
Integer variable: TurretQ (Turrent Quantity)

1) A unit builds a Turret
-> Set TurretQ = TurrestQ + 1
-> Set Turrets[TurretQ] = last created turret.
2) If/Then Else
-> If: TurretQ = 10
-> Set TurretQ =TurretsQ - 1
-> Unit - Remove Turrets[1]
-> For each integer A from 2 to 10 do:
-> Set Turrets[Integer A] = Turrets[Integer A - 1]


3) A unit Dies
If: Unit-Type of Triggering Unit = Turret
-> Set TurretQ = TurretQ - 1

- However, maybe the tower that died wasn't the Turret[1] so, this doesn't work =)
------------------------------------------
Example:

When you build the Turret #10, the Turret[1] Will be destroyed, and Turret[2, 3, 4, 5, 6, 7, 8, 9 10] will be reduced by 1, making their values to Turret[1, 2, 3, 4, 5, 6, 7, 8, 9]. And will loop over and over.

[/HIDDEN]


1) A unit builds a Turret
-> Set TurretQ[Triggering Player Index] = TurrestQ[Triggering Player Index] + 1
-> Save last created turret as TurretQ[Triggering Player Index] of Handle Trigger Player in TurretHash
2) If/Then Else
-> If: TurretQ[Triggering Player Index] = 10
-> Set TurretQ[Triggering Player Index] =TurretsQ[Triggering Player Index] - 1
-> Unit - Remove Load 1 of Handle Triggering Player in TurretHash
-> For each integer A from 2 to 10 do:
-> Save (Load IntergerA of Handle Triggering Player in TurretHash) as IntergerA - 1 of Handle Trigger Player in TurretHash


3) A unit Dies
If: Unit-Type of Triggering Unit = Turret
-> Set TurretQ[Triggering Player Index] = TurretQ[Triggering Player Index] - 1
 
Level 7
Joined
Apr 1, 2010
Messages
289
you could use an array instead,
JASS:
local integer i
local player p
local unit u
set p = GetTriggerPlayer()
loop
   exitwhen i > 12
   set i = i+1
   if player(i) == p then
      call GroupAddUnit(GetTriggerUnit(),TurretsGroup[i])
      if turrets[i] == turretsmax then
         set u = FirstOfGroup(TurretsGroup[i])
         call GroupRemoveUnit(u,TurretsGroup[i]) // this part has to be custom script nothing else does.
         call RemoveUnit(u)
      else
         set turrets[i] = turrets[i]+ 1
      endif
     endif
endloop
set p = null
this is for when a unit dies (i think this will work)
JASS:
local player p
local integer i
set p = GetTriggerPlayer()
loop
   exitwhen i > 12
   set i = i+1
   if player(i) == p then
      set turrets[i] = turrets[i] - 1
      call GroupRemoveUnit(GetTriggerUnit(),udg_TurretsGroup[intger A]) 
   endif
endloop
set p = null
the only thing is I am concerned that this might create null values in the unit group and it won't actually remove a turret it(in the first loop) instead it will remove a null value.
edit: updated code
 
Last edited:
Status
Not open for further replies.
Top