Jump to content
Sign in to follow this  
O.Languedoc

Mobile HQ that deploys from a Container. Addaction issue. Need help.

Recommended Posts

Hi everybody.

I am trying something different for a mission that i working on. We are often using vehicle has mobile HQ out on the field but i tought that this was too easy and unrealistic. I then decided to make a little bit different so it adds the impression on setting up camp when you deploy the mobile HQ. Instead of a vehicle i use a Container. The container has an Addaction on it calling a script that create objects and place them in the surrounding of the Container. I manage to create the objects around the container. Now i want to remove the action from the container that was originally in his init and create a new addaction calling a script that will give the impression of Repacking the HQ by deleting the created content and reAdding the Deploy AddAction.

Object placed in the editor: Container

Name of the Object : HQ1

Init Code of the Object :

this addAction["<t color='#ff1111'>Deploy Mobile HQ</t>", "HQ1.sqf"];

HQ1.SQF

//Creation of camo cover

_camocover = "CamoNet_BLUFOR_big_F" createVehicle ([ (getPos HQ1 select 0)+0.05, (getPos HQ1 select 1), (getPos HQ1 select 2)+200] );
_camocover attachTo [HQ1, [0,0,0]];
detach _camocover;



//Creation of supplycrate

_supply = "B_supplyCrate_F" createVehicle ([ (getPos HQ1 select 0), (getPos HQ1 select 1),(getPos HQ1 select 2)+200] );
_supply = attachTo [HQ1, [-0.5,-0.2,0]];
detach _supply;


//delete the action to remove the possibility to redeploy the HQ again.

_removeActionDeploy = removeAllActions HQ1;


// Add an Action to HQ1 so we can call the repack HQ script

_addRepack = HQ1 addAction ["RePackage HQ","reHQ1.sqf"];

reHQ1.SQF

// Delete cover & Delete supplycrate

_deletecover = deletevehicle _camocover 
_deleteSupply = deletevehicle _supply

// Remove the action on the container HQ1 so we cannot repack twice

_removeActionRepack = removeAllActions HQ1;

// add an Action to HQ1 so we can finish the loop and redeploy the container

_addDeploy = HQ1 addAction ["Deploy HQ", "HQ1.sqf"];

So here are my two scripts. I know i am doing something wrong. I hope someone can help me make this work. Thx for the help.

R22R-Sillyflip

Edited by sillyflip
error when posting

Share this post


Link to post
Share on other sites

_camocover and _supply are not defined in the second script. That's probably where your problem lies.

Share this post


Link to post
Share on other sites

How do you suggest I defined them. they were created the first script? Also i think my error comes earlier then this, since the -removeAllActions- doesnt remove the action on my container named HQ1.

Share this post


Link to post
Share on other sites

Well, you are assigning it to a variable, which wont work.

removeAllActions HQ1

then for defining the objects in the second script. You can use a simple method like nearestObject to return that object.

_camocover = getPos HQ1 nearestObject "CamoNet_BLUFOR_big_F"; 
_supply = getPos HQ1 nearestObject "B_supplyCrate_F"; 

Also, you have a local variable before the deleteVehicle command. That wont work, like the removeAllActions command.

deleteVehicle _camocover;
deleteVehicle _supply;

Having an underscore ( _ ) before a variable causes it to be local to that script. It does not exist in any other script, then. You'll have to define it again to make use of that variable.

Share this post


Link to post
Share on other sites

not working. removeallactionsns HQ1 dont work. Deploy action is still there.

---------- Post added at 03:58 ---------- Previous post was at 03:34 ----------

Ok. I manage to get it to work in SinglePLayer. I dont know if it will work in Multiplayer (nobody to test it tonight).

Container Name : HQ1

Container Init:

HQ1Deploy = HQ1 addAction["<t color='#ff1111'>Deploy HQ</t>", "HQ1.sqf"];

HQ1.SQF

_HQ = _this select 0;
_caller = _this select 1;
_id = _this select 2;

