Home   Help Search Login Register  

Author Topic: Counting dead civs in an array  (Read 1404 times)

0 Members and 1 Guest are viewing this topic.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Counting dead civs in an array
« on: 22 Nov 2008, 05:55:27 »
ok code:

GameLogic:
ca = civilian countSide list civ;

Trigger Named civ, repeated trigger:
Condition: civilian present
Act: civdead = civilian countSide list civ;

Trigger Named obj2, repeated
condition: civilian present && civdead +5 == ca
Act: ObjStatus Failed.... <paraphrase


So when 5 civilians die I want the mission to end. Apparently the arrays are empty. I get a Scalar error for both "ca" and "civdead". Any help is appreciated, even if you direct me to a similar question....

I know i can name the civs and see if they are alive repatatively but I do not want to name all the dam civs. So, I am trying to work around that while becoming more rounded in scrippets. Hope I made this clear.
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Counting dead civs in an array
« Reply #1 on: 22 Nov 2008, 15:45:36 »
The fundamental problem with this is that all CORPSES are considered to be civilians, regardless of what side they were on in life (and they are picked up by triggers, of course). This means it is impossible to count how many corpses

You don't need to name your triggers. When running code inside a trigger, you can use "thisList" as shorthand for "list triggerName".

The reason ca is empty is because it will be counted at object init phase. You need to wait until the trigger detects someone before recording the value.

You don't need to make the triggers repeated, since you only need them to activate once. That isn't what repeated means. A normal trigger will continually check until the condition is true and then activate, then check until the condition is false then deactivate, then it will stop doing anything. A repeated trigger will continually check throughout the mission and activate and deactivate as many times as the condition changes.

"civilian present" isn't a condition (inasmuch as it doesn't go into the condition line).

EDIT: Wrong (correct answer in later post)...

Anyway, I think this should be a much simpler solution for you (count how many dead civilians you have):
Trigger (CIVILIAN PRESENT NON-REPEATING)
Condition: ({ (not (alive _x)) and (_x isKindOf "civilian")} count thisList)  >= 5
OnAct: ObjStatus Failed.... <paraphrase
« Last Edit: 25 Nov 2008, 05:58:04 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Counting dead civs in an array
« Reply #2 on: 22 Nov 2008, 17:08:03 »
Thanks for crushing my hopes and dreams spooner lol..... :clap:


BAHHHH HUMMMM BAHHHG. That didn't work Spooner but I got no errors either?

I think in the end I ended up crushing Spooners hopes and dreams..... hahaha
« Last Edit: 25 Nov 2008, 05:47:55 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Counting dead civs in an array
« Reply #3 on: 25 Nov 2008, 05:57:25 »
OK, I was so far off on my previous answer, that I'm frankly embarrassed. Although I was right in saying that all corpses are civilians, it is a fact that triggers never pick up corpses anyway (Unlike nearestObject type commands, which is what I was thinking about). Sorry! While I was fixing this (by actually building a test mission, rather than answering from the top of my head) I also added JIP handling and managing the civilians potentially being in vehicles.

You need a trigger to count the initial number of civilians on the map, including those that start within vehicles (CIVILIAN PRESENT NON-REPEATEDLY)
Condition: this
OnAct: initialCivs = { count (crew _x) } forEach thisList;
(This is actually similar to your initial system, but using a trigger to count the initial number of civilians).

A trigger to end the mission if 5 civilians have been killed (CIVILIAN PRESENT NON-REPEATEDLY)
Condition: numCivs = 0; { numCivs = numCivs + ({ alive _x } count (crew _x))  } forEach thisList; (initialCivs - numCivs >= 5) and (time > 10)
OnAct: end mission....

(time > 10 allows for start of mission, especially JIP, to have created all the civilians so the mission doesn't think they have died already!)
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)