Jump to content

Recommended Posts

Hello!
I'll try to explain this carefully, but I want to warn you that I do not understand anything about scripting, and I do not speak English either, of which it hurts me a lot in endenter the script.

 

I have a SQF file with the script below, this script adds some random items, so I put that SQF script inside the Init of a "Land_Battery_F" battery so that each battery scattered on the map manages these items.

 

*My file "loot.sqf"

if ! ( isServer ) exitWith {};


_loot = nearestObject [player, "Land_Battery_F"];

_weap = selectRandom ["hgun_Pistol_heavy_01_F", "hgun_P07_F", "hgun_Pistol_heavy_02_Yorris_F", "hgun_Rook40_F"];
_qtd1 = random 3;
_qtd2 = random 1;
_this = _loot;


_Loot1 = "groundweaponholder" createVehicle getpos _this; // Creates "groundweaponholder

_magazines = getArray (configFile / "CfgWeapons" / _weap / "magazines");
_magazineClass = _magazines call bis_fnc_selectRandom; 

_Loot1 addWeaponCargoGlobal [_weap, 1]; // creater weapon
_Loot1 addMagazineCargoGlobal [_magazineClass, _qtd1]; // creates magazine
_Loot1 addItemCargoGlobal ["optic_Arco_blk_F", _qtd2]; // creates optics
_Loot1 addBackpackCargoGlobal ["B_AssaultPack_blk", _qtd2]; // creates backpacks
_Loot1 attachTo [_this, [0,0,0.62]];  
detach _Loot1; 

inside the Init of a battery ("Land_Battery_F")

 

nul = execVM "target_loot.sqf";

The problem I'm encountering is ..

 

1. The items only generate on the battery closest to the player;

2. All items from other batteries always generates on the battery closest to the player, so the first battery is with all items generated of other battery placed on the map.

 

I believe the problem is in the line below since it uses the player's position.

 

_loot = nearestObject [player, "Land_Battery_F"];

 

I searched for solutions in other scripts that I about adding loot, but I always get lost inside them, because as I said, I do not understand anything of script and also do not understand English, because I always use the translator for everything here.

 

The help I'd like is the correct command for each battery placed on the map add your own script item.

 

If anyone can help me in this, I will be very grateful.

Share this post


Link to post
Share on other sites

Well a few things:

BIS_fnc_selectRandom has long been replaced with a dedicated script command.

To make loot more interesting you could use a weighted randomization. So certain (more powerful) weapons will be chosen less likely, giving some sort of accomplishment to the player.

 

if ! ( isServer ) exitWith {};

It's never needed in this case, since the script is yours and you know where it's executed. Just execute it on the server through remoteExec or, for stuff that needs to run only once use initServer.sqf.

 

You can use helper objects like arrows, markers, or predefined positions if you want to retrieve multiple positions on the game map, like this:

 

//initServer.sqf or wherever you seem fit

//place objects on the map, like battery or similar, put this in each objects init field:
this setVariable ["TAG_fnc_lootSpawn",true];

//this marks each object as reference of where to spawn loot, to retrieve all loot positions and get rid of the no longer needed objects:
_lootMarkerObjects = vehicles select {_x getVariable ["TAG_fnc_lootSpawn",false]};
TAG_fnc_lootSpawnPositions = _lootMarkerObjects apply {getPosATL _x};
{deletevehicle _x} forEach _lootMarkerObjects;

//now TAG_fnc_lootSpawnPositions holds all positions needed to spawn the loot and the objects have been deleted
//to spawn your loot on every position:



{
_weap = selectRandom ["hgun_Pistol_heavy_01_F", "hgun_P07_F", "hgun_Pistol_heavy_02_Yorris_F", "hgun_Rook40_F"];
_qtd1 = random 3;
_qtd2 = random 1;


_Loot1 = "groundweaponholder" createVehicle _x; // Creates "groundweaponholder

_magazines = getArray (configFile / "CfgWeapons" / _weap / "magazines");
_magazineClass = selectRandom _magazines; 

_Loot1 addWeaponCargoGlobal [_weap, 1]; // creater weapon
_Loot1 addMagazineCargoGlobal [_magazineClass, _qtd1]; // creates magazine
_Loot1 addItemCargoGlobal ["optic_Arco_blk_F", _qtd2]; // creates optics
_Loot1 addBackpackCargoGlobal ["B_AssaultPack_blk", _qtd2]; // creates backpacks
} forEach TAG_fnc_lootSpawnPositions;

Also no need to define _this, since it's a magic variable and reserved to be used in special cases, so don't make it a habit, heh.

 

You could use multiple tiers of loot using the above way, having certain positions spawn rifles or sniper rifles depending on the value returned by TAG_fnc_lootSpawn, easy to adapt and build upon.

 

Cheers

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

@Grumpy Old Man thank you!

 

Your name will be in the credits for my script and mission and the tutorial video that I will publish with this script, because I have a channel that shows how to create ArmA 3 tasks to do their own missions.
It worked like magic!

With now this same script I can accomplish other things that I have in mind.

 

Now one thing I noticed is that the generated item always stays on the ground, I know that you have helped me a lot, but can you tell if you have how the spawned item stays above on some of the object that I put on the map?

 

I tried to link the line ..
_Loot1 attachTo [_x, [0,0,0.62]];

 

I saw that the script generates an in-place markup, so you can not attach the spawn item to it.

 

I think of this possibility because I would like to spawn some item on some tables and boxes.

Share this post


Link to post
Share on other sites

So you placed those batteries on desks/tables?

Might just need to add a setPosATL after creating the weapon holder, might do the trick:

 

_Loot1 = "groundweaponholder" createVehicle _x; // Creates "groundweaponholder
_Loot1 setPosATL _x; //sets position of weapon holder where the battery was placed at

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
22 hours ago, Grumpy Old Man said:

So you placed those batteries on desks/tables?

Might just need to add a setPosATL after creating the weapon holder, might do the trick:

 


_Loot1 = "groundweaponholder" createVehicle _x; // Creates "groundweaponholder
_Loot1 setPosATL _x; //sets position of weapon holder where the battery was placed at

Cheers

Unfortunately this forum does not have the ability to demonstrate my happiness.

 

Thank you very much for your help, because without it I would not have gotten this function in script.

 

May peace, happy and health accompany you everywhere.

  • Like 1

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

×