Forum Jump :

Author Message

Posts: 1

Level: Member

Country: au
In-game name:

#1 Posted at 2018-02-08 04:57        
//Solved I needed to use "WeaponHolderSimulated_Scripted" in my createVehicle. I believe it's because the weapon holder was empty for too long so it got deleted. The _scripted variant does not auto delete but I already have a cleanup script in place to delete it later.

Hi Folks, I'm a bit new so this is probably something dumb that I'm doing.

I'm attempting to spawn random loot in a random room in a random building in a random city. I can sucessfully spawn players in a random room but creating loot is proving to be more difficult. This script works about 1/4 of the time. It never throws any debug error messages, the loot just does not appear! I believe createVehicle is creating null objects most of the time. Here's the script:

//ARRAYS FOR LOOT I ripped this from someone else's script just for testing and will make my own arrays later
_gunToSpawn = ["arifle_MX_F", "arifle_MX_GL_F", "arifle_MXC_F", "arifle_TRG20_F", "arifle_TRG21_F", "arifle_TRG21_GL_F", "arifle_MXM_F", "srifle_EBR_F", "LMG_Mk200_F", "hgun_P07_F", "hgun_rook40_F"];
_ammoToSpawn = ["30Rnd_65x39_Caseless_mag", "100Rnd_65x39_Caseless_mag", "30Rnd_65x39_caseless_mag_Tracer", "100Rnd_65x39_caseless_mag_Tracer", "30Rnd_65x39_case_mag", "20Rnd_762x45_Mag", "16Rnd_9x21_Mag", "30Rnd_9x21_Mag", "20Rnd_556x45_UW_Mag", "30RND_556x45_Stanag", "200RND_65x39_Cased_box_Tracer", "RPG32_F", "ATMine_Range_Mag", "APERSMine_Range_Mag", "ClaymoreDirectionalMine_Remote_Mag", "DemoCharge_Remote_Mag", "APERSBoundingMine_Range_Mag", "SLAMDirectionalMine_Wire_Mag", "APERSTripMine_Wire_Mag", "1Rnd_HE_Grenade_shell", "1Rnd_Smoke_Grenade_shell", "1Rnd_SmokeGreen_Grenade_shell", "1Rnd_SmokeYellow_Grenade_shell", "1Rnd_SmokePurple_Grenade_shell", "1Rnd_SmokeBlue_Grenade_shell", "1Rnd_SmokeOrange_Grenade_shell", "SmokeShellRed", "SmokeShell", "SmokeShellGreen", "SmokeShellYellow", "SmokeShellPurple", "SmokeShellBlue", "SmokeShellOrange"];
_itemToSpawn = ["muzzle_snds_H", "muzzle_snds_L", "muzzle_snds_B", "muzzle_snds_H_MG", "optic_Arco", "optic_Hamr", "optic_Aco", "optic_ACO_grn", "optic_Holosight", "acc_flashlight", "acc_pointer_IR", "FirstAidKit", "Toolkit"];

activeLoot = [];

for "_i" from 1 to 10 do {
//find room to spawn loot
_lootRoomPos = nil;
while {isNil "_lootRoomPos"} do {
_randCityLocation = [(bulwarkCity select 0) + (random [-10, 0, 10]),(bulwarkCity select 1) + (random [-10, 0, 10]), 0]; //bulwarkCity is a public variable defined outside of this script.
_lootBulding = nearestBuilding _randCityLocation;
_lootRooms = _lootBulding buildingPos -1;
_lootRoomPos = selectRandom _lootRooms;
_lootHolder = "WeaponHolderSimulated" createVehicle _lootRoomPos; //create the container for the weapon
_lootHolder setVehicleVarName ("loot" + str _i); //to make the var unique to put in a table so I can delete the loot later
//determine type of loot to spawn
_lootToSpawn = floor random [1,3,3];
if (_lootToSpawn == 1) then { //spawn weapon
_lootHolder addWeaponCargo [selectRandom _gunToSpawn,1];
if (_lootToSpawn == 2) then {
_lootHolder addmagazinecargo [selectRandom _ammoToSpawn,1];
if (_lootToSpawn == 3) then {
_lootHolder additemcargo [selectRandom _itemToSpawn,1];
_lootHolder setPos [_lootRoomPos select 0, _lootRoomPos select 1, (_lootRoomPos select 2) + 2]; //set the containers POS so it's not in the floor
activeLoot pushback _lootHolder; //add to array so it can be deleted later

The really odd thing is that this works in certain locations, reliably. Then in others it thinks the loot is at 0,0,0 which probably means it's a null object and has not been created, I think. Does anyone know of any issues with createVehicle in certain locations or buildings?? I've tried a ton of different things, this is just the most reliable code I have come up with. Sorry if this is something known and online, I've done a ton of googling!

This post was edited by Hilltop (2018-02-08 07:35, 373 days ago)