Home   Help Search Login Register  

Author Topic: Count Enemy deaths, when deaths reach X then game ends  (Read 2840 times)

0 Members and 2 Guests are viewing this topic.

Offline Ghost644

  • Members
  • *
    • Ghostland
I would like to set up a mission where there are many waves of enemy troops. To end the mission X amount of enemy have to be killed. I was wondering what the little code snipet is. Thanks in advance!
Ghost

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #1 on: 28 May 2006, 22:39:35 »
not sure if this works in MP, but make a trigger large enough to cover the map, activated by the enemy side present, and in the on activation field put

Code: [Select]
all_enemy = thislist
then in a script you can use the variable all_enemy to refer to the number of enemies on the map. the variable is dynamic, so to end the mission when there are only 10 enemies left use

Code: [Select]
?( ({alive _x} count thislist) <=10) : end the mission

Offline hardrock

  • Members
  • *
  • Title? What's that?
    • Operation FlightSim
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #2 on: 29 May 2006, 00:00:45 »
You could also use the killed eventhandler which is better for the performance than a trigger, I guess.

Create a trigger covering the whole map, condition 'true' and activation by the enemy side. In the onActivation field you put:
Code: [Select]
DeadUnits = 0; {_x addEventHandler ["killed", {DeadUnits = DeadUnits+1; publicVariable "DeadUnits"}]} forEach thislist
Leave away '; publicVariable "DeadUnits"' when in Singleplayer.

The variable DeadUnits will always represent the number of killed enemies in total. If you want to count only those killed by the player(s), you have to add an if-statement:
Code: [Select]
DeadUnits = 0; {_x addEventHandler ["killed", {if (_this select 1 == player) then {DeadUnits = DeadUnits+1; publicVariable "DeadUnits"}}]} forEach thislist
Same for the publicVariable part as above.

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #3 on: 29 May 2006, 12:00:53 »
Im only going to have a handful of enemy placed on the map. Most of the waves are going to be spawned in. So i need it to count up to a number then when that number is reached it will endgame.
Ghost

Offline hardrock

  • Members
  • *
  • Title? What's that?
    • Operation FlightSim
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #4 on: 29 May 2006, 12:03:53 »
Then, additionally to the above listed, add the eventhandler also to the spawned units.
Code: [Select]
_spawnedUnit addEventHandler ...
Your mission end trigger would have a condition:
Code: [Select]
DeadUnits > 20or similar.

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #5 on: 29 May 2006, 12:06:20 »
ok, ill have to try it out later on. Thanks for responding. Ill let you know how it works for me later.
Ghost

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #6 on: 09 Jun 2006, 04:02:20 »
Ok so i have a trigger setup as follows

Code: [Select]
detection:Russian
Type: End1
Condition:DeadUnits = 200
OnActivation:Stopspawn=true;  (to stop the respawn script)

I would like to add a parameter to allow me to change the Deadunits = 200 to any other amount. So from the side selection screen in mp you would see "Kills to win" and below are options for different amounts i.e. 100, 200, 300, etc.
Ghost

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #7 on: 09 Jun 2006, 11:53:04 »
make a description.ext
Code: [Select]
titleParam1 = "Score to win:";
valuesParam1[] = {10000, 100, 200, 300, 400};
defValueParam1 = 200;
textsParam1[] = {"Unlimited", 100, 200, 300, 400};

and in ur endtrigger put in condition:

(DeadUnits >= Param1);

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #8 on: 15 Jun 2006, 13:19:10 »
Ok so i put  (DeadUnits >= Param2); in my trigger and have the desciption.ext set like
Code: [Select]
titleParam2="Kills to Win";
valuesParam2[]={1,2,3,4,5};
defvalueParam2=2;
textsParam2[]={100,200,300,400,500};

and i killed one man when i set it to 100 and the game ended? Is that because this param is reffuring to score? How would i set it to reffur to kills? Or how many points does killing an enemy soldier give?
in my init.sqs i have it set
Code: [Select]
?param2 ==1: 100
?param2 ==2: 200
?param2 ==3: 300
?param2 ==4: 400
?param2 ==5: 500
Ghost

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #9 on: 15 Jun 2006, 22:33:41 »
ghost644

compare your parameters with Seven's example and you'll get the error.

you have:
Code: [Select]
valuesParamX[]={1,2,3,4,5};
Seven has:
Code: [Select]
valuesParamx[]= {10000, 100, 200, 300, 400};
the code you have in the init.sqs is unnecessary and useless
Code: [Select]
?param2 ==1: 100
this can't work, this line says
Quote
if param2 is equal to one, then 100

You might see the error in the logic....is 100....100 what?

With seven's code these lines are obsolete since the value is corectly set with the valuesParamX

So if you use Seven's code 1 on 1 you'll get a working counter for dead units and the mission will end after the set amount of killed enemies.

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #10 on: 15 Jun 2006, 22:47:13 »
ok ill try that now. I have the code in the init.sqs because in other topics about parameters they said to do what i did.
Ghost

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Count Enemy deaths, when deaths reach X then game ends
« Reply #11 on: 15 Jun 2006, 23:21:38 »
i guess you're relatively new to scripting so let me explain you a bit about the params and the use of it.

basically there are 2 parameters which you use for user to choose from.
Code: [Select]
param1
param2

for each of these parameters you have a set of 4 commands to set these params to your need. Let's start with
Code: [Select]
titleParamX="Understand this post?"Here you just set the name visible in the MP setup. I see you already know this so lets jump to the next 2 commands.

Code: [Select]
ValuesParamX[]= {true, false}
textsParamX[]= {"Yes", "No"}
these 2 commands goes together. The textsParamX command defines which text will be shown in the list. This list is linked with the values of valuesParamX. The first entry in textsparamx is also the first entry in valuesparamx.
Always make sure you have the same count in each of these arrays.

so the above code would set paramX to true or false. ingame with this i could start a tutorial or skip it as example.

and now the last command
Code: [Select]
defValueParamX=2

This command simply sets which entry from the list of the above commands is preselected. This just points to the array so this example says "use the second entry from the array". So don't put any other values in here.


One word for multiplayer use of defValueParamX: this setting will also be used whenever you play on a server without admin. So make sure u set a default value which most likely the people would choose from themselves. As example, for a deathmatch or a CTF most used time setting is 30 minutes, so setting up this as default would be a good idea.