Jump to content
Sign in to follow this  
oktyabr

YET ANOTHER player = undercover as civ scripting?

Recommended Posts

~sigh~

I've been reading post after post, script after script, and I thought maybe it was time to see if anyone who has been down this road before might save me a bit of time and tell me the easy/best way to do the following:

Mission: SP/CooP, player(s) is undercover as a civilian in a bad, bad place, and is given missions to complete. Looks like a civilian, gets along with the civilians, as long as he isn't caught holding a (prohibited) weapon in his hands.

When this happens the civilians need to turn nasty, the mob (independents) need to engage, and any military (OPFOR) that happens to be in the vicinity should react with hostility as well.

So far I've been experimenting with ways to "holster" weapons and I think I've settled on Arctor's "Sidearm Holster Script", which seems to work perfectly. NOW what I would like to know is how to get the player(s) sides to switch when a weapon is in their hands, and then perhaps revert to a neutral one when the weapon is gone (or concealed, in the case of a pistol). I know there are several options available, at least the ones I know about, and these would include setCaptive, setFriend and I'm assuming there must be a way to make a switch in a script using playerSide?

I'm sure left to my own devices (until the real world calls me back for my 'free' time) I would eventually figure out something that worked. I'm posting because I am hoping maybe someone already has figured out the optimal solution and wouldn't mind sharing it?

I plan to populate civs probably with TPW Mods, maybe with MCC/GAIA or even ALIVE, if that matters?

Here is the code of the holster script I'm using:

//
//	arc_holster.sqf
//	Sidearm-Holster-script by Arctorkovich
//
// in init.sqf put:
// 
// if (!isDedicated) then
// {
//		holstered = 0;  
//		player addAction ["Holster sidearm","arc_holster.sqf",nil,2.5,false,true,"",""];
//  };

if (isDedicated) exitWith {};

private ["_unit","_holstered"];

_id = _this select 2;
_unit = player;
_holstered = holstered;

switch (_holstered) do
{
case 0:
{
	class_weapon = currentWeapon _unit;

	if (currentWeapon _unit != handgunWeapon _unit) exitWith 
	{
		hint "Equip your sidearm first!";
	};

	_unit removeAction _id;

	A_mags = [];
	_magazinesAmmoFull = magazinesAmmoFull _unit;

	for "_i" from 0 to ((count _magazinesAmmoFull)-1) do
	{
		_type = (_magazinesAmmoFull select _i) select 3;
		if(_type == 2) then 
		{
			A_mags = A_mags + [(_magazinesAmmoFull select _i) select 0];
		};			
	};

	A_mags = A_mags + [handgunMagazine _unit];
	b_count = _unit ammo class_weapon;

	_unit removeWeapon class_weapon;

	holstered = 1;
	_unit addAction ["Draw sidearm","arc_holster.sqf",nil,2.5,false,true,"",""];
};
case 1:
{
	_unit removeAction _id;

	for "_i" from 0 to ((count A_mags)-1) do
	{
		_unit addMagazine (A_mags select _i);
	};

	_unit addWeapon class_weapon;
	_unit setAmmo [handgunWeapon _unit, b_count];
	_unit selectWeapon class_weapon;

	holstered = 0;
	_unit addAction ["Holster sidearm","arc_holster.sqf",nil,2.5,false,true,"",""];
};
};

if (true) exitWith {};

Thanks in advance!

Share this post


Link to post
Share on other sites

I use a basic trigger that covers the map. Not sure but this may help. I have players as civ's too, if they do not have gun, they dont get shot, if they do they get shot. Allows players to move around enemy areas. Have not tried concealed weapons.

activationBy="ANY";
repeating=1;
Cond=currentWeapon player == """";
Activ=player setcaptive true;
Desactiv=player setcaptive false;

Share this post


Link to post
Share on other sites
I use a basic trigger that covers the map. Not sure but this may help. I have players as civ's too, if they do not have gun, they dont get shot, if they do they get shot. Allows players to move around enemy areas. Have not tried concealed weapons.

activationBy="ANY";
repeating=1;
Cond=currentWeapon player == """";
Activ=player setcaptive true;
Desactiv=player setcaptive false;

