Jump to content

Recommended Posts

Hi. I'm trying to make a script that triggers on AI death. On death the script will check what magazines the unit has, then remove his weapon (which removes all magazines for some reason) then put 1 magazine back to his corpse.

So AI will drop only a single magazine of the ammotype they are using. This is what I've got

{_x addeventhandler ["killed",{
_this spawn {_unit = _this select 0; removeallweapons _unit};
}];
} forEach allUnits;

Now this is the first time I'm scripting in Arma so please use simple instructions. Thank you in advance!

Share this post


Link to post
Share on other sites

This will add one magazine for the units primary weapon into the units uniform upon death:

this addEventHandler ["Killed",{
	params ["_unit"];
	_mag = primaryWeaponMagazine _unit # 0;
	removeAllWeapons _unit;
	_unit addMagazineGlobal _mag;
}];

Assuming the unit already has a weapon with a loaded magazine this should work fine.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Sorry for being a newbie, but

8 minutes ago, Grumpy Old Man said:

this addEventHandler ["Killed",{ params ["_unit"]; _mag = primaryWeaponMagazine _unit # 0; removeAllWeapons _unit; _unit addMagazineGlobal _mag; }];

gives me an error code as soon as I start the mission. Am I supposed to use this somewhere else than init.sqf?

Share this post


Link to post
Share on other sites
Just now, FookinThicc said:

Sorry for being a newbie, but

gives me an error code as soon as I start the mission. Am I supposed to use this somewhere else than init.sqf?

 

Yes, "this" doesn't exist in init.sqf, you need to adjust it to fit your application, taking your first post as an example it could look like this:

{
	_x addEventHandler ["Killed",{
		params ["_unit"];
		_mag = primaryWeaponMagazine _unit # 0;
		removeAllWeapons _unit;
		_unit addMagazineGlobal _mag;
	}];
} forEach allUnits; 

Cheers

 

  • Like 1

Share this post


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

 


_mag = primaryWeaponMagazine _unit # 0;

 

 

i've never seen this before. does this have any benfits over "select 0" other than way less typing and looking waaaaay cooler? i'm just genuinely curious.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, bad benson said:

 

i've never seen this before. does this have any benfits over "select 0" other than way less typing and looking waaaaay cooler? i'm just genuinely curious.

 

Not sure about the looking cooler part, you can simply use # instead of select and it has higher priority than math operators, hence you can skip goofing around with brackets:

[0,1,2] select 1 + [0,1,2] select 1;// error in expression
([0,1,2] select 1) + ([0,1,2] select 1);// 2
[0,1,2]#1+[0,1,2]#1;// 2

 

Cheers

 

 

 

  • Like 1
  • Thanks 2

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

×