OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: SniperUK on 29 Jun 2007, 13:45:42

Title: Multiplayer Ammo Drop
Post by: SniperUK on 29 Jun 2007, 13:45:42
Hi guys i've been pondering over every script i can possibly find regarding an ammo drop and even written several myself but all seem to have the same issue when introduced to multiplayer.
Most scripts i use work fine where you spawn a parachute + an ammo crate which sequentially keeps updating iits own position either from a game logic or the parachute itself.
These scripts work fine in single player but when introducting the script to multiplayer the ammo box no longer seems to follow the code and instead of hanging below the parachute floats above it and updates itself every second or so.
Is there anything i can do to correct this issue or is it a syncronization problem that is encountered in multiplayer and a restriction of the game engine. Thanks in advance.
Title: Re: Multiplayer Ammo Drop
Post by: ArMaTeC on 29 Jun 2007, 14:11:07
try this sample out of one of my demo missions i use it to drop a car from a chopper chute opens ar the start of the script but can be called any time with

[ammoboxname]execVM"paradrop.sqf"
Code: [Select]
// AmmoBox filler + Dropper
// By ArMaTeC
//
// Usage: res=[(getpos [location]),AmmoBoxWest]execVM"ammobox.sqf";
// Edited: 30.06.07 23:41




_location = _this select 0;
_boxtype = _this select 1;
_Upos = _location;
_SPheight = 18;
_cpara =
{
private ["_grp","_u","_pos"];
_grp=_this select 0;
_pos=_this select 1;
_u=_grp createvehicle _pos;
_u setpos _pos;
_u
};
_ammobox=[_boxtype,[_location  select 0,_location  select 1,(_location  select 2)+_SPheight]] call _cpara;
sleep 0.001;
_Offsetx = 0;
_Offsety = 0;
_Offsetz = -1.5;// how far below you wont the ammobox
_para=["ParachuteG",(getpos _ammobox)] call _cpara;
player setpos getpos _ammobox;
_pUpos= GetPos _ammobox;
_pux=_pUpos Select 0;
_puy=_pUpos Select 1;
_puz=_pUpos Select 2;

while {_puz >= 15} do
{
hint format["%1",_puz];
_mpvol = Velocity _para;
_pvolx = _mpvol select 0;
_pvoly = _mpvol select 1;
_pvolz = _mpvol select 2;
_ammobox SetPos (_para ModelToWorld [_Offsetx,_Offsety,_Offsetz]);
_ammobox SetVelocity [_pvolx,_pvoly,_pvolz -1];
_VUp=VectorUp _para;
_VDir=VectorDir _para;
_ammobox SetvectorDir _VDir;
_ammobox SetvectorUp _VUp;
sleep 0.001;
_pUpos= GetPos _ammobox;
_puz=_pUpos Select 2;
hint format["%1",_puz];
};
_ammobox SetPos (_para ModelToWorld [_Offsetx,_Offsety,_Offsetz]);
deleteVehicle _para;
_boxname = _ammobox;
while {true} do
{

_waitrnd = random 600;
_count = 10+random 20;
_West_weap = ["M16A2","M16A2GL","M16A4","M16A4_GL","M16A4_ACG","M16A4_ACG_GL","M4","M4GL","M4AIM","M4A1SD","M4SPR","M4A1","M4A1GL","G36K","G36C","G36A","MP5A5","MP5SD","M249","M240","M24","M107","M9","M9SD","M136","JAVELIN","STINGER"];
_East_weap = ["AK74","AK74GL","AKS74U","AKS74UN","AKS74PSO","PK","SVD","KSVK","MAKAROV","MAKAROVSD","RPG7V","STRELA"];
_West_ammo = ["30Rnd_556x45_Stanag","20Rnd_556x45_Stanag","30Rnd_556x45_StanagSD","30Rnd_556x45_G36","30Rnd_9x19_MP5","30Rnd_9x19_MP5SD","200Rnd_556x45_M249","100Rnd_762x51_M240","5Rnd_762x51_M24","10Rnd_127x99_M107","15Rnd_9x19_M9","15Rnd_9x19_M9SD","M136","JAVELIN","STINGER","FlareWhite_M203","FlareGreen_M203","FlareRed_M203","FlareYellow_M203","1Rnd_HE_M203"];
_East_ammo = ["30Rnd_545x39_AK","30Rnd_545x39_AKSD","100Rnd_762x54_PK","10Rnd_762x54_SVD","5Rnd_127x108_KSVK","8Rnd_9x18_Makarov","8Rnd_9x18_MakarovSD","PG7V","PG7VR","FlareWhite_GP25","FlareGreen_GP25","FlareRed_GP25","FlareYellow_GP25","1Rnd_HE_GP25"];
_Misc_ammo = ["HandGrenade","HandGrenadeTimed","SmokeShell","SmokeShellRed","SmokeShellGreen","PipeBomb","TimeBomb","Mine","MineE","Laserbatteries"];
{_boxname removeWeapon _x;} forEach Weapons _boxname;
{_boxname removeMagazine _x;} forEach magazines _boxname;
{_boxname addWeaponCargo [_x,_count];} forEach _West_weap;
{_boxname addWeaponCargo [_x,_count];} forEach _East_weap;
{_boxname addMagazineCargo [_x,_count];} forEach _West_ammo;
{_boxname addMagazineCargo [_x,_count];} forEach _East_ammo;
{_boxname addMagazineCargo [_x,_count];} forEach _Misc_ammo;
_wait = 60 + _waitrnd;
sleep _wait;
_reWait = _time + 60;
waitUntil {(!Alive _boxname) && (_time < _reWait);};
_boxname setdammage 0;
};
Title: Re: Multiplayer Ammo Drop
Post by: Mandoble on 29 Jun 2007, 14:12:49
Ammo boxes are static objects, and setPos effect is not global in MP. So, if your script is running from the server, the setPos will be seen only by the server. Consider that your GL is global, and its position is common for all machines, so you should create the objects only if server (chute, ammobox and logic), but you need to setPos the ammo in every client and every client may read the correct position of the GL each time.

Title: Re: Multiplayer Ammo Drop
Post by: SniperUK on 30 Jun 2007, 01:33:06
tried what you said mandoble, i created the logic, parachute and ammo crate on the server then ran a repetative script on all clients from the init file that was activated by a publicvariable to getpos/getpos the movements of the crate. The issue turned out to be exactly the same, with the crate trailing behind the parachute.
Title: Re: Multiplayer Ammo Drop
Post by: ArMaTeC on 01 Jul 2007, 02:03:31
tested my way and it worked
Title: Re: Multiplayer Ammo Drop
Post by: SniperUK on 01 Jul 2007, 11:40:35
yeah sorry armatec i wasnt disregarding your script, was just trying to salvage what i had wrote more than anything. I did try to introduce your script but whenever i tried to use it i got errors and nothing happened. Can you give me alittle more information background on your script? ie. i just save that code into a script called paradrop and then call it from another script or a trigger. Do i have to have the ammo crate already created hidden on the map or does it dynamically create an ammo crate everytime the script is called?
Title: Re: Multiplayer Ammo Drop
Post by: JasonO on 03 Jul 2007, 22:55:08
http://www.ofpec.com/forum/index.php?topic=29090.0

I tested this on MP with another person and nothing went seriously wrong. After a quick test I released it.