Hmmm... Thanks for the suggestion! I wonder if there is a way to incorporate that into the conceal weapon script? The script I'm trying does remove the weapon while it is 'concealed' but leaves any extra magazines in my inventory. I suppose I could try it and see!

Edited by Oktyabr

Share this post


Link to post
Share on other sites

For some reason I couldn't get the trigger to work! This is the exact code from my mission.sqm:

activationBy="ANY";
		repeating=1;
		interruptable=0;
		age="UNKNOWN";
		name="TEST";
		expCond="currentWeapon player == """""""";  ";
		expActiv="player setCaptive true;   ";
		expDesactiv="player setCaptive false; ";

I know it must be me not using the trigger correctly because if I insert _unit setCaptive true; into the concealment script (when the pistol is concealed), and vice versa when the weapon is drawn, and hint about it, it works and they won't shoot me *until* I draw the pistol. The problem with that method is that it only works properly if the player never picks up anything BUT the pistol. If I pick up a rifle for example, while the pistol is "concealed", I'm still left in a setCaptive true state and can shoot the OPFOR with abandon. :(

Share this post


Link to post
Share on other sites

My undercover script, maybe it's useful for you. I use it in Antistasi.

_arrayCivVeh = arrayCivVeh + ["B_G_Quadbike_01_F"];

while {true} do
{
waitUntil {sleep 1;((vehicle player == player) or ((typeOf (vehicle player) in _arrayCivVeh))) and ({((side _x== EAST) or (side _x== independent)) and (_x knowsAbout player > 1.4)} count allUnits == 0) and (secondaryWeapon player == "") and (primaryWeapon player == "") and (handgunWeapon player == "") and (vest player == "")};
player setCaptive true;
hint "You are in Undercover Mode";
waitUntil {sleep 1;((vehicle player != player) and (not (typeOf (vehicle player) in _arrayCivVeh))) or ({((side _x== EAST) or (side _x== independent)) and (_x distance player < 30)} count allUnits > 0) or (secondaryWeapon player != "") or (primaryWeapon player != "") or (handgunWeapon player != "") or (vest player != "") or (!captive player)};
player setCaptive false;
hint "You are no longer in Undercover Mode";
waitUntil {sleep 1; ({((side _x== EAST) or (side _x== independent)) and (_x knowsAbout player > 0) and (_x distance player < 500)} count allUnits == 0)};
sleep 60;
};

_arrayCivVeh is composed with the classnames of all the civilian vehicles.

The player will be undercover if he has no weapons in hand, no vest, is not mounted in a military vehicle and it's not close enough to enemy troops.

Share this post


Link to post
Share on other sites

Interesting, does setCaptive work instantly now?

For purposes of a quick sidechange I was always forced to use the help of "player joinSilent (createGroup <side>)" in the past, as this would lead to instant recognition and fire by the enemy. SetCaptive false didnt seem very reliable on units already in sight/in knowsabout.

Share this post


Link to post
Share on other sites

So for my trigger, its covers Altis, set to anyone present, repeating, cond = currentWeapon player == """", Act = player setCaptive true, DeAct = player setCaptive false. How this works for me is, I take a civ unit, drop ammo box, at start opfor just stands and does nothing, once I arm my unit, opfor sees I am armed and shoots me dead.

I will be following this as this thread made come up with some good ideas to fit more exact stuff. This trigger is basic.

Share this post


Link to post
Share on other sites

I just spawn this script via initPlayerLocal.sqf:

[player] spawn {
_unit = _this select 0;

while {true} do {
if (isClass(configFile >> "CfgPatches" >> "AGM_Core")) then {
	if (currentWeapon _unit == "") then {
		[_unit, "ADV_isCaptive", true] call AGM_Interaction_fnc_setCaptivityStatus;
		waitUntil {sleep 1; !(currentWeapon _unit == "")};
		[_unit, "ADV_isCaptive", false] call AGM_Interaction_fnc_setCaptivityStatus;
	};
} else {
	if (currentWeapon _unit == "") then {
		player setCaptive true;
		waitUntil {sleep 1; !(currentWeapon _unit == "")};
		player setCaptive false;
	};
};
sleep 5;
};

if (true) exitWith {};
};

Share this post


Link to post
Share on other sites

I don't use AGM so I suppose I could try this?

[player] spawn { 
_unit = _this select 0; 

while {true} do { 
   if (currentWeapon _unit == "") then { 
   player setCaptive true; 
   waitUntil {sleep 1; !(currentWeapon _unit == "")}; 
   player setCaptive false; 
       }; 
   }; 
   sleep 5; 
}; 

if (true) exitWith {}; 
};

Share this post


Link to post
Share on other sites
I don't use AGM so I suppose I could try this?

You left one bracket at the end. This would be right if you're not using AGM (although the if-check would return this exactly if you're not running AGM):

[player] spawn {
_unit = _this select 0;

while {true} do {
if (currentWeapon _unit == "") then {
	player setCaptive true;
	waitUntil {sleep 1; !(currentWeapon _unit == "")};
	player setCaptive false;
};
sleep 5;
};

if (true) exitWith {};
};

Share this post


Link to post
Share on other sites

You may be able to do the following as well, since it's not a heavy performance hit (I don't think so anyhow), mind you though that this will almost instantaneously change setCaptive on the player depending on the current weapon state, and it will not be re-applied on respawn. In other words, add functionality where needed:

//also in the initPlayerLocal.sqf
[
"checkWeapon",
"onEachFrame",
{
	if (currentWeapon player != "") then
	{
		player setCaptive false;
	}
	else
	{
		if (currentWeapon player isEqualTo "") then
		{
			player setCaptive true;
		}
	};
}
] call BIS_fnc_addStackedEventHandler;

EDIT: A thread of similar merit- http://forums.bistudio.com/showthread.php?189444-Script-Help-Enemies-Ignore-Players-Based-on-Uniform

EDIT2: Changed my mind on some logic, fixed above.

Edited by JShock

Share this post


Link to post
Share on other sites

Personally I'd have made the player blufor with setcaptive true; when the sidearm is out, setcaptive false. Make sure indeps are enemy.

I didn't read how in-depth these guys got, so you may disregard my comment if its nothing you want.

Share this post


Link to post
Share on other sites
Personally I'd have made the player blufor with setcaptive true; when the sidearm is out, setcaptive false. Make sure indeps are enemy.

I didn't read how in-depth these guys got, so you may disregard my comment if its nothing you want.

That's how I've been doing it. A blufor player dressed as a civilian with setcaptive true as long as no pistol in his hands. Since the mission I'm working on specifically forbids any type of weapons in civilian possession, for the player to 'blend in' this method doesn't work perfectly because player can still have a rifle slung over their shoulder and keep setcaptive status. Realistically I would like any visible weapons to trigger a violent reaction.

More so I've been considering what could be done with addRating and do away with setCaptive altogether. I'm not much of a scripter but this is sort of how I think it could work:

Uniform player is wearing determines Faction/Side. Player dressed as a civilian is shot at if seen carrying a weapon(s). Player dressed as opfor is not shot at until he blows his cover by shooting at other opfor (player addRating = -2000, etc.)

Next, assuming player survives any aggression in the immediate area it would be cool to re-adjust that rating based on the time and distance the player is from the last infraction. Example: player dressed as opfor assassinates opfor general with a rifle, and his two body guards, immediately making him targeted by any (?) opfor due to negative rating. As time passes and/or distance from the scene of the crime is established, rating could improve incrementally to the point that he is no longer shot at by other opfor. This would help simulate an assassination, a quick fire fight with body guards (who either win, killing the player, or loose by dying themselves), or witnesses, and as long as no other opfor show up on the scene in the next few minutes the player can distance himself from the scene of the crime and once again be safe as just another opfor going about his tasks.

Civilians too... Civilian should be shot at by opfor if presenting any weapons, whether in hand or slung over shoulder. The "holster" script I've been experimenting with seems to completely remove the pistol from inventory, only adding it back again when the player selects the "Draw Pistol" addaction, so that shouldn't be a problem. Civ player shoots opfor general with pistol, killing him. Outgunned by the bodyguards he manages to escape, concealing the pistol again (removing it from inventory) and quickly fleeing the scene. This last concept brings to light a point I'm struggling with concerning the setCaptive usage. Currently, if I use the holster script as I have it configured (setCaptive true if no pistol in hand, false when pistol is present) means that the player could shoot the opfor general, maybe trade a couple of shots with the angry bodyguards and then instantly find safety simply by concealing the pistol again, which returns setCaptive to true... and the bodyguards lower their weapons and stare at the player in confusion. :p

There MUST be a better way! Isn't there????

EDIT:

Oh scripting gurus, please help me! :D

I altered the holster script (see the posts in the first page) by adding _unit setCaptive true; when pistol is holstered, and the opposite when the player draws the concealed pistol (via addaction). Is there an easy way to put a delay on the setCaptive true so the player still gets treated as "false" for a time, after concealing the pistol? Further I've found another "exploit" using this method... While an easy way to make it work (sort of), the player gets setCaptive true just by holstering the pistol. If he then picks up a weapon off a dead body or whatever he can use it with impunity because setCaptive status is solely based on the last addaction (holster or draw) the player used.

Thanks in advance!

Edited by Oktyabr

Share this post


Link to post
Share on other sites

add sleep, so he's not captive until a few more min/seconds?

seems like it would do the trick.

or once he kills the guy make him perm enemy?

Share this post


Link to post
Share on other sites
add sleep, so he's not captive until a few more min/seconds?

seems like it would do the trick.

or once he kills the guy make him perm enemy?

I really need to find a test for weapon in hand. As I said, the way I currently have it working, a player can setcaptive true by concealing the pistol and then pick up another weapon and shoot all day long without payback... because setcaptive is true.

Share this post


Link to post
Share on other sites
You may be able to do the following as well, since it's not a heavy performance hit (I don't think so anyhow), mind you though that this will almost instantaneously change setCaptive on the player depending on the current weapon state, and it will not be re-applied on respawn. In other words, add functionality where needed:

//also in the initPlayerLocal.sqf
[
"checkWeapon",
"onEachFrame",
{
	if (currentWeapon player != "") then
	{
		player setCaptive false;
	}
	else
	{
		if (currentWeapon player isEqualTo "") then
		{
			player setCaptive true;
		}
	};
}
] call BIS_fnc_addStackedEventHandler;

EDIT: A thread of similar merit- http://forums.bistudio.com/showthread.php?189444-Script-Help-Enemies-Ignore-Players-Based-on-Uniform

EDIT2: Changed my mind on some logic, fixed above.

JShock, thanks for sharing! I've been trying your bit of code and it seems to work pretty well. But as I'm not much of a scripter could you please tell me if there is a way to put a delay on the "true"? I don't want my player to get out of trouble instantly, just because he no longer has a weapon in his hands. :)

Share this post


Link to post
Share on other sites

Change the "sleep 5", to whatever:

[
   "checkWeapon",
   "onEachFrame",
   {
       if (currentWeapon player != "") then
       {
           player setCaptive false;
       }
       else
       {
           if (currentWeapon player isEqualTo "") then
           {
			if !(player getVariable ["isCaptive",false]) then
			{
				player setVariable ["isCaptive",true];
				[] spawn {sleep 5; player setCaptive true;};
			};
           };
       };
   }
] call BIS_fnc_addStackedEventHandler; 

Share this post


Link to post
Share on other sites

This is working quite well and I've been playing with the ACE3 (unofficial) mod which includes a very neat "holster" option...

But I'm back to the original problem... Using the above bit of script sets captive "true" when currentWeapon player isEqualTo "", which keeps my undercover player from being shot at unless he draws a pistol. Using the "sleep" variable assures that even if he puts away the pistol that opfor will continue to shoot at him for awhile. Perfect!

Now I just need to know how to check to see if a second weapon is present... i.e. rifle slung over the shoulder and no pistol in hand? Now: pistol goes away, opfor stop shooting because they don't see the pistol. The way it should be: Rifle (or launcher, etc.) over the shoulder means player IS armed and I want opfor to shoot at him whether he is holding a weapon in his hands or not.

Ideas?

Share this post


Link to post
Share on other sites

Guys,

 

I do not know if this is any use to anyone however i achieved my desired affects using the holster weapon script and by modifying one of the undercover scripts above as follows: This way the player can have a holstered weapon and still go undercover.

 

Holster script (many thanks Oktyabr)

 

//
//    arc_holster.sqf
//    Sidearm-Holster-script by Arctorkovich
//
// in init.sqf put:
// 
// if (!isDedicated) then
// {
//        holstered = 0;  
//        player addAction ["Holster sidearm","scripts\holster.sqf",nil,2.5,false,true,"",""];
//  };

if (isDedicated) exitWith {};

private ["_unit","_holstered"];

_id = _this select 2;
_unit = player;
_holstered = holstered;

switch (_holstered) do
{
case 0:
{
    class_weapon = currentWeapon _unit;

    if (currentWeapon _unit != handgunWeapon _unit) exitWith 
    {
        hint "Equip your sidearm first!";
    };

    _unit removeAction _id;

    A_mags = [];
    _magazinesAmmoFull = magazinesAmmoFull _unit;

    for "_i" from 0 to ((count _magazinesAmmoFull)-1) do
    {
        _type = (_magazinesAmmoFull select _i) select 3;
        if(_type == 2) then 
        {
            A_mags = A_mags + [(_magazinesAmmoFull select _i) select 0];
        };            
    };

    A_mags = A_mags + [handgunMagazine _unit];
    b_count = _unit ammo class_weapon;

    _unit removeWeapon class_weapon;

    holstered = 1;
    _unit addAction ["Draw sidearm","scripts\holster.sqf",nil,2.5,false,true,"",""];
};
case 1:
{
    _unit removeAction _id;

    for "_i" from 0 to ((count A_mags)-1) do
    {
        _unit addMagazine (A_mags select _i);
    };

    _unit addWeapon class_weapon;
    _unit setAmmo [handgunWeapon _unit, b_count];
    _unit selectWeapon class_weapon;

    holstered = 0;
    _unit addAction ["Holster sidearm","scripts\holster.sqf",nil,2.5,false,true,"",""];
};
};

if (true) exitWith {};

 

I then modified Barbaloni's undercover script to remove the vehicle dependency:

 

//undercover script
//The player will be undercover if he has no weapons in hand, no vest, and it's not close enough to enemy troops.

while {true} do
{
waitUntil {sleep 1;({((side _x== EAST) or (side _x== independent)) and (_x knowsAbout player > 1.4)} count allUnits == 0) and (secondaryWeapon player == "") and (primaryWeapon player == "") and (handgunWeapon player == "") and (vest player == "")};
player setCaptive true;
hint "You are in Undercover Mode";
waitUntil {sleep 1;({((side _x== EAST) or (side _x== independent)) and (_x distance player < 10)} count allUnits > 0) or (secondaryWeapon player != "") or (primaryWeapon player != "") or (handgunWeapon player != "") or (vest player != "") or (!captive player)};
player setCaptive false;
hint "You are no longer in Undercover Mode";
waitUntil {sleep 1; ({((side _x== EAST) or (side _x== independent)) and (_x knowsAbout player > 0) and (_x distance player < 50)} count allUnits == 0)};
sleep 60;
};

 

I then placed: player addAction ["Go undercover","scripts\undercover.sqf"];  in the initplayerlocal.sqf

 

It seems to work great for what i need - i am a very basic scripter at the moment and would really like some help in modifying the undercover script above to include the following:

 

1.  Hints that tell you what the issue is if you can not enter undercovermode - i.e "you need to holster your sidearm to go undercover" or "you need to holster your side arm and remove your vest to go undercover"

2.  Is there a way for the script to check what uniform you are wearing? at the moment using the scripts i modified above you can still wear military uniform and go undercover as long as all weapons and vest are removed.

3.  I modified this as i couldnt get the script working with the vehicle array stuff in it - is there a way for it to stop undercover mode if you are in a military vehicle?

 

Hydrol

 

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  

×