Jump to content
Rawshark

[Solved] Restrict looting of only one faction's corpses?

Recommended Posts

In a multiplayer survival mission I have going, I am trying to prevent my re-spawning players from simply walking up to their own bodies and looting their weapons and ammo -but- I don't want to disable looting altogether because I need them to be able to loot the enemy (OPFOR/Indep) during the course of the mission. So I tried this in an antiloot.sqf:
 

Quote

addMissionEventHandler ["EntityKilled", {

    params ["_killed", "_killer", "_instigator"];
    
    if (isPlayer _killed) exitWith {};
    if !(_killed isKindOf "Man") exitWith {};

 

if (faction _killed == "BLU_F") then {
    
        removeAllWeapons _killed;
        removeAllItems _killed;
        removeAllAssignedItems _killed;
        deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]);


 and called it via the init.sqf....but it didn't seem to work. 

I'm not the best with using scripts so if someone knows what I am doing wrong or has an alternative code for preventing friendly looting i'd be delighted with any help I can get. 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Your 3 line excluding players body from being affected.

Anyway try this below, if you want to affect only players corpses uncomment 3 line:

 

if (isServer) then {
	addMissionEventHandler ["EntityKilled", {	
	//if (!isPlayer (_this select 0)) exitWith {};
    if !((_this select 0) isKindOf "Man") exitWith {};
	
		0 = [_this select 0] spawn {
			params [["_remains",objNull,[objNull]]];
			if (isNull _remains) exitWith {};
			if (!isNull (objectParent _remains)) then {
				_remains setPosATL (objectParent _remains modelToWorld [-3,0,-2]);
			};

			waitUntil {
				sleep 10; 
				(
					(entities [["Man"], [], false, true]) select {
						isPlayer _x &&
						{(position _x) inArea [position _remains, 200, 200, 360, false, -1]}
					}
				) isEqualTo []
			};
			private _pos = getPosASL _remains;
			private _up = vectorUp _remains;
			private _dir = vectorDir _remains;
			deleteVehicle _remains;
			private _skelet = [["Land_HumanSkeleton_F","a3\structures_f\civ\dead\humanskeleton_f.p3d",0,0.217,[],[],0,[],false,false], _pos, 0,true,true] call BIS_fnc_createSimpleObject;
			_skelet setVectorDirAndUp [_dir,_up];
			_skelet setPos [((getPos _skelet) select 0), ((getPos _skelet) select 1), ((getPos _skelet) select 2) - 0.1];
			private _bloodSplash = createSimpleObject ["a3\characters_f\blood_splash.p3d", getPosWorld _skelet];
			_bloodSplash setDir (random 360);
			private _fliesTrigger = createTrigger ["EmptyDetector", position _bloodSplash, true];
			_fliesTrigger setTriggerArea [30, 30, 0, true, 3];
			_fliesTrigger setTriggerActivation ["ANYPLAYER", "PRESENT", true];
			_fliesTrigger setTriggerStatements [
				"
				this 
				",
				"
				if (hasInterface) then {
					_flies = [position thisTrigger, 0.1, 0.5] call BIS_fnc_flies;
					thisTrigger setVariable ['trigger_flies',_flies param [0,objNull]];
				};
				",
				"
				if (hasInterface) then {
					_flies = thisTrigger getVariable ['trigger_flies',objNull];
					if (!isNull _flies) then {
						deleteVehicle _flies;
					};
				};
				"
			];
		};
	}];
};

This code will create an event around corpse after unit gets killed.

If the body was killed in vehicle it will be moved out of vehicle.

Next, event will wait until no onfoot player around 200m to prevent changes in front of players eyes.

Next, the body gets deleted and new permanent super simple object will be created (Skeleton) instead and simple object blood splash underneath.

Last an global trigger will be created which will switch flies appearance above the skeleton if any player near.

Unfortunately i was unable to find any flies sound in arma 3, this way the flies looks more like moths.

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites
12 minutes ago, HazJ said:

??? Why not just use:

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#InventoryOpened

Check condition and close if not met.

Thanks for the reply. Im quite new to scripting so I am not 100% on how to adapt the code correctly, but does this look about right?
 

Quote


player addEventHandler ["InventoryOpened",{ if (_this select 1 is "man") then {close; true} }];

 

If so do I call it via an init.sqf or do I have to initialise it in each player character's init box?
Thanks for your time. 

Share this post


Link to post
Share on other sites

No. I am not sure what condition you want but here is an example for side.

player addEventHandler ["InventoryOpened",
{
	params ["_unit"];
	if (side _unit != blufor) then
	{
		true
	};
}];

This will close it if you aren't BLUFOR side. Note: Being set captive and bad rating affects this.

  • Thanks 1

Share this post


Link to post
Share on other sites
4 minutes ago, HazJ said:

No. I am not sure what condition you want but here is an example for side.


player addEventHandler ["InventoryOpened",
{
	params ["_unit"];
	if (side _unit != blufor) then
	{
		true
	};
}];

This will close it if you aren't BLUFOR side. Note: Being set captive and bad rating affects this.

Thanks so much, can I modify it so that:

if (side _unit = blufor) then

so that the inventory will close if you are BLUFOR? Also for MP should i just have this in the init boxes of each player or that the same as calling it via the init.sqf

Share this post


Link to post
Share on other sites

Thank you for helping a newbie out, you all are amazing!

Share this post


Link to post
Share on other sites


 

addMissionEventHandler ["EntityRespawned", {
 params [" _unit"," _corpse"];
 removeAllWeapons _corpse;
 removeBackpackGlobal _corpse;
 removeUniform _corpse;
 removeVest _corpse;
 removeAllAssignedItems _corpse;
 removeAllItems _corpse;
 removeGoggles _corpse;
 removeHeadgear _corpse;
 removeAllActions _corpse;
 {deleteVehicle _x} forEach nearestObjects [(getPosATL _corpse),["WeaponHolderSimulated","groundWeaponHolder"],5];
}];

 

Share this post


Link to post
Share on other sites
6 minutes ago, pierremgi said:

 


addMissionEventHandler ["EntityRespawned", {
 params [" _unit"," _corpse"];
 removeAllWeapons _corpse;
 removeBackpackGlobal _corpse;
 removeUniform _corpse;
 removeVest _corpse;
 removeAllAssignedItems _corpse;
 removeAllItems _corpse;
 removeGoggles _corpse;
 removeHeadgear _corpse;
 removeAllActions _corpse;
 {deleteVehicle _x} forEach nearestObjects [(getPosATL _corpse),["WeaponHolderSimulated","groundWeaponHolder"],5];
}];

 

 

I get an error saying "local variable in global space"

Share this post


Link to post
Share on other sites

Sorry, remove the spaces in  params ["_unit","_corpse"];

 

 

Share this post


Link to post
Share on other sites

Your original question was to restrict looting to one side. The code @pierremgi shared above doesn't do that.

Share this post


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

Your original question was to restrict looting to one side. The code @pierremgi shared above doesn't do that.

 

Just add 2 lines.

Share this post


Link to post
Share on other sites

@pierremgi - Why all of that when you can just have:

player addEventHandler ["InventoryOpened",
{
	params ["_unit"];
	if (side _unit == blufor) then
	{
		true
	};
}];

 

  • Confused 1

Share this post


Link to post
Share on other sites

The question was to restrict not delete the loot.

Share this post


Link to post
Share on other sites
21 minutes ago, HazJ said:

The question was to restrict not delete the loot.

And you prefer to restrict, anyway, anytime? No more access to inventory ?????

Btw, you can grab a weapon (beside the corpse) without opening the inventory.

 

The question:

I am trying to prevent my re-spawning players from simply walking up to their own bodies and looting their weapons and ammo -but- I don't want to disable looting altogether because I need them to be able to loot the enemy (OPFOR/Indep) during the course of the mission.

 

I started with non-respawning (OPFOR/indep) So, the EH (entityRespawned) which is on my mind the most adapted, is simple.

You need something for multiple player camps (BLU/RED/INDEP players)? keeping looting for other camps?...

... Just add a condition which make remove the loot if a friendly player is approaching the corpse:


 

addMissionEventHandler ["EntityRespawned", {
 params ["_unit","_corpse"];
  [_unit,_corpse] spawn {
   params ["_unit","_corpse"];
   waitUntil {sleep 0.5; {_x distance _corpse < 5} count (allPlayers select {side _x == side _unit}) >0};
   removeAllWeapons _corpse;
   removeBackpackGlobal _corpse;
   removeUniform _corpse;
   removeVest _corpse;
   removeAllAssignedItems _corpse;
   removeAllItems _corpse;
   removeGoggles _corpse;
   removeHeadgear _corpse;
   removeAllActions _corpse;
   {deleteVehicle _x} forEach nearestObjects [(getPosATL _corpse),["WeaponHolderSimulated","groundWeaponHolder"],5]
  };
}];

 

Share this post


Link to post
Share on other sites

Read the thread title. Despite the actual intention of the thread author. The thread title is what it is. Yes, I am aware that you can take the weapon without opening the inventory menu. You can use Take EH to solve that. That is like asking for an apple and getting an orange despite actually wanting an apple. :rofl:

Doesn't deleteVehicle execute globally?

7 hours ago, Rawshark said:

Thanks so much, can I modify it so that:


if (side _unit = blufor) then

so that the inventory will close if you are BLUFOR? Also for MP should i just have this in the init boxes of each player or that the same as calling it via the init.sqf

 

Share this post


Link to post
Share on other sites

Thanks for your text explanation. Your script is just perfect. :wave:

  • Haha 1

Share this post


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

@HazJ Where are you going with that?

Just as you requested. If there is anything else you don't understand, I'd be happy to help! :wave:

Share this post


Link to post
Share on other sites

Don't worry. I didn't request anything. I was just thinking totally weird to definitely block the inventory for Blufor. It was not the initial demand.

So I understood the essential. Let's readers choose a solution or the other.

Share this post


Link to post
Share on other sites
On 3/3/2018 at 6:21 PM, HazJ said:

No. I am not sure what condition you want but here is an example for side.


player addEventHandler ["InventoryOpened",
{
	params ["_unit"];
	if (side _unit != blufor) then
	{
		true
	};
}];

This will close it if you aren't BLUFOR side. Note: Being set captive and bad rating affects this.

Well hello , I like all of those scrips, but if you can help I'm a bit confused.. I'm have a MP game NO AI PVP only, and want them to be able to loot only weapon , and ammo regardeless of the team side.. But i dont want them to loot the gear( uniform, headgear, vest, binocular etc..)  can you plz help me to create that script ? 

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

×