Jump to content
Sign in to follow this  
PlacidPaul

random weapon on table script

Recommended Posts

I had this working for SP, but made some changes for multiplayer and cant get it to work.

init.

newWeapons = true;
rnum = 5;
rnum2 = 5;

randomWeapon.sqf

if (newWeapons) then {

if (isServer) then
{
rnum = floor (random 4);   
rnum2 = floor (random 4);   
publicVariable "rnum";   
publicVariable "rnum2";

table1 = createvehicle [ "groundweaponholder",[getPos randSpawn select 0,getPos randSpawn select 1,0],[], 0, "can_Collide"]; 
table2 = createvehicle [ "groundweaponholder",[getPos randSpawn2 select 0,getPos randSpawn2 select 1,0],[], 0, "can_Collide"];
table1 setPos [getPos randSpawn select 0,getPos randSpawn select 1,0.85];
table2 setPos [getPos randSpawn2 select 0,getPos randSpawn2 select 1,0.85];

};

sleep 3;	
if (rnum == 0) then { table1 addweaponcargo ["srifle_EBR_F",1];};
if (rnum == 1) then { table1 addweaponcargo ["arifle_MX_f",1]; };
if (rnum == 2) then { table1 addweaponcargo ["arifle_MXM_F",1]; };
if (rnum == 3) then { table1 addweaponcargo ["arifle_TRG20_F",1]; };
if (rnum == 4) then { table1 addweaponcargo ["arifle_Katiba_F",1]; };
if (rnum2 == 0) then { table2 addweaponcargo ["srifle_EBR_F",1]; };
if (rnum2 == 1) then { table2 addweaponcargo ["arifle_MX_f",1]; };
if (rnum2 == 2) then { table2 addweaponcargo ["arifle_MXM_F",1]; };
if (rnum2 == 3) then { table2 addweaponcargo ["arifle_TRG20_F",1]; };
if (rnum2 == 4) then { table2 addweaponcargo ["arifle_Katiba_F",1]; };

newWeapons = false;
sleep 600;
clearweaponcargo table1;
clearmagazinecargo table1;
clearweaponcargo table2;
clearmagazinecargo table2;
newWeapons = true;
};

My understanding was that createVehicle array, needed to only be done on one machine, but it seemingly works if the createVehicle block is down with addweaponcargo, but I'm not sure if that's proper MP.

I'm calling this with a repeating trigger, nul = []execVM "randomWeapon.sqf"; Maybe that's problem, but im unsure how to make a function without everyone having different random numbers.

thanks

Share this post


Link to post
Share on other sites

Have you tried addweaponcargoglobal? MP synchronized.

---------- Post added at 20:16 ---------- Previous post was at 20:00 ----------

_randomWeapons1 = ["srifle_EBR_F","arifle_MX_f","arifle_MXM_F","arifle_TRG20_F","arifle_Katiba_F"] call bis_fnc_selectRandom;   
_randomWeapons2 = ["srifle_EBR_F","arifle_MX_f","arifle_MXM_F","arifle_TRG20_F","arifle_Katiba_F"] call bis_fnc_selectRandom;  

_holder1 = createVehicle ["groundweaponholder",[getPosATL randSpawn1 select 0, getPosATL randSpawn1 select 1, 0.85], [], 0, "can_Collide"]; 
_holder2 = createVehicle ["groundweaponholder",[getPosATL randSpawn2 select 0, getPosATL randSpawn2 select 1, 0.85], [], 0, "can_Collide"];

_holder1 addWeaponCargoGlobal [_randomWeapons1, 1];
_holder2 addWeaponCargoGlobal [_randomWeapons2, 1];

Edited by cobra4v320

Share this post


Link to post
Share on other sites

you should definetly be using the global versions of those commans because the one's currently used are local so only the server would see them. also, it looks like there are several things you really don't need (unless they are part of some other script). like why the need to publicVariable if you have the script wrapped in isServer check? also you mentioned a repeating trigger, why not just make the script itself loop and you wont even need a trigger ?

example

if (!isServer) exitWith {};

// spawn weapons on table function
tableWeapons = 
{
// spawn objects at specified location.  
table1 = createvehicle ["groundweaponholder",[getPosATL randSpawn select 0,getPosATL randSpawn select 1,0.85],[], 0, "can_Collide"]; 
table2 = createvehicle ["groundweaponholder",[getPosATL randSpawn2 select 0,getPosATL randSpawn2 select 1,0.85],[], 0, "can_Collide"];
table1 setDir floor (random 360);
table2 setDir floor (random 360);

// select random weapon
_wep1 = ["srifle_EBR_F","arifle_MX_f","arifle_MXM_F","arifle_TRG20_F","arifle_Katiba_F"] call bis_fnc_selectRandom;   
_wep2 = ["srifle_EBR_F","arifle_MX_f","arifle_MXM_F","arifle_TRG20_F","arifle_Katiba_F"] call bis_fnc_selectRandom; 
sleep 0.2;

// add selected weapons
table1 addWeaponCargoGlobal [_wep1,1];
table2 addWeaponCargoGlobal [_wep2,1];
};

// clear weapons on table function
clearTableWeapons = 
{
clearWeaponCargoGlobal table1;
clearMagazineCargoGlobal table1;
clearWeaponCargoGlobal table2;
clearMagazineCargoGlobal table2;
};

// loop to spawn and then clear weapons after sleep time.
while {true} do 
{
_handle = [] spawn tableWeapons;
waitUntil{scriptDone _handle};
sleep 600;  
_handle = [] spawn clearTableWeapons;
waitUntil{scriptDone _handle};
};

Share this post


Link to post
Share on other sites

Thanks guys and nimrod you always help me out. Your right about control statements, it was the quickest way for me to test it, with my kids puking all spring break. But, I was totally unaware of addweaponcargoglobal. I swear the biki hates me.

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  

×