Home   Help Search Login Register  

Author Topic: Can you add mags to and remove mags from clients via script in MP?  (Read 1387 times)

0 Members and 1 Guest are viewing this topic.

Offline Ranger

  • Members
  • *
  • Hoo-ah!
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?
« Last Edit: 17 Aug 2007, 18:48:33 by Ranger »
Ranger

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
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.

Offline Ranger

  • Members
  • *
  • Hoo-ah!
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.
Ranger

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
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.
urp!

Offline Ranger

  • Members
  • *
  • Hoo-ah!
That's good to know; thanks, Mr. Peanut.
Ranger