_HQ removeAction _id;
_HQ addaction ["RePackage HQ","reHQ1.sqf"];

//Creation of camo cover

_camocover = "CamoNet_BLUFOR_big_F" createVehicle ([ (getPos HQ1 select 0)+0.05, (getPos HQ1 select 1), (getPos HQ1 select 

2)+200] );
_camocover attachTo [HQ1, [0,0,0]];
detach _camocover;



//Creation of supplycrate

_supply = "B_supplyCrate_F" createVehicle ([ (getPos HQ1 select 0), (getPos HQ1 select 1),(getPos HQ1 select 2)+200] );
_supply = attachTo [HQ1, [-0.5,-0.2,0]];
detach _supply;

reHQ1.SQF

_HQ = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_camocover = getPos HQ1 nearestObject "CamoNet_BLUFOR_big_F";
_supply = getPos HQ1 nearestObject "B_supplyCrate_F";

_HQ removeAction _id;
_HQ addaction ["Deploy HQ","HQ1.sqf"];

// Delete cover & Delete supplycrate

deletevehicle _camocover; 
deletevehicle _supply;

So this is working. I Deployed and rePack many times. I'll test it in multiplayer when i have a chance. Next i want to spawn a flag that will have a specific name/Id/variable so i can link it to a Mobile Spawn Script. Should i use a global variable when i create the objects? ( ex. camocover = X ) instead of ( ex. _camocover = X)

Share this post


Link to post
Share on other sites

Its not working well in MP. Its a addaction Broadcast issue i think... I wrote a full post on this new issue. Received a message saying that it needed approval from moderator. i think the moderator blocked it??? Wrote it Before posting the pictures. Weird.

---------- Post added at 22:11 ---------- Previous post was at 20:42 ----------

I'll rewrite it when in a couple of days when i come back home

Share this post


Link to post
Share on other sites

AddAction is a local command. Later tonight, after work, I'll write you a function you can call to apply the command globally.

Share this post


Link to post
Share on other sites

Thx for the help Flight. My script changed a lot on the past 24h. I wont be able To post it here until tuesday. I suggest you wait a bit before spending Time on this. You'll have the final working version in SP that needs to be concerted To MP.

Share this post


Link to post
Share on other sites

I don't know if this will work in MP but as it doesn't remove and add actions it may work ok.

just place both lines in the units init.


this addAction ["Deploy    HQ",{"HQ1.sqf";  (_this select 0)  setvariable ["state",false,true]},[],0,true,true,"","_target getvariable ['state',true]"];  this addAction ["RePackage HQ",{"reHQ1.sqf";(_this select 0)  setvariable ["state",true,true] },[],0,true,true,"","!(_target getvariable ['state',true])"];

it doesn't need any external code it just acts like a switch, one turns off the other.

Share this post


Link to post
Share on other sites

Alright, since I was making one function, I decided to put the whole script into functions. This reduces it down to one file. Just make a sqf file in your mission folder and add the following script below. Then put 0 = [this] execVM "scriptName.sqf"; in your cargo containers INIT box. The addActions, I placed in a function, then ran that function through BIS_fnc_MP, which is another function that runs functions globally. Its quite useful for stuff like this. The switch method I use in my function is something I made for another script I haven't released yet. This method also makes the script much more universal. You can run it on as many cargo containers as you like, not just one named HQ1.

Well, here it is.

//Mobile Container HQ
// 0 = [this] execVM "scriptName.sqf"; <--- Put in containers INIT

