OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: Ghost644 on 28 May 2006, 21:19:05
-
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!
-
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
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
?( ({alive _x} count thislist) <=10) : end the mission
-
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:
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:
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.
-
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.
-
Then, additionally to the above listed, add the eventhandler also to the spawned units.
_spawnedUnit addEventHandler ...
Your mission end trigger would have a condition:
DeadUnits > 20or similar.
-
ok, ill have to try it out later on. Thanks for responding. Ill let you know how it works for me later.
-
Ok so i have a trigger setup as follows
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.
-
make a description.ext
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);
-
Ok so i put (DeadUnits >= Param2); in my trigger and have the desciption.ext set like
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
?param2 ==1: 100
?param2 ==2: 200
?param2 ==3: 300
?param2 ==4: 400
?param2 ==5: 500
-
ghost644
compare your parameters with Seven's example and you'll get the error.
you have:valuesParamX[]={1,2,3,4,5};
Seven has:valuesParamx[]= {10000, 100, 200, 300, 400};
the code you have in the init.sqs is unnecessary and useless
?param2 ==1: 100
this can't work, this line says
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.
-
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.
-
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.
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
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.
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
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.