[SCRIPT] an action to place F2 tripflares

Party-approved programming
Post Reply
User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

[SCRIPT] an action to place F2 tripflares

Post by wolfenswan »

This script allows a selection of units to place exactly one F2 Trip Flare. The units, radius of the tripflare and side which triggers the tripflare can be customized.
As the only thing this script does is placing a trigger it can easily be modified to fire anything one could imagine.


init.sqf

Code: Select all

[[unitname1,unitname2],15,5,east] execVM "ws_scripts\ws_tripwire_init.sqf";
_this select 0 is an array with all the unitnames that would get the action.
_this select 1 is a number for length of tripwire area
_this select 2 is a number for width of tripwire area
_this select 3 is a valid side

ws_tripwire_init

Code: Select all

private ["_units"];

_units = _this select 0;
_size1 = _this select 1; //Length
_size2 = _this select 2; //Width
_side = _this select 3;

if (isNil "ws_tripwire") then {ws_tripwire = []};

ws_fnc_tripwire = {
		pos = ws_tripwire select 0;
		_size1 = ws_tripwire select 1;
		_size2 = ws_tripwire select 2;
		_side =ws_tripwire select 3;
		_dir = ws_tripwire select 4;
		_sidestr = format ["%1",_side];
		
		_trg=createTrigger["EmptyDetector",_pos];
		_trg setTriggerArea[_size2,_size1,_dir,true];
		_trg setTriggerActivation[_sidestr,"PRESENT",false];
		_trg setTriggerStatements["this","nul = [thisList,thisTrigger] execVM ""f\common\f_tripflare.sqf"";", ""];
		
		if (side player == _side) exitWith {};
		_mkr = createMarkerLocal [format["%1",_pos], _pos];
		_mkr setMarkerShapeLocal "RECTANGLE";
		_mkr setMarkerSizeLocal [_size2,_size1];
		_mkr setMarkerDirLocal _dir;
		_mkr setMarkerColorLocal "ColorRed";
		_mkr setMarkerBrushLocal "BORDER";
	};

{_x addAction ["<t color='#dddd00'>"+"Place tripwire"+"</t>","ws_scripts\ws_tripwireaction.sqf",[_size1,_size2,_side],1,false,true,"","(driver _target == _this)"];} forEach _units;
	
"ws_tripwire" addPublicVariableEventHandler {call ws_fnc_tripwire;};
ws_tripwireaction.sqf

Code: Select all

private ["_unit","_pos","_id","_size","_side","_sidestr","_mkr"];

_unit = _this select 1;
_pos = getPos _unit;
_dir = getDir _unit;
_id = _this select 2;
_size1 = (_this select 3) select 0;
_size2 = (_this select 3) select 1;
_side = (_this select 3) select 2;

_unit removeAction _id;

ws_tripwire = [_pos,_size1,_size2,_side,_dir];
publicvariable "ws_tripwire";
	
call ws_fnc_tripwire;

Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by Black Mamba »

At first glance, this one might be problematic:

Code: Select all

if (side player == _side) exitWith {};
as side won't return a string.
So you should be better off inputing a side at the beginning, and converting it to a string (eg using format) when you want to use it in the trigger.

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by wolfenswan »

You're right. Here's my updated code, need to test it.

Code: Select all

[[dude,dude1],15,east] execVM "ws_scripts\ws_tripwire_init.sqf";

Code: Select all


private ["_units"];

_units = _this select 0;
_size = _this select 1;
_side = _this select 2;
_sidestr = "";

switch (_side) do {
case west: {_sidestr = "WEST"};
case east: {_sidestr = "EAST"};
case resistance: {_sidestr = "GUER"};
case civilian: {_sidestr = "CIV"};
};

if (isNil "ws_tripwire") then {ws_tripwire = []};

