Jump to content

Recommended Posts

So I pulled this script and am building a little persistant map for me and some friends to play on and have got stuck with the loot spawning. (Its a warhammer 40k mod pack in case that makes a difference.)
Here is what I got so far...
gun = ["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", "arifle_Khaybar_F", "arifle_Khaybar_C_F", "arifle_Khaybar_GL_F", "hgun_rook40_F"] call BIS_fnc_selectRandom;  
Waffe1 = "groundweaponholder" createVehicle getpos this;
Waffe1 addWeaponCargo [gun,1];
Waffe1 setPos [getPos this select 0,getPos this select 1,0.00];

(I know none of those are from a 40k mod pack but it is the code I used to test and it works)
I put that into something like an invisible helipad and I spawn a random weapon from the list.

My problem begins when I try to get the script to repeat after say an hour. I have tried, unsuccessfully, to pack it in an execVM only to have it slap me with errors.
What I really want is loot boxes that spawn and despawn when the player is 500m away every 60 minutes. But baby steps as I am new to scripting.
Can anyone help?

Edited by Wraith_last
mistype

Share this post


Link to post
Share on other sites

What I really want is loot boxes that spawn and despawn when the player is 500m away every 60 minutes

Could you elaborate?

Share this post


Link to post
Share on other sites

When a player is 500m away, the box is empty/not there. when they are within 500m loot spawns in a box/the box spawns in. Each time it respawns there is a different loot list in said box.
I know how to make a loot list, and that I can use addItemCargo to achive at least part of this, though I am not sure how yet. I am still learning and need all the help I can get, but a point in the right direction would be enough.
I also wanna save the players inventory on logout using saveNameSpace but have not figured out what you actually do with it yet.

Edited by Wraith_last
Additional

Share this post


Link to post
Share on other sites
3 hours ago, Wraith_last said:

When a player is 500m away, the box is empty/not there. when they are within 500m loot spawns in a box/the box spawns in. Each time it respawns there is a different loot list in said box.

 

Imho, totally useless! You will not save any resource with that. On contrary!

 

You're in multiplayer. So, the crate can be created locally (visible, existing only on a player's PC) In this case, use createVehicleLocal, then each crate is different and not broadcast from server.

But, you can do it simpler, placing an empty crate in editor (so shared by players), then your command addItemCargo will work locally (on contrary of addItemCargoGlobal). So you can have different cargo inside the same crate.

If you want to change this cargo when a player respawns, just code something in onPlayerRespawn.sqf or the event handlers concerning respawn (like this one or this one)

Share this post


Link to post
Share on other sites

Thanks! I ended up using this in a .sqf

params["_box"];
while {true} do
{
  clearMagazineCargo _box;
  _Magazine = ["TIOW_OCC_CarbineMag_40rnd","TIOW_OCC_CarbineMag_40rnd_Tracer","M36KantRifle_mag","TIOW_LongLas_Mag"] call BIS_fnc_selectRandom;
 
  _box addMagazineCargo [_Magazine, 3];  

  sleep 5400;
};
With the variations for medical, weapons ect.
How would I add an empty slot? as if there is a chance nothing would spawn in the box.
"", For example?

I figured I could further randomise the loot by making the compo spawn in and have only a 40% chance that the boxes would be there. That way every time I restart the server the boxes would be organised as if in different buildings and as many of the buildings are the same, I could copy and paste the compo to save time. So the next set will be working out how to save the designated equipment boxes between server restarts. I found a code for player inventory between logings (not tried it yet.)
I have timed respawning enemies now too for the enemy bases, timed to about twenty five mins to allow for looting but not so fast they will respawn while the players are still there.

Share this post


Link to post
Share on other sites
5 hours ago, Wraith_last said:

How would I add an empty slot? as if there is a chance nothing would spawn in the box.

params["_box"];
while {true} do{
	clearMagazineCargo _box;
	private _magazine = selectRandom ["TIOW_OCC_CarbineMag_40rnd","TIOW_OCC_CarbineMag_40rnd_Tracer","M36KantRifle_mag","TIOW_LongLas_Mag"];
	_box addMagazineCargo [_magazine, [0,3] select (round (random 1) isEqualTo 1)];
	sleep 5400;      
};

 

Share this post


Link to post
Share on other sites
8 hours ago, RCA3 said:

params["_box"];
while {true} do{
	clearMagazineCargo _box;
	private _magazine = selectRandom ["TIOW_OCC_CarbineMag_40rnd","TIOW_OCC_CarbineMag_40rnd_Tracer","M36KantRifle_mag","TIOW_LongLas_Mag"];
	_box addMagazineCargo [_magazine, [0,3] select (round (random 1) isEqualTo 1)];
	sleep 5400;      
};

 

Interesting.. will give it a go, though I gotta admit I have no idea what the new commands do or how they influence the way gear spawns. Would you explain the [_magazine, [0,3] select (round (random 1) isEqualTo 1)]; part to me?
Why is there no whole number after _magazine? Spawn percentage chance?
The other two I have no idea.

Share this post


Link to post
Share on other sites
19 hours ago, Wraith_last said:

Spawn percentage chance?

Yup. It's 50/50 now but you should change the order of first param so it returns true (with magazines) more often:

_box addMagazineCargo [_magazine, [3,0] select (round (random 4) isEqualTo 0)]; //20% chance of being 0 (empty)

Or change to isNotEqualTo 😛

_box addMagazineCargo [_magazine, [0,3] select (round (random 4) isNotEqualTo 0)]; //20% chance of being 0 (empty)

Share this post


Link to post
Share on other sites

[_magazine, [0,3] select (round (random 1) isEqualTo 1)] is the convoluted way for randomizing 0 or 3 as magazine quantity. (round random is 0 or 1, then false or true compared to 1, then pick 0 as false or 3 as true in selection...

 

You can replace by: [_magazine, selectRandom [0,3]]

You can also use: [_magazine, selectRandomWeighted [0,1,3,3] ]

  • Like 1

Share this post


Link to post
Share on other sites

Awesome, you guys are the best!
One last question (that I can think of), is it possible to add a player specific Arsenal/Storage box? For example a box assigned to a slot or a box simular to the save player inventory script on logout that will act like a personal locker for the individual players to store extra equipment in? This one is way out of my skills to even attempt TBH but it would add a nice finishing touch to the player base.

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

×