Jump to content
Sign in to follow this  
Finland

Random Weapon Spawns Inconsistent Between Players

Recommended Posts

Hi everyone,

This is my first post on the forums so I'm not sure if this is in the right spot, so feel free to move it if it belongs somewhere else.

So I've been trying to make random weapons and items spawn in buildings across the map, and it works fine with the exception of one thing: Everyone sees different items. The best way I can think of to describe it is as the script being executed client side rather than server side. I don't really know how to script from scratch, so this is just other people's scripts they have posted on the forums which I have edited for my needs.

_weapons = ["Colt1911", "Makarov", "AK_47_S", "AK_47_M", "AKS_74", "AK_74", "ACE_M72", "AKS_74_U","FN_FAL","huntingrifle","LeeEnfield","M16A2","M4A1","sa58p_EP1","Sa58V_EP1","ACE_RPK", "ACE_RPG22", "ACE_RPG27","ACE_RPG29", "AKS_74_pso","Saiga12K","SVD"];

_items = ["ACRE_PRC343", "ItemMap","ItemWatch","ItemCompass","ItemGPS","Binocular","ACE_ALICE_Backpack","ACE_Earplugs","ACE_GlassesGasMask_US","ACE_Map"];

_magazines = ["ACE_PG7VL_PGO7", "ACE_30Rnd_556x45_SB_Stanag", "ACE_75Rnd_545x39_S_RPK", "ACE_40Rnd_762x39_S_AK47", "30Rnd_762x39_SA58", "ACE_30Rnd_762x39_AP_AK47", "ACE_30Rnd_545x39_AP_AK", "10x_303", "10Rnd_762x54_SVD", "ACE_Bandage","ACE_Knicklicht_B","ACE_Knicklicht_Y","ACE_LargeBandage","ACE_Epinephrine","ACE_Medkit","ACE_Morphine","PipeBomb"];

hintsilent "placing loot";
_buildings = nearestObjects [player, ["house"], 60000];
_markernum = 0;
{
_building = _x;
hintsilent "placing loot.";
// search more positions
_positions = 0;
_i = 0;
_loop = 1;
while {_loop == 1} do
{
_next = _building buildingPos _i;
if (((_next select 0) == 0) && ((_next select 1) == 0) && ((_next select 2) == 0)) then
{
_loop = 0;
} else {
_positions = _positions + 1;
_i = _i + 1;
};
};
_posnumber = floor (random _positions);
_position = _building buildingpos _posnumber;
hintsilent "placing loot..";
if (random 100 > 80) then {
_weapon = _weapons call BIS_fnc_SelectRandom;
_mag=(getArray (configFile/"Cfgweapons"/_weapon/"magazines")) select 0;
       _weap = "weaponHolder" createVehicle [0,0];
       _weap addMagazineCargo [_mag,(round (random 2))];
       _weap addWeaponCargo [_weapon,1];
       _weap setPos [(_position select 0),(_position select 1),((_position select 2)-.14)];
};
_posnumber = floor (random _positions);
_position = _building buildingpos _posnumber;
hintsilent "placing loot...";
if (random 100 > 80) then {
_weapon = _items call BIS_fnc_SelectRandom;
       _weap = "weaponHolder" createVehicle [0,0];
       _weap addWeaponCargo [_weapon,1];
       _weap setPos [(_position select 0),(_position select 1),((_position select 2)-.14)];;
};
if (random 100 > 50) then {
_weapon = _magazines call BIS_fnc_SelectRandom;
       _weap addMagazineCargo [_weapon,(round(random 3))];
       _weap addMagazineCargo [_magazines, 2];
};

_posnumber = floor (random _positions);
_position = _building buildingpos _posnumber;

if (random 100 > 1) then {
_weapon = _magazines call BIS_fnc_SelectRandom;
       _weap = "weaponHolder" createVehicle [0,0];
       _weap addMagazineCargo [_weapon,(round(random 2))];
       _weap setPos [(_position select 0),(_position select 1),((_position select 2)-.14)];;
};

hintsilent "placing loot....";
} foreach _buildings; hint "Done!";

Any help would be appreciated!

Share this post


Link to post
Share on other sites

Run it only on the server and use the commands addWeaponCargoGlobal and addMagazineCargoGlobal.

