Jump to content
Sign in to follow this  
viper[cww]

Removing Weapons from dead npc's

Recommended Posts

Like the title says I am looking for a way to lock (cant be taken) or remove weapons from dead non playable characters, so that the player does not take said weapons.

Only with this I would like to keep the ammo on the npc so the player can re-use it.

How would I go about doing this in script form?

EDIT:

Something like this perhaps?

if (!isDedicated) then 
{

[]spawn 
{

	while {!alive [b]unplayable[/b]} do 
	{

               removeAllWeapons this;

               };
               sleep 0.3; 
      };
};

Complete shot in the dark ofcourse... (highlighted the classname I wasn't to sure about)

Edited by VIPER[CWW]

Share this post


Link to post
Share on other sites

When there are no units spawned during the mission:

A trigger with

activation: once

condition: true

code:

{_x addEventHandler ["Killed", {if !(isPlayer (_this select 0)) then {removeallweapons (_this select 0); removebackpack (_this select 0)}}] } forEach allUnits;

---------------------------------------------------------------------------------------------------------------------------------

When you have units spawned during the mission and want to remove their weapons when they are dead:

Put into the init.sqs or into a trigger with the condition "true":

[] exec "remove.sqf";

file remove.sqf:

#start
_deadlist = [];
{ if !(isPlayer _x) then {_deadlist = _deadlist + [_x]} } forEach allDead;
~5.0
{_x removeallweapons; removebackpack _x} forEach _deadlist;
goto "start";

The workaround with the delayed _deadlist also removes the weapons some seconds after they have fallen to the ground. Otherwise it would look strange when their weapons suddenly and visibly blobbed away in the second they die.

Edit:

Nah, unplayable only :-/

Couldn't find a check for "is playable". You might add the condition "isPlayer"... this at least would keep the weapons of those corpses that CURRENTLY are a human player. I've tried to add it to my codes above. Hopefully distributing all the ( and [ and { correctly.

Edited by RogueTrooper

Share this post


Link to post
Share on other sites

just to point out that above code is sqs and executed with exec wich is correct, but he named it sqf, both in name and exec line, probably a writing error, should be sqs and its all good.

Share this post


Link to post
Share on other sites

I name all my files sqf (f like fox, with exceptions) and execute them with

[] exec "file.sqf" (f like fox)

and I never have problems because of this.

I think my code is sqf(ox). I hate the unreadable sqs format with its ugly shortings && ??: and such. I always thought sqs (s like sigma) was the ugly unreadable code.

I'm using sqf(ox) and the kind of code stated above and everything works fine...

Edited by RogueTrooper

Share this post


Link to post
Share on other sites

thanks for the replies....

one question with the removeAllWeapons code, this removes everything he has in his gear except items ofcourse is there anyway I can just remove the weapon, or let him keep the weapon but it cannot be picked up, like a non-pilot cant pilot a helicopter for example...

Share this post


Link to post
Share on other sites

@RougeTrooper

It appears you are right, the script do work like this with a fix.

that is strange because you are clearly using sqs and sqf together.

In SQS scripts only: Go to given label.

goto

and the ~5.0 is clearly the sqs variant of sleep.

and for the exec part, it appears it can be used for both by wiki, but inidcates errors and restrictions when used on sqf.

btw, i tested your fox script and it gave lots of errors in .prt:

but was related to wrong usage of removeAllWeapons command.

removeAllWeapons is wrong, _x should be after not before the command.

so after fixing the removeAllWeapons command, the script worked as you said, but very strange and confusing to use combination of both syntaxes.

When mixing alot of both into one, will mess up so many things for those not knowing better.

especially for new scripters.

but i learned a new thing today :)

@VIPER[CWW]

here is a proper sqf version of RougeTrooper´s "fox".

place this in init.sqf or a trigger or whatever like he said:

_null = [] [b]execVM[/b] "remove.sqf";

remove.sqf

while {true} do {
_deadlist = [];
{if !(isPlayer _x) then {_deadlist = _deadlist + [_x]}} forEach allDead;
sleep 5.0;
{removeallweapons _x; removebackpack _x} forEach _deadlist;
};

Share this post


Link to post
Share on other sites

^^ works perfect, the only thing is and I suspected this would happen, is that it removes everything from his gear, I would only like to remove the weapon, so his magazines, bandages etc remain for scavenging...

Tried this to no avail..

while {true} do {
_deadlist = [];
{if !(isPlayer _x) then {_deadlist = _deadlist + [_x]}} forEach allDead;
sleep 5.0;
{removeallweapons _x; removebackpack _x} forEach _deadlist;
};

Share this post


Link to post
Share on other sites
while {true} do {
_deadlist = [];
{if !(isPlayer _x) then {_deadlist = _deadlist + [_x]}} forEach allDead;
sleep 5.0;
{_x removeWeapon (primaryWeapon _x); _x removeWeapon (secondaryWeapon _x); removebackpack _x} forEach _deadlist;
};

Share this post


Link to post
Share on other sites

this removes only main and secondary weapon (launcher, etc)

magazines are still left in inventory:

while {true} do {
_deadlist = [];
{if !(isPlayer _x) then {_deadlist = _deadlist + [_x]}} forEach allDead;
sleep 5.0;

{
	_x removeWeapon (primaryWeapon _x);
	_x removeWeapon (secondaryWeapon _x);
	removebackpack _x;
} forEach _deadlist;
};

edit: ninjaed :D

Share this post


Link to post
Share on other sites

How would I remove all hand grenades for a given side? I want to make/call an array composed of all East and Independent units, to remove eg. hand grenades.

It's a different script given that the people would all be alive, but I thought it closely enough related that it was worth asking in here. I need something like allUnits, but for resistance or opfor only.

Share this post


Link to post
Share on other sites

allUnits only return alive units, so do it like this:

{
_unit = _x;
if ((side _unit) in [resistance,east]) then {
	{if (_x == "classname_of_grenades") then {_unit removeMagazine _x}} foreach (magazines _unit);
};
} foreach allUnits;

you need to find the grenade classname yourself and replace in the code.

Share this post


Link to post
Share on other sites

Thank you, Demonized! I've somewhat lengthened and botched it, but here's a way to remove all rifle- and hand grenades in the game:

{
_unit = _x;
if (((side _unit) in [resistance,east])) then {
	{if (_x == "handgrenade_west") then {_unit removeMagazines _x}} foreach (magazines _unit);
	{if (_x == "handgrenade_east") then {_unit removeMagazines _x}} foreach (magazines _unit);
	{if (_x == "1Rnd_HE_GP25") then {_unit removeMagazines _x}} foreach (magazines _unit);
	{if (_x == "1Rnd_HE_M203") then {_unit removeMagazines _x}} foreach (magazines _unit);
};
} foreach allUnits;

Certainly not as efficient as could be (I imagine the classes can be put into an array and called a lot quicker) but it does what it needs to do.

Share this post


Link to post
Share on other sites

you can use the in command for that, placing all types in a array and check that:

_magzToRemove = ["handgrenade_west","handgrenade_east","1Rnd_HE_GP25","1Rnd_HE_M203"];
{
_unit = _x;
if (((side _unit) in [resistance,east])) then {
	{if (_x in _magzToRemove) then {_unit removeMagazine _x}} foreach (magazines _unit);
};
} foreach allUnits;

the result is just the same as yours, but easier on the eyes maybe, also i use the single removeMagazine instead of the plural just incase there are some issues when doing foreach on all the magazines.

  • 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  

×