# TRIGGER request

Status
Not open for further replies.

#### Darkshine

Level 4
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 14
I shall try

#### Spartipilo

Level 20
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

#### Gopinich

Level 4
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

#### Darkshine

Level 4
So, this is the full trigger? Someone can do a test map?

Level 20
Maybe you?

#### noob

Level 14
Do not use hastables they bug and are slow

#### Narogog

Level 7
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
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:

#### Zaio

Level 8
Narogog could you please use [ JASS ] [ /JASS] texts when posting code, its much easier on the eyes

Status
Not open for further replies.

Replies
12
Views
1K
Replies
1
Views
492
Replies
1
Views
685
Replies
3
Views
604
Replies
2
Views
1K