sillyflip_fnc_deployHQ = {
private ["_HQ","_caller","_id","_remove","_add","_camocover","_supply"];
_HQ = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_remove = [[_HQ,3,_id],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
_add = [[_HQ,1],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
_camocover = "CamoNet_BLUFOR_big_F" createVehicle ([ (getPos _HQ select 0)+0.05, (getPos _HQ select 1), (getPos _HQ select 2)+200] );
_camocover attachTo [_HQ, [0,0,0]];
detach _camocover;
_supply = "B_supplyCrate_F" createVehicle ([ (getPos _HQ select 0), (getPos _HQ select 1),(getPos _HQ select 2)+200] );
_supply attachTo [_HQ, [-0.5,-0.2,0.1]];
detach _supply;
true;
};

sillyflip_fnc_packHQ = {
private ["_HQ","_caller","_id","_camocover","_supply","_remove","_add"];
_HQ = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_camocover = getPos _HQ nearestObject "CamoNet_BLUFOR_big_F";
_supply = getPos _HQ nearestObject "B_supplyCrate_F";
_remove = [[_HQ,3,_id],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
_add = [[_HQ,2],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;	
deleteVehicle _camocover;
deleteVehicle _supply;
true;
};

sillyflip_fnc_addActionHQ = {
private ["_civ","_case","_ID","_this"];
_HQ = _this select 0;
_case = _this select 1;
_ID = if (count _this > 2) then {_this select 2} else {nil};
switch (_case) do {
	case 1: {_HQ addaction ["<t color='#ff1111'>RePackage HQ</t>",sillyflip_fnc_packHQ];};
	case 2: {_HQ addaction ["<t color='#ff1111'>Deploy HQ</t>",sillyflip_fnc_deployHQ];};
	case 3: {_HQ removeAction _ID;};
};
_case;
};

(_this select 0) addAction ["<t color='#ff1111'>Deploy HQ</t>",sillyflip_fnc_deployHQ];

Share this post


Link to post
Share on other sites

Hi flight,

Just came back. I tested it in SP and it works. I'll test it with some friends soon to see if it works in MP. I'll keep you posted. Thx a lot.

---------- Post added at 15:21 ---------- Previous post was at 14:00 ----------

Ok. Tested it in multiplayer. Spawning the camo works. But often its not attaching to the same position on all clients. It often collapse on the ground when it appear. Spawning and attaching the Supply box works most of the time. Flight, Before you sent the reWritten version i added a flag with a global name that is setup as a MobileSPawn point in INS_Revive. So when deploying i need to move that flag to the Container for all client. I added to your new script the move command for the flag, but it doesnt work with all client. Only the client that is deploying de HQ sees the flag move. After a couple of sec it goes back to its initial position. The other clients dont see the flag move at all, still at initial pos. Moving the flag works in SP. i think it might be a position sycnh issue with JIP.

here is the code.

//Mobile Container HQ
// 0 = [this] execVM "scriptName.sqf"; <--- Put in containers INIT
// Change the name of the spawnflag that you placed in the editor and that is setup has a spawn in INS_REVIVE

sillyflip_fnc_deployHQ = {
   private ["_HQ","_caller","_id","_remove","_add","_camocover","_supply"];
   _HQ = _this select 0;
   _caller = _this select 1;
   _id = _this select 2;
   _remove = [[_HQ,3,_id],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
   _add = [[_HQ,1],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
   _camocover = "CamoNet_BLUFOR_big_F" createVehicle ([ (getPos _HQ select 0)+0.05, (getPos _HQ select 1), (getPos _HQ select 2)+200] );
   _camocover attachTo [_HQ, [0,0,0]];
   detach _camocover;
   _supply = "B_supplyCrate_F" createVehicle ([ (getPos _HQ select 0), (getPos _HQ select 1),(getPos _HQ select 2)+200] );
   _supply attachTo [_HQ, [-0.5,-4,0]];
   detach _supply;
_supply addAction["<t color='#ff1111'>Virtual Ammobox</t>", "INS_revive\VAS\open.sqf"];

//Move the spawn flag //

mobileHQ1_initPos = getPos mobileHQ1;//Initial editor position of the flag named mobileHQ1

mobileHQ1 attachto [_HQ, [0,-15,2]]; // Move the flag to the container
detach mobileHQ1;
true;
};

sillyflip_fnc_packHQ = {
   private ["_HQ","_caller","_id","_camocover","_supply","_remove","_add"];
   _HQ = _this select 0;
   _caller = _this select 1;
   _id = _this select 2;
   _camocover = getPos _HQ nearestObject "CamoNet_BLUFOR_big_F";
   _supply = getPos _HQ nearestObject "B_supplyCrate_F";
   _remove = [[_HQ,3,_id],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
   _add = [[_HQ,2],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;    
   deleteVehicle _camocover;
   deleteVehicle _supply;

// Move the flag back to its initial position.

mobileHQ1 setPos mobileHQ1_initPos; 
   true;
};

sillyflip_fnc_addActionHQ = {
   private ["_civ","_case","_ID","_this"];
   _HQ = _this select 0;
   _case = _this select 1;
   _ID = if (count _this > 2) then {_this select 2} else {nil};
   switch (_case) do {
       case 1: {_HQ addaction ["<t color='#ff1111'>RePackage HQ</t>",sillyflip_fnc_packHQ];};
       case 2: {_HQ addaction ["<t color='#ff1111'>Deploy HQ</t>",sillyflip_fnc_deployHQ];};
       case 3: {_HQ removeAction _ID;};
   };
   _case;
};

(_this select 0) addAction ["<t color='#ff1111'>Deploy HQ</t>",sillyflip_fnc_deployHQ];  

Every container will have a dedicated spawn flag. I know i will have to edit the script for each of them.

Here is a link to the PBO. MOBILE HQ TEST

This is what i think is missing. BroadCast of Public Variable.

Edited by sillyflip
added link to public variable BlogPost

Share this post


Link to post
Share on other sites

Ok, I tried to edit the flag in. It's late and I dont want to test it so you will have to do it for me. The problem defining multiple flags is that I am making these functions global. I am not sure how it will work sending the flag with the initial execVM, but you can test it for me. The first one will allow you to send the flags name with the INIT line for the container. This will help make the script more universal. If that doesn't work, then use the second version. If that doesn't work, then I will work something new out.

There is only a slight difference between the two versions but I have never sent a variable into a define like I did in the first one. We'll see how that works.

*** Removed incorrect scripts ***

If these do not work, let me know. I'll then re-write some of the functions and compile them first instead of doing it this way. It wouldn't be that hard but its time that I don't really have. I don't mind helping you, just don't expect a quick response. :)

Also, you keep typing my name wrong.

Edited by Fight9

Share this post


Link to post
Share on other sites

Sorry for The error in your name. I'll try this in a couple of days. I am away again.

So basically this issue is that we don't broadcast the flag position globally?

Share this post


Link to post
Share on other sites

LOCAL SERVER 1 player VERSION 1 :

On activation of the action Deploy.

CamoCover is created, Ammo Box is Created.

Flag is not Moved.

On activation of the action Repack.

CamoCover and Ammo Box are deleted.

VERSION 2 LOCAL server 1 player.

On activation of Deploy.

CamoCover Created, AmmoBox Created, Flag Moved.

On activation of Repack

CamoCover and AmmoBox Deleted but flag dont move back to STARTPOS.

------

Waiting for online buddies to test online with JIP Players.

Share this post


Link to post
Share on other sites

I know what the problem is. I'll have to store the starting location of the flag in a variable. I'll fix it tonight.

I must have been drunk when I wrote that last version. It's way wrong.

Edited by Fight9

Share this post


Link to post
Share on other sites

Here you go, dude. I got my head out of my ass and did it right.

see comments for execution

///////////////////////////////
// Mobile Container HQ
// Written by Fight9 for sillyflip
// 0 = [this, flagName] execVM "scriptName.sqf"; <--- Put in containers INIT
//////////////////////////////

// Definitions for easy editing
#define CAMOCOVER "CamoNet_BLUFOR_big_F" // <-- Camo Cover class name
#define CRATE "B_supplyCrate_F" // <-- Supply Crate class Name

sillyflip_fnc_deployHQ = {
   private ["_HQ","_caller","_id","_remove","_add","_camocover","_supply","_flagData","_flag"];
   _HQ = _this select 0;
   _caller = _this select 1;
   _id = _this select 2;
   _remove = [[_HQ,3,_id],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
   _add = [[_HQ,1],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
   _camocover = CAMOCOVER createVehicle ([ (getPos _HQ select 0)+0.05, (getPos _HQ select 1), (getPos _HQ select 2)+200] );
_camocover allowDamage false;
   _camocover attachTo [_HQ, [0,0,0]];
   detach _camocover;
   _supply = CRATE createVehicle ([ (getPos _HQ select 0), (getPos _HQ select 1),(getPos _HQ select 2)+200] );
   _supply attachTo [_HQ, [-0.5,-0.2,0.1]];
   detach _supply;
_flagData = _HQ getVariable "flagData";
_flag = _flagData select 0;
_flag attachto [_HQ, [0,-15,2]]; // Move the flag to the container
detach _flag;
sleep 1;
_camocover allowDamage true;
   true;
};

sillyflip_fnc_packHQ = {
   private ["_HQ","_caller","_id","_camocover","_supply","_remove","_add","_flagData","_flag","_flagPos"];
   _HQ = _this select 0;
   _caller = _this select 1;
   _id = _this select 2;
   _camocover = getPos _HQ nearestObject CAMOCOVER;
   _supply = getPos _HQ nearestObject CRATE;
   _remove = [[_HQ,3,_id],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;
   _add = [[_HQ,2],"sillyflip_fnc_addActionHQ",true,true] call BIS_fnc_MP;    
   deleteVehicle _camocover;
   deleteVehicle _supply;
_flagData = _HQ getVariable "flagData";
_flag = _flagData select 0;
_flagPos = _flagData select 1;
_flag setPos _flagPos;
   true;
};

sillyflip_fnc_addActionHQ = {
   private ["_civ","_case","_ID","_this"];
   _HQ = _this select 0;
   _case = _this select 1;
   _ID = if (count _this > 2) then {_this select 2} else {nil};
   switch (_case) do {
       case 1: {_HQ addaction ["<t color='#ff1111'>RePackage HQ</t>",sillyflip_fnc_packHQ];};
       case 2: {_HQ addaction ["<t color='#ff1111'>Deploy HQ</t>",sillyflip_fnc_deployHQ];};
       case 3: {_HQ removeAction _ID;};
   };
   _case;
};

_HQ = _this select 0;
_flagPole = _this select 1;
_flagData = [_flagPole,(getPos _flagPole)];  
_HQ setVariable ["flagData",_flagData,true];
_HQ addAction ["<t color='#ff1111'>Deploy HQ</t>",sillyflip_fnc_deployHQ];

I didn't test it in MP, but I dont expect any issues.

Edited by Fight9

Share this post


Link to post
Share on other sites

Good morning Fight9,

I have just finished testing the script in Local and Multiplayer with another player.

The game was hosted on my machine. When I (the server client) deploy. it works. When the JIP do it, the flag doesnt move and the camover doesnt spawn exactly at the right place and fall to the ground.

I didnt tought it was that complex to make something appear in game lol. I will try with another object then a flag so see if there is a difference.

Thx again for all this.

Share this post


Link to post
Share on other sites

///////////////////////////////
// Mobile Container HQ
// Written by Fight9 for sillyflip
// 0 = [this, flagName] execVM "scriptName.sqf"; <--- Put in containers INIT
//////////////////////////////

// Definitions for easy editing
#define CAMOCOVER "CamoNet_BLUFOR_big_F" // <-- Camo Cover class name
#define CRATE "B_supplyCrate_F" // <-- Supply Crate class Name

_HQ = _this select 0;

if (isServer) then {
_flagPole = _this select 1;
_flagData = [_flagPole,(getPosATL _flagPole)];
_HQ setVariable ["flagData",_flagData];
_HQ setVariable ["deployed",false,true];

sillyflip_fnc_deployHQ = {
 	private ["_HQ","_camocover","_supply","_flag"];
 	_HQ = _this select 0;
 	_camocover = createVehicle [CAMOCOVER, getPosATL _HQ,[],0,"CAN_COLLIDE"];
 	_HQ setVariable ["CAMO",_camocover];
 	_camocover allowDamage false;
 	_supply = createVehicle [CRATE,[ (getPos _HQ select 0)-2, (getPos _HQ select 1)-0.2,(getPos _HQ select 2)+0.1],[],0,"CAN_COLLIDE"];
 	_HQ setVariable ["SUPPLY",_supply];
 	_flag = (_HQ getVariable "flagData") select 0;
 	_flag attachTo [_HQ, [0,-15,2]]; // Move the flag to the container
 	detach _flag;
 	sleep 1;
 	_camocover allowDamage true;
 	_HQ setVariable ["deployed",true,true];
};

sillyflip_fnc_packHQ = {
	 private ["_HQ","_flag"];
	 _HQ = _this select 0;
	 deleteVehicle (_HQ getVariable "CAMO");
	 deleteVehicle (_HQ getVariable "SUPPLY");
	 _flag = ((_HQ getVariable "flagData") select 0);
	 _flag setPos ((_HQ getVariable "flagData") select 1);
	 _HQ setVariable ["deployed",false,true];
};

};

if (!isDedicated) then {
waitUntil{!(isNull player)};

_HQ addAction ["<t color='#ff1111'>Deploy HQ</t>",{
		[_this,"sillyflip_fnc_deployHQ",false] call BIS_fnc_MP;
	}
	,[],0,true,true,"","!(_target getVariable ['deployed',true])"];

_HQ addAction ["<t color='#ff1111'>Pack HQ</t>",{
		[_this,"sillyflip_fnc_packHQ",false] call BIS_fnc_MP;
	},[],0,true,true,"","_target getVariable ['deployed',false]"];

//Uncomment for testing to move HQ crate to players location
//player addAction ["Move HQ",{((_this select 3) select 0) setPosATL (getPosATL player)},[_HQ]];
};

This leaves all the heavy lifting to the server (The only thing that is not set globally is the enableDamage false on the CAMO while it is being created, I have chosen to ignore this fact as it is only set for a very short period and hopefully has minor impact on the whole process (not particularly sure its needed at all any more) ).

The only thing the clients know about are the two addActions, there is no need to keep adding and removing the actions, they are shown dependent on the HQ's deployed variable which is transmitted and looked after by the server via setVariable, this also prevents BIS_fnc_MP stacking multiple calls for JIP's each time the addActions are added/removed via BIS_fnc_MP's isPersistent param. I have removed the nearestObjects commands and instead stored the objects on the HQ itself, the majority of the attachTo's have gone aswell, instead utilizing createVehicle ARRAY's CAN_COLLIDE instead.

Not meaning to step on your toes Flight, it was just a nice little project to have a go at for an hour.

Quickly tested on a dedicated server but with no one around to fully test JIP functionality and did not have the time to setup a persistent mission to jump in and out of.

Let me know how you get on.

Edited by Larrow

Share this post


Link to post
Share on other sites

That looks good. Thank you for doing that.

I might have just learned a thing or two.

Share this post


Link to post
Share on other sites

Well, it works guys.

Thx a lot. I added a marker to the script that So it can work via moving the flag in INS Revive and via the normal spawn system in Arma. If i want to make the addaction radius smaller, like 1meter what parameters of the addaction do i change? I looked at the code and it seems like a custom addaction.

Share this post


Link to post
Share on other sites

Change the condition in the actions to look like this...

"(!(_target getVariable ['deployed',true])) && ((_this distance _target) < 1)"

"(_target getVariable ['deployed',false]) && ((_this distance _target) < 1)"

Share this post


Link to post
Share on other sites

Hello awesome script, thank you very much, quick question, is there a way to spawn soldiers to guard the HQ? im working on a persistent map, and i need that so they can guard taken posts..

 

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  

×