On a related note, if anybody had any ideas on how to synchronize random weapons added to players inventory at the start of the mission, and have the correct weapon seen by everyone in the briefing/gear screen, I would like to hear those ideas because I am finding it a pain in the ass to get them synced.

Edited by 2nd Ranger

Share this post


Link to post
Share on other sites
Random is different on each client so run it serverside.

EDIT: Ninja'd

That's what I'm trying to figure out how to do. I have the script being run through a game logic, and I'm the host, so how would I run the script server side?

2nd Ranger, I'll try that. Thanks!

Share this post


Link to post
Share on other sites
isServer

if (isServer) then {
clearWeaponCargoGlobal;
// more
};

This goes at the top or what?

Share this post


Link to post
Share on other sites

Using addweaponcargoglobal just makes it so the script doesn't execute, how am I supposed to use it?

Share this post


Link to post
Share on other sites

there is no "clearWeaponCargoGlobal" command, and you need "deleteVehicle" for weaponholder items. addWeaponcargoGlobal is what u nead in script.. only the server should spawn these items, so depending how you call the script you'll need

if (isServer) then { ..all loot script stuff inside this };

or

if (!isServer) exitwith {};

at the top of the script.. i found that same script on armaholic a while back and it works pretty good. but i since modified it based on some code by JW Custom..

if (!isServer) exitwith {};

_weapons = ["M16A2","DMR","M4A1_AIM_CAMO","M4A1_AIM","G36K","AK_47_M","M1014","bizon","AK_107_PSO", "M14_EP1", "Bizon_Silenced","VSS_Vintorez","Saiga12K","Huntingrifle","m107","AKS_GOLD","SVD","SVD_Camo","LeeEnfield","ACE_MugLite","ACE_MugLite"];

_items = ["ItemMap","Binocular","ItemWatch","ItemCompass"];

_med = ["ACE_Medkit","ACE_Morphine","ACE_Tourniquet","ACE_Bandage","ACE_Epinephrine","ACE_Morphine"];

//_radio = ["","",""];

_pistol = ["Makarov","M9","Colt1911","revolver_EP1"];

_backpack = ["ACE_Coyote_Pack_Black","ACE_CharliePack_WMARPAT","ACE_Coyote_Pack_Wood","ACE_Backpack_US","ACE_BackPack","ACE_AssaultPack_BAF","ACE_BackPack_ACR","ACE_Backpack_ACU","ACE_CharliePack"];

_magazines = ["8Rnd_9x18_Makarov","30Rnd_556x45_Stanag","30Rnd_556x45_G36","7Rnd_45ACP_1911","6Rnd_45ACP","64Rnd_9x19_Bizon","ACE_20Rnd_762x51_B_G3","30Rnd_545x39_AK","20Rnd_762x51_DMR","8Rnd_B_Saiga12_Pellets","10Rnd_762x54_SVD","5x_22_LR_17_HMR","30Rnd_762x39_AK47","8Rnd_B_Beneli_74Slug","8Rnd_B_Beneli_Pellets","20Rnd_9x39_SP5_VSS","15Rnd_9x19_M9","10Rnd_127x99_M107","10Rnd_762x54_SVD","30Rnd_762x39_AK47","10x_303","30Rnd_556x45_G36","HandGrenade_East","17Rnd_9x19_glock17"];

_centerPoint = _this select 0; // define location for center.

_spawnSize = _this select 1; // radius to find house positions from centerpoint.

_debug = _this select 2; // if true a marker is shown on ititial spawn location.

_houseList = getPos _centerPoint nearObjects ["House",_spawnSize];

_i = 0;

{

_c = 0;

while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};

if (_c > 0) then

