Jump to content
1para{god-father}

Advice on Dialog and Local / server issue

Recommended Posts

Hi Guys,

 

Need some advice , i have my GUI and its all working  and spawns in my groups  etc...

 

As I am using a Dialog does all the spawns -  spawn Local not on server  i.e i am running this on my Dedibox  - they all spawn fine but no EH or addactions 

 

example  through my GUI buttons  ( this is not full code but just an  example of what i am doing)

_grpP = [getmarkerpos "sZoneLocal", EAST, (configFile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call BIS_fnc_spawnGroup;

{
				_x setVariable ["AISpawnTime", time];

				_x setVariable ["AISpawnPos",_cpPos];
				_x setVariable ["LastAIDistanceCheck",time];
				_x addMPEventHandler ["MPKilled",'if (isServer) then {_this call God_fnc_OnKilled;};'];
} foreach (units  _grpP  );


////////////and this as well how would I add an addaction to an object that would work on Dedi ?

[_object, ["<t color='#ff0000'>Defuse The Bomb</t>", God_fnc_actionDefuse, [], 1.5, true, true, "", _condition, 3, false]] remoteExec ["addAction", 0, true];

 

Share this post


Link to post
Share on other sites

init.sqf

 

#include "\a3\ui_f\hpp\definedikcodes.inc"

_adminIDs = [ "76561198027698781", "76561198027698781" ];

if (
	hasInterface &&		//Client machine
	{
		isServer ||	//SP
		{ getPlayerUID player in _adminIDs } ||		//Predefined admin
		{ serverCommandAvailable "#exportjipqueue" } ||		//Logged in admin
		{ !isNil { missionNamespace getVariable "BIS_fnc_admin" } && { call BIS_fnc_admin isEqualTo 2 } }	//Logged in admin, A3 version 1.70 maybe?
	}
) then {
	waitUntil { !isNull ( findDisplay 46 ) };
	( findDisplay 46 ) displayAddEventHandler [ "KeyDown", {
		params[  "_display", "_keyCode", "_shft", "_ctr", "_alt"];

		if ( _keyCode isEqualTo DIK_F10 ) then {

			[] execVM "populate.sqf";
		};
	} ];
};

Then  i create the dialog in  populate.sqf

 

If i use a Dialog / GUI  and spawn something via this is it always local ?

Share this post


Link to post
Share on other sites
4 hours ago, 1para{god-father} said:

init.sqf

 


#include "\a3\ui_f\hpp\definedikcodes.inc"

_adminIDs = [ "76561198027698781", "76561198027698781" ];

if (
	hasInterface &&		//Client machine
	{
		isServer ||	//SP
		{ getPlayerUID player in _adminIDs } ||		//Predefined admin
		{ serverCommandAvailable "#exportjipqueue" } ||		//Logged in admin
		{ !isNil { missionNamespace getVariable "BIS_fnc_admin" } && { call BIS_fnc_admin isEqualTo 2 } }	//Logged in admin, A3 version 1.70 maybe?
	}
) then {
	waitUntil { !isNull ( findDisplay 46 ) };
	( findDisplay 46 ) displayAddEventHandler [ "KeyDown", {
		params[  "_display", "_keyCode", "_shft", "_ctr", "_alt"];

		if ( _keyCode isEqualTo DIK_F10 ) then {

			[] execVM "populate.sqf";
		};
	} ];
};

Then  i create the dialog in  populate.sqf

 

If i use a Dialog / GUI  and spawn something via this is it always local ?

Yes of course, this has to be local to the player. Unless of course you're going to use remoteExec with this, you're just throwing it at the mission not the player.

 

Share this post


Link to post
Share on other sites
4 hours ago, 1para{god-father} said:

hmmmm sorry so how would i do that then as really would like it to be on server rather than local !

Where your dialog creates the AI you need to run it on the server using remoteExec. Where ever you call the code shown in the OP this needs to be a function available to the server for instance TAG_fnc_spawnAI, then from your dialog...

[ any vars needed ] remoteExec [ "TAG_fnc_spawnAI", 2 ];

Share this post


Link to post
Share on other sites
1 hour ago, Larrow said:

Where your dialog creates the AI you need to run it on the server using remoteExec. Where ever you call the code shown in the OP this needs to be a function available to the server for instance TAG_fnc_spawnAI, then from your dialog...

 


[ any vars needed ] remoteExec [ "TAG_fnc_spawnAI", 2 ];

 

Would this be for each player or just run on the server? I thought 2 in remoteExec was for server only?

Share this post


Link to post
Share on other sites

I missed the addAction at the end of the OP code. Let me make sure I have this right..

  • Player uses F10 to open dialog
  • Player presses button in UI to spawn AI
  • AI spawn on the server
  • AI have event for when killed
  • All clients get addAction on the AI

If all that is correct then something like..
 

Spoiler

description.ext


class CfgFunctions
{
	class god_bombDefuse
	{
		tag = "GOD";
		class god_server
		{
			class spawnAI {};
			class onKilled {};
		};
		class god_client
		{
			class populate {};
			class addDefuseAction {};
			class removeDefuseAction {};
		};
	};
};

initPlayerLocal.sqf


#include "\a3\ui_f\hpp\definedikcodes.inc"

_adminIDs = [ "76561198027698781", "76561198027698781" ];

if (
	hasInterface &&		//Client machine
	{
		isServer ||	//SP
		{ getPlayerUID player in _adminIDs } ||		//Predefined admin
		{ serverCommandAvailable "#exportjipqueue" } ||		//Logged in admin
		{ !isNil { missionNamespace getVariable "BIS_fnc_admin" } && { call BIS_fnc_admin isEqualTo 2 } }	//Logged in admin, A3 version 1.70 maybe?
	}
) then {
	waitUntil { !isNull ( findDisplay 46 ) };
	( findDisplay 46 ) displayAddEventHandler [ "KeyDown", {
		params[  "_display", "_keyCode", "_shft", "_ctr", "_alt"];

		if ( _keyCode isEqualTo DIK_F10 ) then {

			[] spawn GOD_fnc_populate;
		};
	} ];
};

 

Server Functions

 

fn_spawnAI.sqf


/* What ever your current code is */

_grpP = [getmarkerpos "sZoneLocal", EAST, (configFile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call BIS_fnc_spawnGroup;

{
	_x setVariable ["AISpawnTime", time];

	_x setVariable ["AISpawnPos",_cpPos];
	_x setVariable ["LastAIDistanceCheck",time];
	_x addMPEventHandler ["MPKilled",'if (isServer) then {_this call God_fnc_OnKilled;};'];
	
	//every client and JIP, that is removed from JIP queue if the AI is deleted/cleaned up
	[ _x ] remoteExec [ "GOD_fnc_addDefuseAction", [ 0, -2 ] select isDedicated, _x ];
} foreach (units  _grpP  );

fn_onKilled.sqf


params[ "_unit", "_killer", "_instigator" ];

/* What ever your current code is */

//Remove client actions
[ _unit ] remoteExec [ "GOD_fnc_removeDefuseAction", [ 0, -2 ] select isDedicated ];
//Remove addAction from JIP queue
remoteExec [ "", _unit ];

 

Client Functions

 

fn_populate.sqf


/* what ever your gui code is */
//on button press call server function to spawn AI
[] remoteExec [ "GOD_fnc_spawnAI", 2 ];

fn_addDefuseAction.sqf


params[ "_unit" ];

_actionID = _unit addAction [ "<t color='#ff0000'>Defuse The Bomb</t>", God_fnc_actionDefuse, [], 1.5, true, true, "", _condition, 3, false];
_unit setVariable[ "defuseActionID", _actionID ];

fn_removeDefuseAction.sqf


params[ "_unit" ];

_actionID = _unit getVariable[ "defuseActionID", -1 ];
if ( _actionID > -1 ) then {
	_unit removeAction _actionID;
};

Then depending on what GOD_fnc_actionDefuse entails would need to be called on the correct machine/s.

 

Think that works out right, have typed this out twice as forum ate first post :(.

  • Like 2

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

×