OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Ranger on 17 Aug 2007, 18:03:06

Title: Can you add mags to and remove mags from clients via script in MP?
Post by: Ranger on 17 Aug 2007, 18:03:06
Hi folks,

I have a .sqf script that is run from the initialization field of two playable snipers that changes their loadout and moves them into the cargo area of a CRRC.  The script is as follows:

Code: [Select]
private ["_i", "_unit"];

_unit = _this;

// c1 is the CRRC.
_unit moveInCargo c1;

_unit removeMagazine "SmokeShellRed";
_unit removeMagazine "SmokeShellGreen";

for [{_i=1},{_i<=4},{_i=_i+1}] do {
_unit addMagazine "5Rnd_762x51_M24";
_unit addMagazine "15Rnd_9x19_M9";
};

It removes their smoke grenades and gives them 4 M24 mags and 4 M9 mags.  Seems simple enough.

In single player, it works without a problem. In multiplayer, the client player does not have his loadout changed.  Thus, he still has the smoke grenades and does not get the extra mags.  However, he does get moved into the CRRC, which means that the script is running.

Is there a way to remove mags and add mags via a script in multiplayer, or can you only do this from the initialization field of a unit?
Title: Re: Can you add mags to and remove mags from clients via script in MP?
Post by: Mandoble on 18 Aug 2007, 15:10:17
You may add or remove magazines for a unit as long as this unit is local for the computer where you run the script.

At any moment, you may also try:
Code: [Select]
   ...
   _unit SetVehicleInit "this removeMagazine ""SmokeShellRed"";this removeMagazine ""SmokeShellGreen""";
   processInitCommands;
   ...

The effect is just like that of the init string.
Title: Re: Can you add mags to and remove mags from clients via script in MP?
Post by: Ranger on 20 Aug 2007, 17:29:39
Thank you, Mandoble.  The SetVehicleInit code seems to have done the trick.

Using addMagazine, addWeapon, and removeMagazine code doesn't work in multiplayer if it is used in a script for a client player.  At least, it didn't work in my case, even though the script was called by the client player's unit.
Title: Re: Can you add mags to and remove mags from clients via script in MP?
Post by: Mr.Peanut on 20 Aug 2007, 23:21:37
That sort of code has to be executed from the init.sqs/sqf for reasons I can not remember,  probably because it is possible for a unit's init field to be run before the unit's locality is established.
Title: Re: Can you add mags to and remove mags from clients via script in MP?
Post by: Ranger on 21 Aug 2007, 01:24:22
That's good to know; thanks, Mr. Peanut.