{

_ranNum = floor(random _c);

if (random 100 > 80) then {

_weapon = _weapons select floor(random(count _weapons));

_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_mag, (round (random 3))];

_weap addWeaponCargoGlobal [_weapon,1];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

_ranNum = floor(random _c);

if (random 100 > 60) then {

_weapon = _pistol select floor(random(count _pistol));

_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_mag, (round (random 2))];

_weap addWeaponCargoGlobal [_weapon,1];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

_ranNum = floor(random _c);

if (random 100 > 70) then {

_weapon = _items select floor(random(count _items));

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addWeaponCargoGlobal [_weapon,1];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

//_ranNum = floor(random _c);

// if (random 100 > 70) then {

// _weapon = _radio select floor(random(count _radio));

// _weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

// _weap addWeaponCargoGlobal [_weapon,1];

// _weap setPos (_x buildingPos _ranNum);

//

// if (_debug) then

// {

// _marker = format ['_marker%1',_i];

// _mkr = createMarker[_marker, getPos _weap];

// _marker setMarkerType 'hd_dot';

// _marker setMarkerSize[1, 1];

// _marker setMarkerDir 1;

// _marker setMarkerColor 'ColorOrange';

// _marker setMarkerText '';

// _i = _i + 1;

// };

//};

_ranNum = floor(random _c);

if (random 100 > 80) then {

_weapon = _backpack select floor(random(count _backpack));

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addWeaponCargoGlobal [_weapon,1];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

_ranNum = floor(random _c);

if (random 100 > 80) then {

_weapon = _med select floor(random(count _med));

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_weapon,1];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

_ranNum = floor(random _c);

if (random 100 > 70) then {

_weapon = _magazines select floor(random(count _magazines));

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_weapon,(round(random 3))];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

_ranNum = floor(random _c);

if (random 100 > 70) then {

_weapon = _magazines select floor(random(count _magazines));

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_weapon,(round(random 3))];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

_ranNum = floor(random _c);

if (random 100 > 90) then {

_weapon = _magazines select floor(random(count _magazines));

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_weapon,(round(random 3))];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

};

sleep 0.123;

} forEach _houseList;

Share this post


Link to post
Share on other sites

So how do I set the location in this part?

_centerPoint = _this select 0; // define location for center.
_spawnSize = _this select 1; // radius to find house positions from centerpoint.
_debug = _this select 2; // if true a marker is shown on ititial spawn location. 

And other than that, are there any other variables that I need to set?

Share this post


Link to post
Share on other sites
So how do I set the location in this part?
_centerPoint = _this select 0; // define location for center.
_spawnSize = _this select 1; // radius to find house positions from centerpoint.
_debug = _this select 2; // if true a marker is shown on ititial spawn location. 

And other than that, are there any other variables that I need to set?

if your using a trigger, name trigger "trigger1" (just for example, it can be anything) then use
_nul = [trigger1,200,false] execVM "whatever_u_named_it.sqf";

if in your init.sqf its

 [trigger1,200,false] execVM "whatever_u_named_it.sqf";

1st is the "name", second is "radius", third is "debug" but debug only works on initial spawn. (just incase u were clearing area then restocking it) just change the names and radius as needed.

Edited by Nimrod_Z

Share this post


Link to post
Share on other sites

Okay, so I think I may be doing it wrong.

I did change the classes in the categories, as well as some of the probabilities, so I'll include the script at the end.

So I have the script saved as "weapons.sqf" in my mission folder.

I have a game logic in the game with this in the init field "_nul = [guns,200,false] execVM "weapons.sqf";" And then a trigger in the middle of a town named "guns".

Nothing spawns and there is no indication that the script even ran.

Sorry to be so clueless, but you're being so helpful and I can't stop asking questions :rolleyes:

if (!isServer) exitwith {};

_weapons = ["RH_RK95", "RH_AK47", "RH_AKS47", "RH_AKM", "RH_AKMs", "RH_AK74", "RH_AKs74", "ACE_M72", "RH_AKS74U","FN_FAL","huntingrifle","LeeEnfield","RH_M16A1", "RH_AR10s", "RH_M16A2","RH_M4A1","sa58p_EP1","Sa58V_EP1","RH_aks74sp", "RH_rpk47", "ACE_RPG22", "ACE_RPG27","ACE_RPG29","Saiga12K","SVD"];

_items = ["ItemMap","ItemWatch","ItemCompass","ItemGPS","Binocular", "ACE_Earplugs","ACE_GlassesGasMask_US"];

_med = ["ACE_Medkit","ACE_Morphine","ACE_Tourniquet","ACE_ Bandage","ACE_Epinephrine","ACE_Morphine"];

_radio = ["ACRE_PRC343"];

_pistol = ["Colt1911", "Makarov"];

_backpack = ["ACE_Coyote_Pack_Wood", "ACE_ALICE_Backpack";

_magazines = ["ACE_PG7VL_PGO7", "8Rnd_B_Saiga12_Pellets", "8Rnd_B_Saiga12_74Slug", "ACE_30Rnd_556x45_SB_Stanag", "RH_45Rnd_545x39_mag", "RH_75Rnd_762x39_mag", "30Rnd_762x39_SA58", "30Rnd_762x39_AK47", "30Rnd_545x39_AK", "10x_303", "10Rnd_762x54_SVD", "ACE_Bandage","ACE_Knicklicht_B","ACE_Knicklicht_Y","ACE_LargeBandage","ACE_Epinephrine","ACE_Medkit","ACE_Morphine","PipeBomb"];


_centerPoint = _this select 0; // define location for center.
_spawnSize = _this select 1; // radius to find house positions from centerpoint.
_debug = _this select 2; // if true a marker is shown on ititial spawn location.

_houseList = getPos _centerPoint nearObjects ["House",_spawnSize];

_i = 0;

{
_c = 0;

while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
if (_c > 0) then
{
_ranNum = floor(random _c);
if (random 100 > 80) then {
_weapon = _weapons select floor(random(count _weapons));
_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_mag, (round (random 3))];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 60) then {
_weapon = _pistol select floor(random(count _pistol));
_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_mag, (round (random 4))];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 70) then {
_weapon = _items select floor(random(count _items));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 60) then {
_weapon = _radio select floor(random(count _radio));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 70) then {
_weapon = _backpack select floor(random(count _backpack));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 50) then {
_weapon = _med select floor(random(count _med));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 65) then {
_weapon = _magazines select floor(random(count _magazines));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,(round(random 2))];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 75) then {
_weapon = _magazines select floor(random(count _magazines));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,(round(random 3))];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 90) then {
_weapon = _magazines select floor(random(count _magazines));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,(round(random 3))];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};
};