ws_fnc_tripwire = {
		_pos = ws_tripwire;
		_trg=createTrigger["EmptyDetector",_pos];
		_trg setTriggerArea[_size,_size,0,true];
		_trg setTriggerActivation[_sidestr,"PRESENT",true];
		_trg setTriggerStatements["this","player groupchat 'triggered';nul = [thisList,thisTrigger] execVM ""ws_scripts\f_tripflare_custom.sqf"";", ""];
		
		if (side player == _side) exitWith {};
		_mkr = createMarkerLocal [format["%1",_pos], _pos];
		_mkr setMarkerShapeLocal "RECTANGLE";
		_mkr setMarkerSizeLocal [_size,_size];
		_mkr setMarkerDirLocal 0;
		_mkr setMarkerColorLocal "ColorRed";
		_mkr setMarkerBrushLocal "BORDER";

		player globalchat format ["DBG:%1,%2,%3,%4,%5",ws_tripwire,_trg,_size,_side,_sidestr];
	};

{_x addAction ["<t color='#dddd00'>"+"Place tripwire"+"</t>","ws_scripts\ws_tripwireaction.sqf",[_size,_side,_sidestr],1,false,true,"","(driver _target == _this)"];} forEach _units;
	
"ws_tripwire" addPublicVariableEventHandler {call ws_fnc_tripwire;};

Code: Select all

private ["_unit","_pos","_id","_size","_side","_sidestr","_mkr"];

_unit = _this select 1;
_pos = getPos _unit;
_id = _this select 2;
_size = (_this select 3) select 0;
_side = (_this select 3) select 1;
_sidestr = (_this select 3) select 2;

_unit removeAction _id;

ws_tripwire = _pos;
publicvariable "ws_tripwire";
	
call ws_fnc_tripwire;

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by wolfenswan »

that did not fix it, it still doesn't like the parsed stuff.

A not directly related but interesting observation:
The values returned by speed differ MASSIVELY depending on locality. It seems like only the local units return correct values (in most cases only the player unit itself), everything else is at a tenth of what it should be, both AI and other players. This makes vectorization useless as well.

Comparison of (vectorized) values:
- for a running unit when hosting locally returns ~ 10
- on a dedi., for a running unit that's local to another client/the server it returns ~ 1 - 0.5
- on a dedi., for a running unit that's local to you or your own unit ~ 10

Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by Black Mamba »

Yeah, this has been reported a number of times already, and is basically at the core of what's currently blocking that headless client stuff. Only the server "knows" exactly what's happening. Clients only have a botched perception, kinda on a "need to know" basis.

I'll have a more thorough look at your stuff as soon as I find time. Same for that pull request, by the way. Need a lil more testing.

Edit: By the way, you don't need a switch here. format ["%1",_side] will return exactly the string you need.

Re-edit: Huh.

Code: Select all

call ws_fnc_tripwire;
Didn't you forget to pass the parameters?
Plus you're not executing on the caller anymore. Or am I just too tired to read properly?

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by wolfenswan »

I just had the amazing idea to turn into ws_tripwire into an array of all values relevant to the function ([_pos,_side] etc.)
Edit: By the way, you don't need a switch here. format ["%1",_side] will return exactly the string you need.
That works for west/east but not for resistance/"GUER" and civilian/"CIV"

Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by Black Mamba »

Are you sure about that? I'm pretty sure it does work for all sides. str on the other hand might return different strings.

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by wolfenswan »

Edit: nevermind, I didn't know it would transform it in a format statement.

What I mean is that the trigger requires one of these Strings to check for a side:
Side': "EAST", "WEST", "GUER", "CIV", "LOGIC", "ANY"
If I use
_side = resistance;
format ["%1",_side];

I get "resistance", something the trigger can't handle.
Unless the Wiki's just wrong and the trigger recognizes both "resistance" and "guer"?

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: [SCRIPT] WIP/Help needed - an action to place F2 tripfla

Post by wolfenswan »

Heureka! it works.

Updated OP to reflect working script.

Post Reply