Jump to content

Recommended Posts

Hey guys, I'm trying to put something together that will prevent players (Co-op) from picking up the weapons off a dead AI. It was easy enough to prevent them going into a dead AI's inventory but I'm stuck for a solid idea on how to stop them getting the weapon that gets dropped on the ground.

 

At the moment I can use this on an AI once it dies:

{_x enableSimulationGlobal false} forEach (nearestObjects [_unit,["WeaponHolderSimulated"],5]);

This works, but it causes the player to level their view horizontally for what seems to be one frame, which is kind of distracting. Is there a batter way to achieve this?

Share this post


Link to post
Share on other sites

You can disable simulation with ~3 sec delay. That should be enough for correct positioning of the Holder

Share this post


Link to post
Share on other sites

The delay is fine. At the moment I'm just running with a stock 2 second delay, which I could substitute with a height check or something similar later. Sorry for the misunderstanding, my fault, I should have posted the rest of what I have at the moment:

private ["_unit"];

_unit = _this select 0;

sleep 2;
{_x enableSimulationGlobal false} forEach (nearestObjects [_unit,["WeaponHolderSimulated"],5]);

This runs from a "MPKilled" event handler. The problem is the player's view snapping to being horizontal for what seems to be a single frame, before going back to where the player was looking when they tried to grab the weapon.

Share this post


Link to post
Share on other sites

Maybe just delete the weapon within the MPKilled EH so it never drops?

  • Like 1

Share this post


Link to post
Share on other sites

Maybe just delete the weapon within the MPKilled EH so it never drops?

Event handler is definitely the most robust way of doing this (and probably best practice!)

What I would do is assign an mp killed event handler to all Ai units and then when the unit is killed generate an array of weapons they are carrying and a list of weapon holders around them. You can then remove these from the invetory and world respectively.

AlThough these commands have global execution I would advise you to run the command on the server or the instance of which is the owner to the Ai unit you wish to handle

If you would like some code ill be happy to provide you with it

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the offer bull, but I'm good for code on this one. Although i didn't want to delete the weapon it looks like it might be the way to go. Seems like it'll fit in better than how I've used enableSimulation.

Share this post


Link to post
Share on other sites

Thanks for the offer bull, but I'm good for code on this one. Although i didn't want to delete the weapon it looks like it might be the way to go. Seems like it'll fit in better than how I've used enableSimulation.

 

If you were able to get the weapon containers e.g. "GroundWeaponHolder" after the unit died you could always apply a Take eventhandler to that container an run code that prevents a player taking items from that container

Share this post


Link to post
Share on other sites

Lol, I've just amused myself by finding a very simple solution to this by using setDamage 1:

{_x setDamage 1} forEach (nearestObjects [_unit,["WeaponHolderSimulated"],5]);

Does the trick, completely removes it from the action menu  :) Don't know how I missed it earlier but it was from this thread:

https://forums.bistudio.com/topic/179837-prevent-player-from-taking-objects/

 

Thanks for the help mate!!

Share this post


Link to post
Share on other sites

Ok, so for anyone interested, I have a Killed event handler that runs this:

private ["_unit","_weaponHolders"];

_unit = (_this select 0) select 0;

sleep 0.5;

_weaponHolders = nearestObjects [_unit,["WeaponHolderSimulated"],5];
waitUntil {
	(({(velocity _x) select 0 == 0} count _weaponHolders) == count _weaponHolders) &&
	(({(velocity _x) select 1 == 0} count _weaponHolders) == count _weaponHolders) &&
	(({(velocity _x) select 2 == 0} count _weaponHolders) == count _weaponHolders)
};
{_x setDamage 1} forEach _weaponHolders;

This will work for units that drop more than one weapon, for example AT soldiers.

Share this post


Link to post
Share on other sites

Try this: 

addMissionEventHandler ["EntityKilled", {
	private _vct = _this select 0;
	if (_vct isKindOf "CAManBase") then {
		_vct spawn {
			sleep 0.5;
			private _hls = nearestObjects [_this, ["WeaponHolderSimulated"], 5];
			while {count _hls > 0} do {
				private _hlx = {if (vectorMagnitude velocity _x == 0) exitWith {_forEachIndex}} forEach _hls;
				if (isNil {_hlx})
				 	then {sleep 0.1}
					else {_hls deleteAt _hlx setDamage 1}
			}
		}
	}
}];
  • Like 2

Share this post


Link to post
Share on other sites

Hey thanks heaps serena. Hadn't known about vectorMagnitude, and didn't even think to use a missionEH. Except for some public variable name changes and an extra side check in that first if statement i used it as is and it works perfectly.

Share this post


Link to post
Share on other sites

Apologies for opening an older thread...

 

Could something like this be done to take the weapon that is on the ground and place it into the dead solider's inventory?  So many times I've gone to inspect the dead soldier's inventory and gotten the single weapon that's laying on top of them... would be great to do away with that... 

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

×