sleep 0.123;

} forEach _houseList;

Edited by Finland

Share this post


Link to post
Share on other sites

yep, u shouldnt notice it ran at all. its not that invasive at all.. but, if u want to make sure it ran, you could always put a hint at the top of the script then another at the bottom to verify that it all ran and also turn on the debug. ("_nul = [guns,200,true] execVM "weapons.sqf";) you'll see a bunch of orange dots on map view where items spawned... also u could just use your gamelogic itself with the name (guns) instead of a logic and trigger if your spawning everything at the start of game. or just a trigger for that matter :D

Share this post


Link to post
Share on other sites
Okay, so I think I may be doing it wrong.

I did change the classes in the categories, as well as some of the probabilities, so I'll include the script at the end.

So I have the script saved as "weapons.sqf" in my mission folder.

I have a game logic in the game with this in the init field "_nul = [guns,200,false] execVM "weapons.sqf";" And then a trigger in the middle of a town named "guns".

Nothing spawns and there is no indication that the script even ran.

Sorry to be so clueless, but you're being so helpful and I can't stop asking questions :rolleyes:

if (!isServer) exitwith {};

_weapons = ["RH_RK95", "RH_AK47", "RH_AKS47", "RH_AKM", "RH_AKMs", "RH_AK74", "RH_AKs74", "ACE_M72", "RH_AKS74U","FN_FAL","huntingrifle","LeeEnfield","RH_M16A1", "RH_AR10s", "RH_M16A2","RH_M4A1","sa58p_EP1","Sa58V_EP1","RH_aks74sp", "RH_rpk47", "ACE_RPG22", "ACE_RPG27","ACE_RPG29","Saiga12K","SVD"];

_items = ["ItemMap","ItemWatch","ItemCompass","ItemGPS","Binocular", "ACE_Earplugs","ACE_GlassesGasMask_US"];

_med = ["ACE_Medkit","ACE_Morphine","ACE_Tourniquet","ACE_ Bandage","ACE_Epinephrine","ACE_Morphine"];

_radio = ["ACRE_PRC343"];

_pistol = ["Colt1911", "Makarov"];

_backpack = ["ACE_Coyote_Pack_Wood", "ACE_ALICE_Backpack";

_magazines = ["ACE_PG7VL_PGO7", "8Rnd_B_Saiga12_Pellets", "8Rnd_B_Saiga12_74Slug", "ACE_30Rnd_556x45_SB_Stanag", "RH_45Rnd_545x39_mag", "RH_75Rnd_762x39_mag", "30Rnd_762x39_SA58", "30Rnd_762x39_AK47", "30Rnd_545x39_AK", "10x_303", "10Rnd_762x54_SVD", "ACE_Bandage","ACE_Knicklicht_B","ACE_Knicklicht_Y","ACE_LargeBandage","ACE_Epinephrine","ACE_Medkit","ACE_Morphine","PipeBomb"];


_centerPoint = _this select 0; // define location for center.
_spawnSize = _this select 1; // radius to find house positions from centerpoint.
_debug = _this select 2; // if true a marker is shown on ititial spawn location.

_houseList = getPos _centerPoint nearObjects ["House",_spawnSize];

_i = 0;

{
_c = 0;

while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
if (_c > 0) then
{
_ranNum = floor(random _c);
if (random 100 > 80) then {
_weapon = _weapons select floor(random(count _weapons));
_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_mag, (round (random 3))];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 60) then {
_weapon = _pistol select floor(random(count _pistol));
_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_mag, (round (random 4))];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 70) then {
_weapon = _items select floor(random(count _items));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 60) then {
_weapon = _radio select floor(random(count _radio));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 70) then {
_weapon = _backpack select floor(random(count _backpack));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addWeaponCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 50) then {
_weapon = _med select floor(random(count _med));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,1];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 65) then {
_weapon = _magazines select floor(random(count _magazines));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,(round(random 2))];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 75) then {
_weapon = _magazines select floor(random(count _magazines));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,(round(random 3))];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};

