Jump to content
Sign in to follow this  
doomnet

how to drop only one ammunition case in script ?

Recommended Posts

Hi,

 

I use this little script to drop items and then call another script to set items in 3D turntable

How to only drop one ammunition case and delete the other ones ?

in this script:

_myStuff = weapons player;
_myMags = magazines player;


// Drop all your stuff on ground.
if (count (_myStuff+_myMags)>0) then 
{
_box = createVehicle ["groundWeaponHolder", player modelToWorld [0,0.8,0], [], 0.5, "CAN_COLLIDE"];
_box setDir floor (random 360);


{
_box addWeaponCargoGlobal [_x, 1];
player removeWeapon _x;
} forEach _myStuff;
{
_box addMagazineCargoGlobal [_x, 1];
player removeItem _x; 
} forEach _myMags;


player reveal _box;
};

Don't know if its possible

but thanks in advance

Share this post


Link to post
Share on other sites

You could add the classnames to an array as you process them and with each loop check if the classname is already in that array (if it's not pushBack the classname, pushBackUnique would be good in this case).  If you've already added it simply skip and move on to the next classname.

The whole dropping on the ground thing seems excessive if it's all going to end up on a table anyway.  Just stripping the player and filling an ammo box with the items would be a lot less overhead and lag for what seems a momentary visual gimmick.

  • Like 1

Share this post


Link to post
Share on other sites

Ok then maybe its not a good idea to drop ammunition

So i tried to delete the ammunition code but now it does not work anymore with the weapons

any idea what i did wrong ?

_myStuff = weapons player;

// Drop all your stuff on ground.
if (count (_myStuff)>0) then 
{
_box = createVehicle ["groundWeaponHolder", player modelToWorld [0,0.8,0], [], 0.5, "CAN_COLLIDE"];
_box setDir floor (random 360);


{
_box addWeaponCargoGlobal [_x, 1];
player removeWeapon _x;
} forEach _myStuff;
{

player reveal _box;
};

Share this post


Link to post
Share on other sites

You have an extra { just above player reveal _box;

_myStuff = weapons player;

// Drop all your stuff on ground.
if (count (_myStuff)>0) then 
{
	_box = createVehicle ["groundWeaponHolder", player modelToWorld [0,0.8,0], [], 0.5, "CAN_COLLIDE"];
	_box setDir floor (random 360);

	{
		_box addWeaponCargoGlobal [_x, 1];
		player removeWeapon _x;
	} forEach _myStuff;

	player reveal _box;
};

Using KK's SQF Highlighter for Notepad++ can help spot little errors like that quickly.  Here's the comparison, note the red warning line on the left side.

 

51Aa207.png

  • Like 1

Share this post


Link to post
Share on other sites

ok sry i found why i forgot to delete one }

Share this post


Link to post
Share on other sites

Can you explain more precisely what do you want?

Share this post


Link to post
Share on other sites

well when players die i launch this script above from onPlayerKilled.sqf

 

and then i have another script that creates the dropped items in 3D like a turntable so other players can see it easily and pick it up

but the problem with ammunition is it will drop like maybe 20 ammunition cases in the air, so that's not really nice, and makes also some server overload and lag

so i wanted to know if i can only drop one ammunition case from a dead player.

the dropped weapons and items will only stay 20 secondes in the air as i use also a cleanup script.

But anyway that works better with only weapon dropping.

 

So that is 3 different scripts that i use to achieve this lol, this could be maybe all done in one script btw.

Share this post


Link to post
Share on other sites

For example: Player has rifle, pistol, 5 rifle mags, 3 pistol mags, 2 grenades. You want to be dropped: rifle, pistol, 1 rifle mag, 1 pistol mag, 1 grenade. Right?

  • Like 1

Share this post


Link to post
Share on other sites

For example: Player has rifle, pistol, 5 rifle mags, 3 pistol mags, 2 grenades. You want to be dropped: rifle, pistol, 1 rifle mag, 1 pistol mag, 1 grenade. Right?

 

yes exactly

Share this post


Link to post
Share on other sites

Okay. This function combine magazines from plain enumeration to pairs <Name, Count>

Fn_CombineMagazines = {
	private _res = [];

	{	private _mgn = _x;
		private _mgr = {if (_x select 0 isEqualTo _mgn) exitWith {_x}} forEach _res;
		if (isNil "_mgr") then {
			_res pushBack [_mgn, 1];
		} else {
			_mgr set [1,  1 + (_mgr select 1)]}
	} forEach _this;
	_res
};

For example:

_result = (magazines player) call Fn_CombineMagazines

//Result: [["30Rnd_65x39_caseless_mag",9],["Chemlight_green",2],["16Rnd_9x21_Mag",2],["SmokeShell",1],["SmokeShellGreen",1],["HandGrenade",2]]
  • Like 1

Share this post


Link to post
Share on other sites

Wow this seems amazing but i really don't understand everything lol

So do i have to use this function in a new sqf file ?

anyway will take a closer look tomorrow cause my brains can take it no more xd !!!

 

will post the results !

 

thanks serena !

Share this post


Link to post
Share on other sites

All code:

Fn_CombineMagazines = {
	private _res = [];

	{	private _mgn = _x;
		private _mgr = {if (_x select 0 isEqualTo _mgn) exitWith {_x}} forEach _res;
		if (isNil "_mgr") then {
			_res pushBack [_mgn, 1];
		} else {
			_mgr set [1,  1 + (_mgr select 1)]}
	} forEach _this;
	_res
};


Fn_DropStuff = {
	private _unt = player;
	private _wps = weapons _unt;
	private _mgs = (magazines _unt) call Fn_CombineMagazines;

	if (count _wps > 0 or count _mgs > 0) then {
		private _box = createVehicle ["groundWeaponHolder", player modelToWorld [0,0.8,0], [], 0.5, "CAN_COLLIDE"];
		_box setDir floor (random 360);

		removeAllWeapons _unt;
		{	_box addWeaponCargoGlobal [_x, 1];
		} forEach _wps;

		{	private _mgn = _x select 0;
			_unt removeMagazines _mgn;
			_box addMagazineCargoGlobal [_mgn, 1];
		} forEach _mgs
	}
};
  • Like 1

Share this post


Link to post
Share on other sites

amazing serena thank you

 

i really appreciate the effort !

 

;)

Share this post


Link to post
Share on other sites

So do i have to use this function in a new sqf file ?

 

You can place functions to properly named sqf file, compile it once at mission start and then use from any place during mission.

 

init.sqf:

call compile preprocessFileLineNumbers "Core.sqf";
call compile preprocessFileLineNumbers "Func.sqf";
call compile preprocessFileLineNumbers "Gear.sqf";
  • Like 1

Share this post


Link to post
Share on other sites

I mean, sure that's cool and all, but shouldn't the extra magazines fly around in a deadly cloud attaching to nearby players and explode?

  • 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
Sign in to follow this  

×