Arma 3
a better way to random spawn weapons on the ground?
what im currently doing because i cannot think of another way right now, is placing down a bunch of triggers and storing them in an array with selectRandom and spawning groundWeaponHolders on those triggers. then i addWeaponCargoGlobal which pulls a rifle from an array with selectRandom and addMagazineCargoGlobal to the weapon holder. now this would be fine if i didnt have well over 50 spawns, is there a way i can just run a loop or something that keeps pulling a random trigger out of the array and spawning a weapon on it? i have multiple different types of calibers so the magazines that spawn with the rifle would need to be of the correct caliber which i already have setup my way, but its just so many lines and i feel like theres a much better way of doing this. i want a random weapon with a random amount of magazines to spawn on a random marker but more efficiently than what i have here. i currently have 170 triggers to spawn on and will be adding probably another 200 more with a much bigger variety, as you can see this is a pain in the but.

_weaponLocationSelection = { weaponSpawnTriggers = selectRandom [weaponSpawn_1, weaponSpawn_2, weaponSpawn_3, weaponSpawn_4, weaponSpawn_5, weaponSpawn_6, weaponSpawn_7, weaponSpawn_8, weaponSpawn_9, weaponSpawn_10, weaponSpawn_11, weaponSpawn_12, weaponSpawn_13, weaponSpawn_14, weaponSpawn_15, weaponSpawn_16, weaponSpawn_17, weaponSpawn_18, weaponSpawn_19, weaponSpawn_20, weaponSpawn_21, weaponSpawn_22, weaponSpawn_23, weaponSpawn_24, weaponSpawn_25, weaponSpawn_26, weaponSpawn_27, weaponSpawn_28, weaponSpawn_29, weaponSpawn_30, weaponSpawn_31, weaponSpawn_32, weaponSpawn_33, weaponSpawn_34, weaponSpawn_35, weaponSpawn_36, weaponSpawn_37, weaponSpawn_38, weaponSpawn_39, weaponSpawn_40, weaponSpawn_41, weaponSpawn_42, weaponSpawn_43, weaponSpawn_44, weaponSpawn_45, weaponSpawn_46, weaponSpawn_47, weaponSpawn_48, weaponSpawn_49, weaponSpawn_50, weaponSpawn_51, weaponSpawn_52, weaponSpawn_53, weaponSpawn_54, weaponSpawn_55, weaponSpawn_56, weaponSpawn_57, weaponSpawn_58, weaponSpawn_59, weaponSpawn_60, weaponSpawn_61, weaponSpawn_62, weaponSpawn_63, weaponSpawn_64, weaponSpawn_65, weaponSpawn_66, weaponSpawn_67, weaponSpawn_68, weaponSpawn_69]; }; _ffsweaponSelection = { ffsweaponSelection = selectRandom ["arifle_Mk20_F", "arifle_SDAR_F", "arifle_TRG21_F", "arifle_SPAR_01_blk_F"]; magazineCount = selectRandom [1, 2, 3]; }; _spfweaponSelection = { spfweaponSelection = selectRandom ["arifle_Katiba_F", "arifle_MXC_F", "arifle_MX_F", "arifle_MXM_RCO_pointer_snds_F", "arifle_ARX_blk_F"]; magazineCount = selectRandom [1, 2, 3]; }; _createWeaponHolders = { call _weaponLocationSelection; wep1 = createVehicle ["groundWeaponHolder", getPosATL weaponSpawnTriggers, [], 0, "NONE"]; call _weaponLocationSelection; wep2 = createVehicle ["groundWeaponHolder", getPosATL weaponSpawnTriggers, [], 0, "NONE"]; call _weaponLocationSelection; wep3 = createVehicle ["groundWeaponHolder", getPosATL weaponSpawnTriggers, [], 0, "NONE"]; call _weaponLocationSelection; wep4 = createVehicle ["groundWeaponHolder", getPosATL weaponSpawnTriggers, [], 0, "NONE"]; call _weaponLocationSelection; wep5 = createVehicle ["groundWeaponHolder", getPosATL weaponSpawnTriggers, [], 0, "NONE"]; call _weaponLocationSelection; wep6 = createVehicle ["groundWeaponHolder", getPosATL weaponSpawnTriggers, [], 0, "NONE"]; call _ffsweaponSpawn; call _spfweaponSpawn; }; _ffsweaponSpawn = { call _ffsweaponSelection; wep1 addWeaponCargoGlobal [ffsweaponSelection, 1]; wep1 addMagazineCargoGlobal ["30Rnd_556x45_Stanag", magazineCount]; call _ffsweaponSelection; wep2 addWeaponCargoGlobal [ffsweaponSelection, 1]; wep2 addMagazineCargoGlobal ["30Rnd_556x45_Stanag", magazineCount]; call _ffsweaponSelection; wep3 addWeaponCargoGlobal [ffsweaponSelection, 1]; wep3 addMagazineCargoGlobal ["30Rnd_556x45_Stanag", magazineCount]; }; _spfweaponSpawn = { call _spfweaponSelection; wep4 addWeaponCargoGlobal [spfweaponSelection, 1]; wep4 addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", magazineCount]; call _spfweaponSelection; wep5 addWeaponCargoGlobal [spfweaponSelection, 1]; wep5 addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", magazineCount]; call _spfweaponSelection; wep6 addWeaponCargoGlobal [spfweaponSelection, 1]; wep6 addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", magazineCount]; }; call _createWeaponHolders;
Last edited by IM SORRY BUFFALO; Oct 28, 2017 @ 12:19am
< >
Showing 1-8 of 8 comments
MrMessy187 Oct 28, 2017 @ 4:59am 
Hey,

