Monday, April 16, 2012

Trigger Troubles...

I have some trigger set up for all my units and buildings because i have variables set up as resources because i wanted more than just the regular 2 in my map. Well... heres my trigger (this is one of them, but its the same for all of them).

Event:

Unit Begins Construction

Conditions:

Or - Any (Conditions) are true

-unit type of (constructing structure) equal to farm

-unit type of (constructing structure) equal to blacksmith

-unit type of (constructing structure) equal to lumbermill

Actions:

For Each integer A from 1 to 12 do -

loop actions -

If all conditions are true then do (then actions) else do (else actions) -

If Conditions -

Or - Any (Conditions) are true

-unit type of (constructing structure) equal to farm

-unit type of (constructing structure) equal to blacksmith

-unit type of (constructing structure) equal to lumbermill

Owner of (triggering unit) equal to Player(Integer A)

Stone(Integer A) greater than or equal to 125

Player(integer A) current lumber greater than or equal to 75

Iron(integer A) greater than or equal to 50

Then Actions -

Player - add -75 to player(integer A) current lumber.

set Iron(integer A) = Iron(integer A) - 50

set Stone(integer A) = Stone(integer A) -125

Else Actions -

Game - display to player group(player(integer A)) the Text: you do not have the resources to build this.

Unit - remove Constructing Structure from the game



This is the trigger but for some reason each time i try to build something the building is removed and the resources are taken away, but when i run out of resources i don't loose any and the message saying I don't have enough pops up. I have tried making this 2 separate If then else things in the same trigger but that didn't work as well. there are about 8 of these total and they are all set up the same way.|||You should wrap your triggers in the CODE tags when posting them here, as otherwise whitespace at the start of the line isn't shown which makes evaluating what belongs where an issue. Anyway, here's a better trigger:


Code:
Trigger
Events
Unit - A unit Begins construction
Conditions
Or - Any (Conditions) are true
Conditions
(Unit-type of (Triggering unit)) Equal to Farm
(Unit-type of (Triggering unit)) Equal to Blacksmith
(Unit-type of (Triggering unit)) Equal to Lumber Mill
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Owner of (Triggering unit)) Current lumber) Greater than or equal to 75
Iron[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 50
Stone[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 125
Then - Actions
Player - Add -50 to (Owner of (Triggering unit)) Current lumber
Set Iron[(Player number of (Owner of (Triggering unit)))] = (Iron[(Player number of (Owner of (Triggering unit)))] - 50)
Set Stone[(Player number of (Owner of (Triggering unit)))] = (Stone[(Player number of (Owner of (Triggering unit)))] - 125)
Else - Actions
Game - Display to (Player group((Owner of (Triggering unit)))) the text: You do not have the resources to build this.
Unit - Remove (Constructing structure) from the game
|||Yes that is easier than using integer a. ill try it to see if that fixes the problem thanks.|||Thanks a lot. just tried it out and it worked.|||No problem. By the way, this is something I should have put in the original trigger to prevent leaks. Create a variable of type 'player group' called TempForce, then use this instead (same trigger, slight changes):


Code:
Trigger
Events
Unit - A unit Begins construction
Conditions
Or - Any (Conditions) are true
Conditions
(Unit-type of (Triggering unit)) Equal to Farm
(Unit-type of (Triggering unit)) Equal to Blacksmith
(Unit-type of (Triggering unit)) Equal to Lumber Mill
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Owner of (Triggering unit)) Current lumber) Greater than or equal to 75
Iron[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 50
Stone[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 125
Then - Actions
Player - Add -50 to (Owner of (Triggering unit)) Current lumber
Set Iron[(Player number of (Owner of (Triggering unit)))] = (Iron[(Player number of (Owner of (Triggering unit)))] - 50)
Set Stone[(Player number of (Owner of (Triggering unit)))] = (Stone[(Player number of (Owner of (Triggering unit)))] - 125)
Else - Actions
Set TempForce = (Player group((Owner of (Triggering unit))))
Game - Display to TempForce the text: You do not have the resources to build this.
Unit - Remove (Triggering unit) from the game
Custom script: call DestroyForce( udg_TempForce )

(Only the actions after the 'else' have been altered)

No comments:

Post a Comment