OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started 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:
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?
-
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:
...
_unit SetVehicleInit "this removeMagazine ""SmokeShellRed"";this removeMagazine ""SmokeShellGreen""";
processInitCommands;
...
The effect is just like that of the init string.
-
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.
-
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.
-
That's good to know; thanks, Mr. Peanut.