I am also working on a lootsystem, although i am doing it a completely different way..
IM SORRY BUFFALO Oct 28, 2017 @ 12:14pm 
Originally posted by MrMessy187:
Hey,

I am also working on a lootsystem, although i am doing it a completely different way..
hi dom lol. would you mind giving me a hand or atleast a better way of doing it? i was thinking about getting all the buildings inside a trigger and sorting them into an array and spawning a random weapon in 40% of the buildings, however idk how well this would work or how to spawn lets say one weapon at the bottom floor and one at the top floor. and plus right now its annoying trying to sort every rifle by caliber so i can spawn the right ammo type with the rifle.
Last edited by IM SORRY BUFFALO; Oct 28, 2017 @ 12:15pm
MrMessy187 Oct 28, 2017 @ 2:10pm 
hey pal,

my code is integrated in my "main" mission code.. but i can show the code and some functions with explanation of what i'm doing in that code if you like..

i don't really want to start breaking down my code in each function to give you a working copy of the function without all the extra stuff i've added... ummmm next post i'll break down some stuff and post what i have done... i know some will help you..

before i do that, are you wanting to spawn stuff in houses OR at random positions you are marking on the map?

:)
Last edited by MrMessy187; Oct 28, 2017 @ 2:22pm
MATTXYO Oct 28, 2017 @ 3:59pm 
Possible shorter code for first part;
_weaponLocationSelection = { weaponSpawnTrigNum = floor random [0,30,69]; selectedWeaponSpawn = call compile format ['weaponSpawn_%1',weaponSpawnTrigNum]; };
Last edited by MATTXYO; Oct 28, 2017 @ 7:47pm
Condasoft Oct 28, 2017 @ 5:26pm 
Thanks for sharing this with us, I too was looking for this ;D
MATTXYO Oct 29, 2017 @ 8:05pm 
Another Possiblility, it can be refined more but as a rough indication here goes >>

I have only used one of the weapon arrays as I am not totally sure how you wish to control the spawns etc..

_weaponSpawnSelection = { _weaponSpawnsNum = _this select 0; while { _weaponSpawnsNum != 0 } do { _SpawnNumSelection = _weaponSpawnsNum; _weaponSpawnsNum = _WeaponSpawnsNum -1; _weaponSpawnPos = call compile format ['weaponSpawn_%1',_SpawnNumSelection]; sleep 0.1; _x = createVehicle ["groundWeaponHolder", getPosATL _weaponSpawnPos, [], 0, "NONE"]; _randWeapon = selectRandom ["arifle_Mk20_F", "arifle_SDAR_F", "arifle_TRG21_F", "arifle_SPAR_01_blk_F"]; _x addWeaponCargoGlobal [_randWeapon,1]; _x addMagazineCargoGlobal [(getArray(configfile >> "cfgWeapons" >> _randWeapon>> "magazines"))select 0,selectRandom [1,2,3]]; }; }; [3] call _weaponSpawnSelection; //Total number of weaponSpawn Triggers.

Triggers are to be named weaponSpawn_1, weaponSpawn_2, weaponSpawn_3.. etc as in your previous script, then pass the total number placed with the call.

[3] call _weaponSpawnSelection

Last edited by MATTXYO; Oct 30, 2017 @ 7:39am
Tajin Oct 30, 2017 @ 2:48am 
Do not use triggers to mark you spawn locations. Use mapmarkers and give them specific names or at least a prefix.

You can then use the "allMapMarkers" command to get a list of all markers and filter them by their name.


Like this for example:
fnc_findMarkers = { _params[ ["_prefix", "", [""]] ]; private ["_len"]; _len = count _prefix; allMapMarkers select { (_x select [0, _len]) isEqualTo _prefix } }; _markers = ["prefix_"] call fnc_findMarkers;


Aside from that, having a huge amount of unnecessary triggers on the map is not going to do the performance any good.
Last edited by Tajin; Oct 30, 2017 @ 2:51am
IM SORRY BUFFALO Nov 4, 2017 @ 9:47am 
heres what i ended up with, works great and exactly what i needed thanks to the help of MrMessy
_spawnChance = 50; _magazineArry = [1, 2, 3, 4]; _houseMarker = getPos weaponLoc; _weaponArray = []; _triggerSize = triggerArea weaponLoc; _sizeY = _triggerSize select 1; _weaponConfig = "true" configClasses (configFile >> "CfgWeapons"); { _weaponName = configName (_x); _parentNames = [_x, true] call BIS_fnc_returnParents; if ("Rifle" in _parentNames) then { _weaponArray append [_weaponName]; }; } forEach _weaponConfig; _houses = _houseMarker nearObjects ["house", _sizeY]; { _buildingPos = [_x] call BIS_fnc_buildingPositions; { if (_spawnChance > random 100) then { _weapons = _weaponArray call BIS_fnc_selectRandom; _magazineCount = _magazineArry call BIS_fnc_selectRandom; _holder = "WeaponHolderSimulated" createVehicle [0,0,0]; _holder setPos _x; _holder addWeaponCargoGlobal [_weapons,1]; _wepMagazines = getArray (configFile >> "CfgWeapons" >> _weapons >> "magazines"); _magazines = _wepMagazines select 0; _holder addMagazineCargoGlobal [_magazines, _magazineCount]; }; } forEach _buildingPos; } forEach _houses;
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: Oct 28, 2017 @ 12:18am
Posts: 8