Home   Help Search Login Register  

Author Topic: Problem with triggers  (Read 2233 times)

0 Members and 1 Guest are viewing this topic.

Offline Joiner

  • Members
  • *
Problem with triggers
« on: 12 Dec 2008, 18:33:35 »
Hello everyone!
First, a description of the situation:
In my mission, I have an area with a marker on it. When an East soldier enters the area, the marker becomes red, when a West soldier enters it, the marker becomes blue, when both East and West guys are inside, the marker becomes yellow. If East kills all West soldiers inside the area, and at least one East soldier stays in the area, the marker becomes red after being yellow, and vice versa, if West wins the duel.
All this is done by the following triggers:
1. A trigger activated by East. On activation: activeEast = true;
2. A trigger activated by West. On activation: activeWest = true;
3. A trigger with the condition "activeEast". On activation: "marker1" setMarkerColor "ColorRed";
4. A trigger with the condition "activeWest". On activation:"marker1" setMarkerColor "ColorBlue";
5. A trigger with the condition "activeEast and activeWest". On activation: "marker1" setMarkerColor "ColorYellow";
6. A trigger with the condition "activeEast and west countSide list trigger1 < 1;". On activation: "marker1" setMarkerColor "ColorRed";
7. A trigger with the condition "activeWest and east countSide list trigger1 < 1;". On activation: "marker1" setMarkerColor "ColorBlue";

Now the problem:
Everything works fine except for one thing: the marker does not become red after beying yellow (that is, after West soldiers are eliminated in the area, provided that East is still in the area). Any idea can be wrong? Please help.
P.S. The marker does become blue after East is eliminated and West is still in the area.

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Problem with triggers
« Reply #1 on: 12 Dec 2008, 18:52:16 »
These two trigger conditions...

Code: [Select]
6. A trigger with the condition "activeEast and west countSide list trigger1 < 1;". On activation: "marker1" setMarkerColor "ColorRed";
7. A trigger with the condition "activeWest and east countSide list trigger1 < 1;". On activation: "marker1" setMarkerColor "ColorBlue";

...are both counting the list from the same trigger:  trigger1

Is that right?  Should trigger 6 be counting the list form a different trigger?
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Walter_E_Kurtz

  • Guest
Re: Problem with triggers
« Reply #2 on: 12 Dec 2008, 19:26:00 »
You should be able to do it with fewer triggers, if you add a few more conditions

1. A trigger activated by East. On activation: activeEast = true;  On de-activation: activeEast = false;
2. A trigger activated by West. On activation: activeWest = true; On de-activation: activeWest = false;
3. A trigger with the conditions: "activeEast && !activeWest". On activation: "marker1" setMarkerColor "ColorRed";
4. A trigger with the conditions: "activeWest && !activeEast". On activation: "marker1" setMarkerColor "ColorBlue";
5. A trigger with the conditions: "activeEast && activeWest". On activation: "marker1" setMarkerColor "ColorYellow";

PS. Make sure all triggers activate Repeatedly, and that the initialisation sets both activeWest and activeEast to false.
« Last Edit: 13 Dec 2008, 01:41:47 by Walter_E_Kurtz »

Offline Ext3rmin4tor

  • Members
  • *
Re: Problem with triggers
« Reply #3 on: 12 Dec 2008, 19:57:25 »
Instead of messing with 1968178629729 triggers just put one trigger activated by "Anyone" instead of a specific side and then use the following script passing the thisList variable and the marker name as parameter:

Code: [Select]
//USAGE: [unit array, marker] execVM "checkSide.sqf"

//local function used to check how many units are alive in an array
_areAlive =
{
_count = 0;
{
if (alive _x) then {_count = _count + 1};
}
forEach _this;

_count
};

_unitArray = _this select 0;
_marker = _this select 1;
_currentAliveUnits = _unitArray call _areAlive;  //store the current number of alive units who activated the trigger
//execute the script until all the units that activated it are alive
while {_currentAliveUnits > 0} do
{
_countEast = 0;
_countWest = 0;
//check what kind of units have activated the script (east and/or west)
{
if (side _x == east and alive _x) then {_countEast = _countEast + 1};
if (side _x == west and alive _x) then {_countWest = _countWest + 1};
}
forEach _unitArray;


if (_countEast > 0 and _countWest > 0) then {_marker setMarkerColor "ColorYellow"}
else
{
if (_countEast > 0) then
{
_marker setMarkerColor "ColorRed";
};

if (_countWest > 0) then
{
_marker setMarkerColor "ColorBlue";
};
};
//if someone is killed need to recheck the units side and eventually reset the marker color
waitUntil{_unitArray call _areAlive != _currentAliveUnits};
//update the number of alive units
_currentAliveUnits = _unitArray call _areAlive;
};

basically you make a trigger activated repeatedly and activated by "Anyone". In the activation field write

call{[thisList, "marker1"] execVM "checkSide.sqf"}

I tested it and it should work, anyway if you experience any bugs tell me and I will try to fix them.

EDIT:  I forgot to say that this is a general purpose script so if you have more than one marker of that kind you have just to put a trigger of the same kind of the one above and just change the marker name in the call arguments (example: if you have another marker called "marker2" create another activation trigger for that marker and write call{[thisList, "marker2"] execVM "checkSide.sqf"}). Also do not copy/paste the script from the forum cause sometimes it messes up with lines if there are script comments (those lines starting with // ) so just write it by yourself (if you copy/paste and it gives you some syntax errors when you run it, it means the forum has messed it up).
« Last Edit: 12 Dec 2008, 20:29:22 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Joiner

  • Members
  • *
Re: Problem with triggers
« Reply #4 on: 12 Dec 2008, 21:00:13 »
Thanks a lot for your hints guys, I achieved the needed effect with your help!

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Problem with triggers
« Reply #5 on: 12 Dec 2008, 22:17:52 »
You gotta love this site.  3 helpful replies within 2 hours!   :D
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Ext3rmin4tor

  • Members
  • *
Re: Problem with triggers
« Reply #6 on: 13 Dec 2008, 12:31:39 »
I'm just curious: did you try the script or you used the trigger solution?
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Joiner

  • Members
  • *
Re: Problem with triggers
« Reply #7 on: 13 Dec 2008, 22:55:15 »
Quote
You gotta love this site.
Yeah, sure!  :)
Quote
did you try the script or you used the trigger solution?
I used triggers - the first hint helped me fix the problem, the second helped me reduce the number of triggers. The script is a very smart solution - I will use it as well, but not in this mission. Thanks again! :)

Offline Ext3rmin4tor

  • Members
  • *
Re: Problem with triggers
« Reply #8 on: 14 Dec 2008, 11:56:47 »
I asked that because I think that the trigger solution doesn't work for a situation like this: the player gets rid of all the enemies and the marker becomes blue, but after that other enemies enters the area and the marker has to become yellow again. But I might mistake.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Joiner

  • Members
  • *
Re: Problem with triggers
« Reply #9 on: 14 Dec 2008, 15:23:22 »
Quote
the player gets rid of all the enemies and the marker becomes blue, but after that other enemies enters the area and the marker has to become yellow again
Yeah, that's what I need. I need the marker to become yellow each time there are both sides in the area.

Offline Ext3rmin4tor

  • Members
  • *
Re: Problem with triggers
« Reply #10 on: 15 Dec 2008, 14:24:05 »
If you use the script that stuff works. I tried it.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Joiner

  • Members
  • *
Re: Problem with triggers
« Reply #11 on: 16 Dec 2008, 00:19:03 »
OK, thanks.