_ranNum = floor(random _c);
if (random 100 > 90) then {
_weapon = _magazines select floor(random(count _magazines));
_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];
_weap addMagazineCargoGlobal [_weapon,(round(random 3))];
_weap setPos (_x buildingPos _ranNum);

if (_debug) then
{
_marker = format ['_marker%1',_i];
_mkr = createMarker[_marker, getPos _weap];
_marker setMarkerType 'hd_dot';
_marker setMarkerSize[1, 1];
_marker setMarkerDir 1;
_marker setMarkerColor 'ColorOrange';
_marker setMarkerText '';
_i = _i + 1;
};
};
};

sleep 0.123;

} forEach _houseList;

I had this issue while trying to do the same thing. I fixed it by having the script run after the player has loaded, so put a 'sleep' at the top of the script of about 5 seconds. waituntil {player == player}; is the usual method of checking for this but you're only running it serverside so it doesn't work. The only other thing I can think of is using the 'reveal' command on the weapon holders

Share this post


Link to post
Share on other sites

Hmm... Setting the debug to true doesn't show anything on the map, so I don't think it's working. Based on the information I gave last post, since I haven't changed anything since then, what do you think it might be?

Share this post


Link to post
Share on other sites

just turning debug on with script errors wont make it run any better... ;) just by glancing at what u changed, i can see that the backpack section is missing a ]; at the end. that would def cause an error and not finish script. after that check your RPT file for any script errors.. and also put a few hints in the script until u know u got it working..

at start of script put

hintSilent "script started";

then do the same at the very end of the script with one that says "script finished". the script actually works very well for what it does. its not perfect but, short of getting all the locations and manually putting them in an array (like day_z) its works extremely good for just throwing it on a map.. and if u still have any issue try putting the original one i posted to see that it works, then just change your weapons and items again.

Share this post


Link to post
Share on other sites

Okay, so I actually took the time to go over everything in the script, and I found a few syntax errors. I fixed those and now it works.

I just have one more question, is there a way to make sure that every time a gun spawns, at least one magazine spawns with it?

Thanks!

---------- Post added at 03:59 ---------- Previous post was at 03:25 ----------

Alright, I figured that one out too. Last question:

If I want to add another category of weapon, let's say "weaponrare", would I just make a new line at the top like "_weaponsrare ["","",""];"?

Share this post


Link to post
Share on other sites

just add your rareweapons array (like all others at top of script) then add

_ranNum = floor(random _c);

if (random 100 > 80) then {

_weapon = _rareweapons select floor(random(count _weapons));

_mag = (getArray (configFile / "CfgWeapons" / _weapon / "magazines")) select 0;

_weap = createVehicle ["WeaponHolder", [0,0], [], 0, "CAN_COLLIDE"];

_weap addMagazineCargoGlobal [_mag, (round (random 3))];

_weap addWeaponCargoGlobal [_weapon,1];

_weap setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _weap];

_marker setMarkerType 'hd_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

notice line 3 is weapon = _rareweapons

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  

×