OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Quagmire on 17 Dec 2009, 11:04:09

Title: triggers as counts instead of individual events.
Post by: Quagmire on 17 Dec 2009, 11:04:09
Hi,

I was wondering if there's a way that I can set a trigger to go off after a certain count has been reached, and if there's some way I can make several triggers contribute toward increasing this count when each of them is triggered.

For example, I have an idea for a mission in which players form a small band of guerrillas with the objective of destroying a certain amount of enemy units, rather than what most missions have, which is the objective of destroying particular enemy units and structures. So I'd want one trigger which increases a "count" when an enemy unit is destroyed, and another trigger which registers an objective as having been complete once this counts reaches a certain level.

It'd be great if anyone could help out, thanks.

edit: also, I'm wondering how I can equip units with gear by a script, rather than having "removeallweapons" etc.. in the init field of each unit which I want to have a defined kit. Particularly, I'd like to equip large numbers of units with the same gear.
Title: Re: triggers as counts instead of individual events.
Post by: Shuko on 17 Dec 2009, 15:15:45
TRIGGER, condition
Code: [Select]
KillCountReached
INIT.SQF, change amount of kills when the trigger should fire and side of enemy
Code: [Select]
[100,EAST] execvm "counter.sqf";

COUNTER.SQF
Code: [Select]
KillCount = 0;
KillCountReached = false;
if (isserver) then {
  _c = _this select 0;
  _s = _this select 1;
  {
    if (side _x == _s) then {
      _x addEventHandler ["killed", {KillCount = KillCount + 1}];
    };
  } foreach allunits;
  waituntil {KillCount >= _c};
  KillCountReached = true;
  publicvariable "KillCountReached";
};

For gear, copy/write all the removeallweapons, addweapon etc command into a file. Example:

GEAR.SQF
Code: [Select]
removeallweapons _this;
_this addweapon "NVGoggles";
_this addweapon "Binocular";
_this addmagazine "30Rnd_556x45_Stanag";
_this addmagazine "30Rnd_556x45_Stanag";
_this addmagazine "30Rnd_556x45_Stanag";
_this addmagazine "30Rnd_556x45_Stanag";
_this addmagazine "30Rnd_556x45_Stanag";
_this addmagazine "30Rnd_556x45_Stanag";
_this addmagazine "SmokeShell";
_this addmagazine "SmokeShell";
_this addmagazine "SmokeShell";
_this addmagazine "SmokeShell";
_this addmagazine "SmokeShellOrange";
_this addmagazine "SmokeShellRed";
_this addweapon "M4A1_Aim_camo";

Then you can just do this in the units init:
Code: [Select]
nul = this execvm "gear.sqf"
Or you can do this from init.sqf. unitname1 etc are the name of units you want to change gear.
Code: [Select]
{_x execvm "gear.sqf"} foreach [unitname1,unitname2,unitname3]
Title: Re: triggers as counts instead of individual events.
Post by: Quagmire on 19 Dec 2009, 10:09:51
both of those solutions work fine, thanks.
Title: Re: triggers as counts instead of individual events.
Post by: Quagmire on 21 Jan 2010, 10:59:03
Even though that gear solution worked fine in single player, I find it doesn't work in multiplayer (at least, not for playable troops). Is there something special I have to do to make this kind of gear script work in multiplayer?
Title: Re: triggers as counts instead of individual events.
Post by: Fincuan on 22 Jan 2010, 10:44:54
Init.sqf:
Code: [Select]
if (not isDedicated) then
{
waitUntil{(not isNull player) and (player == player)};
};
/*
Whatever other stuff you need to run BEFORE mission starts
*/
if (local player) then
{
sleep 0.01;
player execVM "gear.sqf";
};

The little sleep is there to prevent the gear script from running before the mission actually starts, as it won't work otherwise. When the mission starts it'll do the sleep, then run the gear script. A slightly cleaner way would imho be to add the sleep to the beginning of the gear script and remove it from there.

You could also wrap the whole gear script to this:
Code: [Select]
sleep 0.01;
if (local _this) then
{

};
and just run it form the unit's initline:
Code: [Select]
this execVM "gear.sqf";
Title: Re: triggers as counts instead of individual events.
Post by: Quagmire on 25 Jan 2010, 02:44:24
great, thanks

edit: actually, using this, will units have the gear listed in the gear.sqf after respawning?

edit2: never mind, problem solved by using Universal Weapons Respawn Script v1.04