Jump to content
Sign in to follow this  
A-SUICIDAL

Scripting gear into a spawned vehicle (problem)

Recommended Posts

So I have a vehicle drop script that spawns a HMMWV GPK (M2) in the air that drops from a parachute. There are actually a few scripts involved, but I have a problem with the script that adds weapons and gear into the cargo of the vehicle - where the weapons and gear multiply depending on how many players are on the server. So if I test by myself, everything works fine, but as soon as a friend joins the server and he request a vehicle drop, the weapons and gear added to his HMMWV vehicle then double in amount, so instead of there being 2 MAAW launchers and 10 MAAW rockets, my friends HMMWV shows 4 MAAW launchers and 20 MAAW rockets. I would imagine that if there are 3 players on the server it would then show 6 MAAW launchers and 20 MAAW rockets. I tried using a if (isServer) command, but then no weapons and gear appear in the vehicle at all, but maybe I did that wrong.

Each player has their own vehicle drop script, and each vehicle is named according to the player, so player s2 would be the owner of dropped vehicle named hmmwv_s2. So I then tried adding triggers that are specific to each player's vehicle name, so when player s2 requests a vehicle drop, a vehicle named hmmwv_s2 would spawn in a parachute and a trigger trigger specific to his vehicle would then do the following:

(Note: The script adds additional armor to the vehicle, additional turret ammunition, clears the vehicle cargo, then adds weapons and gear in cargo, and adds the action to repair the vehicle if it is damaged. I haven't checked, but I would assume that the turret ammunition is multiply too.)

condition:

alive hmmwv_s2

On Act.

null = [hmmwv_s2] execVM "request_vehicle_drop\veh_add_gear_s2.sqf";

veh_add_gear_s2.sqf:

hmmwv_s2 setVehicleInit "hmmwv_s2=this;

this setVariable ['selections', []];
this setVariable ['gethit', []];
this addEventHandler ['HandleDamage',{

_veh = _this select 0;

_selections = _veh getVariable ['selections', []];
_gethit = _veh getVariable ['gethit', []];
_selection = _this select 1;
if !(_selection in _selections) then {
	_selections set [count _selections, _selection];
	_gethit set [count _gethit, 0];
};
_i = _selections find _selection;
_olddamage = _gethit select _i;
_damage = _olddamage + ((_this select 2) - _olddamage) * 0.25;
_gethit set [_i, _damage];
_damage;
}];

this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];
this addMagazineTurret ['100Rnd_127x99_M2',[1]];

clearWeaponCargo this;
clearMagazineCargo this;

this addMagazineCargoGlobal ['PIPEBOMB',2];
this addMagazineCargoGlobal ['20Rnd_762x51_B_SCAR',20];
this addMagazineCargoGlobal ['MAAWS_HEAT', 10];
this addMagazineCargoGlobal ['stinger', 4];
this addWeaponCargoGlobal ['M110_NVG_EP1',2];
this addWeaponCargoGlobal ['MAAWS', 2];
this addWeaponCargoGlobal ['Stinger', 2];

hmmwv_s2 addAction [('<t color=''#FF0000''>' + ('Repair HMMWV GPK M2') + '</t>'),'vehicle\veh_repair.sqf',nil,+50,true,true,'','alive hmmwv_s2 && (!canMove hmmwv_s2 OR (damage hmmwv_s2>0 && damage hmmwv_s2<1)) && player distance hmmwv_s2<5'];";

processInitCommands;

How should this script be changed, or how should it be executed so it will add the weapons and gear to the vehicle and not multiply for every player on the server?

It seems as though the script executes twice if there are 2 people on the server. I need it to execute only 1 time and add the weapons and gear and other stuff to the vehicle and make sure that all players can then see the correct amount of weapons and gear in the cargo of the vehicle.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I changed the veh_add_gear_s2.sqf file to look like the following and it seemed to work in single player, but now my friend is sleeping, so I am unable to test it online with him. I'm hoping this will work.

hmmwv_s2 setVariable ["selections", []];
hmmwv_s2 setVariable ["gethit", []];
hmmwv_s2 addEventHandler ["HandleDamage",{

_veh = _this select 0;

_selections = _veh getVariable ["selections", []];
_gethit = _veh getVariable ["gethit", []];
_selection = _this select 1;
if !(_selection in _selections) then {
	_selections set [count _selections, _selection];
	_gethit set [count _gethit, 0];
};
_i = _selections find _selection;
_olddamage = _gethit select _i;
_damage = _olddamage + ((_this select 2) - _olddamage) * 0.25;
_gethit set [_i, _damage];
_damage;
}];

hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];
hmmwv_s2 addMagazineTurret ["100Rnd_127x99_M2",[1]];

clearWeaponCargo hmmwv_s2;
clearMagazineCargo hmmwv_s2;

hmmwv_s2 addMagazineCargoGlobal ["PIPEBOMB",2];
hmmwv_s2 addMagazineCargoGlobal ["20Rnd_762x51_B_SCAR",20];
hmmwv_s2 addMagazineCargoGlobal ["MAAWS_HEAT", 10];
hmmwv_s2 addMagazineCargoGlobal ["stinger", 4];
hmmwv_s2 addWeaponCargoGlobal ["M110_NVG_EP1",2];
hmmwv_s2 addWeaponCargoGlobal ["MAAWS", 2];
hmmwv_s2 addWeaponCargoGlobal ["Stinger", 2];

hmmwv_s2 addAction [("<t color=""#FF0000"">" + ("Repair HMMWV GPK M2") + "</t>"),"vehicle\veh_repair.sqf",nil,+50,true,true,"","alive hmmwv_s2 && (!canMove hmmwv_s2 OR (damage hmmwv_s2>0 && damage hmmwv_s2<1)) && player distance hmmwv_s2<5"];

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×