Jump to content
Sign in to follow this  
coolfact

Making script JIP compatible

Recommended Posts

So I have made a MHQ script, but can't get it to work with JIP, the script is called in the MHQ unit init:

null=[this] execVM "MHQ_init.sqf";

MHQ_init.sqf

if (!isDedicated) then {
waitUntil {!isNull player};
_MHQ = _this select 0;
_MHQ allowDamage false;
_MHQ addAction["Deploy MHQ","Deploy.sqf",[_MHQ], 0, false, true, "", "_this in (crew _target) && {speed _target < 1}"];
};

Deploy.sqf

private ["_MHQ","_IDMHQ","_markerstr","_mkrname"];
_MHQ = (_this select 3) select 0;
_IDMHQ = _this select 2;
_MHQ removeAction _IDMHQ;
_MHQ setfuel 0;
_markerstr = format["_markerstr_%1",_MHQ];
_mkrname = format["Respawn_West_%1",_MHQ];
_markerstr = createMarkerLocal [_mkrname,[(getPos _MHQ select 0),(getPos _MHQ select 1)]];
_markerstr setMarkerShapeLocal "ICON";

_MHQ addAction["Repack MHQ","Repack.sqf",[_MHQ,_markerstr], 0, false, true,"", "_this in (crew _target)"];

Repack.sqf

private ["_MHQ","_IDMHQ","_markerstr"];
_MHQ = (_this select 3) select 0;
_markerstr = (_this select 3) select 1;
_IDMHQ = _this select 2;
_MHQ removeAction _IDMHQ;
deleteMarkerLocal _markerstr;
_MHQ setfuel 1;

_MHQ addAction["Deploy MHQ","missionscripts\MHQ\Deploy.sqf",[_MHQ], 0, false, true, "", "_this in (crew _target) && {speed _target < 1}"];

Share this post


Link to post
Share on other sites

You might be able to call it as a function, many scripts in my group's missions with JIP issues needed to be functions.

null = [this] call compile preprocessFileLineNumbers "MHQ_init.sqf"; 

Share this post


Link to post
Share on other sites

It could be that your creating the marker locally, and since your using an addAction, that means whomever executes the action can see the marker, but no one else. I may be mistaken as to the "locality" of createMarkerLocal, but just my idea.

Out of pure laziness in my current project I just placed an editor marker down "outside" of the map on the black outline portion, named it "blah" and then in the script I just have a setMarkerPos (getPos _obj) command, works fine, and covers JIP/respawn etc. (as far as I'm aware).

Edited by JShock

Share this post


Link to post
Share on other sites

Yeah Im pretty sure its a location problem, I will try it out Jshock

Share this post


Link to post
Share on other sites

maybe you need to use BIS_fnc_MP with persistent = true on AddAction..

on init.sqf make a function to all:

fnc_MyAddActionFunction = {
private ["_ActObj","_ActName","_ActScript","_ActArgumn","_ActCondition"];

_ActObj =  [_this,0] call BIS_fnc_param;
_ActName= [_this,1] call BIS_fnc_param;
_ActScript = [_this,2] call BIS_fnc_param;
_ActArgumn = [_this,3,[],["",[],0,objNull]] call BIS_fnc_param;
_ActCondition = [_this,4, "(_target distance _this) < 3",[""]] call BIS_fnc_param;

if(isNull _ActObj) exitWith {};
_ActObj addAction [_ActName, _ActScript, _ActArgumn, 1, True, True, "",_ActCondition];
};

and then replace:

_MHQ addAction["Deploy MHQ","Deploy.sqf",[_MHQ], 0, false, true, "", "_this in (crew _target) && {speed _target < 1}"];

with this

[[_MHQ,"<t color='#FFFF00'>Deploy MHQ</t>","Deploy.sqf",[],"_this in (crew _target) && {speed _target < 1}"],"fnc_MyAddActionFunction",nil,true] call BIS_fnc_MP;	

Edited by KoVValsky

Share this post


Link to post
Share on other sites

Locality will be the issue.

Here's some code I used for a very similar situation. I made a choice to keep the actions on the vehicle and enable/disable them by using the conditional variables "deployed" and "cooldown". If I were to re-write this now I would use setVariable on the vehicle to create a public variable in a sensible place. As it is, the scripts "makeBase.sqf", "cooldown.sqf" and such just use the variables and then public them as well as doing the actual necessary work of generating the base.

The advantage of not adding and removing the actions is that you can't have a JIP player reset the base to undeployed mode or vice versa.

removeAllActions hq;
hq addAction["<t color='#ff1111'>Deploy Base</t>",
      {

	if (({(side _x)== resistance} count (getPos hq nearObjects ["Man",300])) > 0) then {
 titleText ["You can't deploy here, enemies are within 300m","PLAIN",1]; 


	  } else {

[[[],"scripts\makeBase.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;

 };


[[[],"scripts\cooldown.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;},
nil,1.5,true,true,"",
"(side player != resistance)&&(!deployed)&&(!cooldown)&&((abs (speed hq)) < 2)"]; 


hq addAction[
"<t color='#ff1111'>Undeploy Base</t>",
{[[[],"scripts\breakBase.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;[[[],"scripts\cooldown.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;},
nil,1.5,true,true,"",
"(side player != resistance)&&(deployed)&&(!cooldown)"];

Share this post


Link to post
Share on other sites

Now I may be talking out of my knowledge, but, the most recent release of Arma 3 now allows BIS_fnc_MP to use script commands, so you may be able to use that now to help broadcast what needs broadcasting??

In other words put the addAction line right into the parameters for BIS_fnc_MP.

Share this post


Link to post
Share on other sites

Indeed, I believe that he could do that. Care would still be necessary to ensure that a JIP doesn't reset the HQ, however.

Share this post


Link to post
Share on other sites
Indeed, I believe that he could do that. Care would still be necessary to ensure that a JIP doesn't reset the HQ, however.

Yep, but that should be easy enough with a few JIP checks at the top of the script, I would think.

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  

×