Jump to content
Sign in to follow this  
sprags

Dedicated Server Scripting - Onmapsingleclick

Recommended Posts

Hi folks,

I am slowly but surely putting together my own evac/taxi script for use with my clan, and hoping to possibly release it in the future as an addon.

I have studied and learnt a lot by reading through posts made by users on here and other sites, and my scripting has come on tenfold.

Unfortunately, my scripts i have put together won't work on a dedicated server and i'm wondering if some can cast an eye over it and point me in the right direction, i'm literally pulling my hair out trying to get this working, and i presume it is something pretty simple now.

I have a chopper called evac1 and a backpack called radiopack1 with the addactions attached.

	
init.sqf
// define function to move chopper on server
spraggsy_fnc_helimove = { 

private ["_heli","_pos"];

_heli = _this select 0;
_pos = _this select 1;
if (local _heli) then 
{ 
  _heli doMove getpos _pos; 
} 
else 
{ 
 helidomove = _this; publicVariable "helidomove"; 
}; 
}; 

"helidomove" addPublicVariableEventHandler { 
_heli = _this select 1 select 0; 
_pos = _this select 1 select 1; 
if (local _heli) then { _heli domove _pos;}; 

 };

 //[evac1, evacpad] call spraggsy_fnc_helimove;
 //call function with above command

"helimoveonclick" addPublicVariableEventHandler {

Evac1 GlobalChat "We've recieved your coordinates sir, We are dusting off and on route!";
   };
"requestevac" addpublicvariableeventhandler {

evac1 globalChat "Ground Team 1, We have recieved your coordinates, We are dusting off and on route. Hawk 1 Out.";
   };

"seesmoke" addpublicvariableeventhandler {

evac1 globalChat "Ground Team 1, We see your smoke, We're bringing her in!";
   };


"mapclickhint" addPublicVariableEventhandler {
hint parseText format["<t size='1.2' /*font='LucidaConsoleB' color='#ff0000'*/> ClICK ON THE MAP TO RELAY COORDINATES TO THE PILOT </t>"];
};

"landin10" addPublicVariableEventhandler {
evac1 GlobalChat "We are on the ground, 10 seconds till dustoff. Get out now!";
 };

"dustoff" addPublicVariableEventhandler {
evac1 GlobalChat "Ground Team 1, We are dusting off and RTB! Good Luck down there! Hawk 1 out.";
};

"RTB" addPublicVariableEventhandler {
evac1 GlobalChat "Ground Team 1, We are RTB! Good Luck down there! Hawk 1 out.";
};

"popsmoke" addpublicvariableeventhandler {
evac1 globalChat "Ground Team 1, We are at your coordinates, Pop green smoke on your LZ, Over!.";
};

"landed" addpublicvariableeventhandler {
evac1 globalChat "Ground Team 1, We are on the ground, Load up!";
};    
// };

if (!(isNull player)) then 
{    
radio_addactionMP =
{
private["_object","_screenMsg","_scriptToCall"];
_object = _this select 0;
_screenMsg = _this select 1;
_scriptToCall = _this select 2;
_option = _this select 3;

if(isNull _object) exitWith {};
_object addaction [_screenMsg,_scriptToCall,_option];
};

// define all addActions here so they display in multiplayer.
[[radiopack1,("<t color=""#8A3324"">" + ("Call for Evac") + "</t>"),"radio.sqf", 1],"radio_addactionMP",nil,false] spawn BIS_fnc_MP;
[[evac1,("<t color=""#8A3324"">" + ("Return to base") + "</t>"), "radio.sqf", 2],"radio_addactionMP",nil,false] spawn BIS_fnc_MP;     
[[evac1,("<t color=""#3A6629"">" + ("Select Destination") + "</t>"), "radio.sqf", 3],"radio_addactionMP",nil,false] spawn BIS_fnc_MP;
//         radiopack addAction ["Call For Evac", "radio.sqf", 1 ];
//         evac1 addAction ["Return To Base", "radio.sqf", 2 ];
//         evac1 addAction ["Select Destination", "radio.sqf", 3 ]; 
};

radio.sqf

_selection = _this select 3;

switch (_selection) do {
case 1 : { nul =  [evac1,radiopack1] execVM "evac.sqf";
};
case 2 : {  nul =  [evac1] execVM "rtb.sqf";
};
case 3 : {  nul =  [evac1] execVM "destination.sqf";

};
};  

Evac.sqf  - first part only as the rest of the code is a mess

hint "working";


_heli = _this select 0;
_heli setbehaviour "CARELESS";
_heli setSpeedMode "FULL";
//	private ["landpad"];

_heli GlobalChat "Select your destination on the map sir!";
Hint parseText format["<t size='1.2' /*font='LucidaConsoleB' color='#ff0000'*/> ClICK ON THE MAP TO RELAY COORDINATES TO THE PILOT </t>"];
publicVariable "mapclickhint";
////		        
destination = true;
private "_pos";
evacpad = "Land_HelipadEmpty_F" createVehicle (getpos _heli);
["click", "onMapSingleClick", { evacpad setPos _pos;destination = false; }] call BIS_fnc_addStackedEventHandler; 
waitUntil {!destination};
_heli setBehaviour "CARELESS";
_heli setSpeedMode "FULL";
_heli domove getpos evacpad;
_heli GlobalChat "We've recieved your orders sir, We are dusting off and on route!";
[evac1,evacpad] call spraggsy_fnc_helimove;
publicVariable "requestevac";		        

while { ( (alive _heli) && !(unitReady _heli) ) } do
{
sleep 1;
};

Now i know onsinglemapclick is a local command only, but i can't really see why this doesn't broadcast with the above code. The event handler fires, telling me the chopper has recieved orders and is on route but nothing happens. :(

Thanks in advance guys,

Andy

Edited by sprags
Format of script

Share this post


Link to post
Share on other sites

Where is all of this code running? I think this is a locality issue:

if (local _heli) then
{
_heli doMove getpos _pos;
}else{
helidomove = _this; publicVariable "helidomove";
};

"helidomove" addPublicVariableEventHandler
{
_heli = (_this select 1) select 0; //strange you don't have script error here
_pos = (_this select 1) select 1;
if (local _heli) then
{
	_heli domove _pos;
};
};

Also, there is no "player" on dedicated server so this will never run:

if (!(isNull player)) then 

EDIT: and pls use standard formatting practices

Share this post


Link to post
Share on other sites

Apologies for the wrong format when i posted the code. Been a long time since i posted on here and i'm pretty sure it was the old forums last time i did.

Anyways, back on topic.

This code was used to wait until player is synchronised and so that the action would show for everyone on the server.

if (!(isNull player)) then  

Is this not correct?

The idea was to have the helicopter movement handled serverside, but broadcasting the variable "_pos" from the client and getting it to fire both via pveh and function have both not worked.

Its obviously my poor scripting which is leading to this, and i am trying ever so hard to learn but this one hurdle has got me stumped.

All of this code is running on everything via the init.sqf :

if (local _heli) then
{
   _heli doMove getpos _pos;
}else{
   helidomove = _this; publicVariable "helidomove";
};

"helidomove" addPublicVariableEventHandler
{
   _heli = (_this select 1) select 0; //strange you don't have script error here
   _pos = (_this select 1) select 1;
   if (local _heli) then
   {
       _heli domove _pos;
   };
};  

I guess this should only run on the server?

P.S I will try this with the amendment you have added DreadedEntity, to see what result this gives.

Share this post


Link to post
Share on other sites

I think your PVEH's are a little underpowered. When I script for dedicated server, I try to keep as much on the server side as possible. Give me a little while to rework these scripts and see what I come up with

---------- Post added at 15:46 ---------- Previous post was at 14:58 ----------

Okay, so I made a few changes, got rid of some traffic-generating commands and such. Basically, what I've done is instead of making the addActions run with BIS_fnc_MP, they are instead created locally, this will reduce a ton of traffic right at the beginning of the mission, and traffic generated on each JIP. Also, moved PVEH's to a separate script. Also, when a player uses one of those actions, the map should automatically open, and create a blank "onMapSingleClick" event. If the user closes their map without making a choice, the EH will be removed to prevent a buildup.

DO NOTE: I've left the map click event handler's blank since I don't know the workings of your other scripts

Here it is:

init.sqf

if (isDedicated) then
{
[] execVM "initPVs.sqf"; //only server will create PVEH's
//make sure you use publicVariableServer instead of publicVariable, to send traffic directly to the server, further reducing traffic
}else{ //clients create local actions
radiopack1 addAction ["<t color=""#8A3324"">" + ("Call for Evac") + "</t>",
{
	openMap [true, false];
	["callEvac", "onMapSingleClick",
	{

	}] call BIS_fnc_addStackedEventHandler;
	[] spawn
	{
		waitUntil {!visibleMap};
		["callEvac","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
	};
}, nil, 6, false];

evac1 addAction ["<t color=""#8A3324"">" + ("Return to base") + "</t>",
{
	openMap [true, false];
	["returnToBase", "onMapSingleClick",
	{

	}] call BIS_fnc_addStackedEventHandler;
	[] spawn
	{
		waitUntil {!visibleMap};
		["returnToBase","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
	};
}, nil, 6, false];
evac1 addAction ["<t color=""#3A6629"">" + ("Select Destination") + "</t>",
{
	openMap [true, false];
	["selectDesination", "onMapSingleClick",
	{

	}] call BIS_fnc_addStackedEventHandler;
	[] spawn
	{
		waitUntil {!visibleMap};
		["selectDestination","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
	};
}, nil, 6, false];
};

initPVs.sqf

//it's possible to make these PVEH's a lot more powerful by putting real code in them instead of just globalChat's
"helidomove" addPublicVariableEventHandler
{  
_heli = _this select 1 select 0;
_pos = _this select 1 select 1;
if (local _heli) then { _heli domove _pos;};
};
"helimoveonclick" addPublicVariableEventHandler
{
Evac1 GlobalChat "We've recieved your coordinates sir, We are dusting off and on route!"; 
}; 
"requestevac" addpublicvariableeventhandler
{
evac1 globalChat "Ground Team 1, We have recieved your coordinates, We are dusting off and on route. Hawk 1 Out."; 
};
"seesmoke" addpublicvariableeventhandler
{
evac1 globalChat "Ground Team 1, We see your smoke, We're bringing her in!"; 
};     
"mapclickhint" addPublicVariableEventhandler
{
hint parseText format["<t size='1.2' /*font='LucidaConsoleB' color='#ff0000'*/> ClICK ON THE MAP TO RELAY COORDINATES TO THE PILOT </t>"]; 
};

"landin10" addPublicVariableEventhandler
{ 
evac1 GlobalChat "We are on the ground, 10 seconds till dustoff. Get out now!"; 
}; 

"dustoff" addPublicVariableEventhandler
{
evac1 GlobalChat "Ground Team 1, We are dusting off and RTB! Good Luck down there! Hawk 1 out.";
};

"RTB" addPublicVariableEventhandler
{
evac1 GlobalChat "Ground Team 1, We are RTB! Good Luck down there! Hawk 1 out.";
};

"popsmoke" addpublicvariableeventhandler
{
evac1 globalChat "Ground Team 1, We are at your coordinates, Pop green smoke on your LZ, Over!.";
};

"landed" addpublicvariableeventhandler
{
evac1 globalChat "Ground Team 1, We are on the ground, Load up!";
};

Share this post


Link to post
Share on other sites

Damn, that makes my code look puny lol.

I saw these StackedEventHandlers when searching the forums and wiki. They do confuse me ever so slightly.

radiopack1 addAction ["<t color=""#8A3324"">" + ("Call for Evac") + "</t>",
   {
       openMap [true, false];
       ["callEvac", "onMapSingleClick",
       {
       evacpad getpos _pos; nul =  [evacpad] execVM "evac.sqf";  // Would this be the correct way to pass the mapclick position to a script and then use _this select 0 to retrieve the variable and use it in that script?

       }] call BIS_fnc_addStackedEventHandler;
       [] spawn
       {
           waitUntil {!visibleMap};
           ["callEvac","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
       };

These fncs aren't my strongest point, i do understand the code above, just uncertain on passing information through them.

P.S. Thanks a lot Dread for your patience and scripting skills.

I have already learnt a lot.

Edited by sprags
spelling

Share this post


Link to post
Share on other sites

Not quite, you'd need to set the variable first:

radiopack1 addAction ["<t color=""#8A3324"">" + ("Call for Evac") + "</t>",
{
openMap [true, false];
["callEvac", "onMapSingleClick",
{
	evacpad = _pos; //reset variable
	nul = //don't need script handle unless you want to save it somewhere. Handle only required in the editor on unit init field
	evacpad execVM "evac.sqf"; //if it's only 1 variable, you don't need to use an array. This will pass the data to the script as _this
	//inside the script: _this = evacpad //same thing
	//or you could just directly send _pos (it keeps track of where you clicked
	//_pos execVM "evac.sqf"
	openMap false; //be sure to close map after clicking
}] call BIS_fnc_addStackedEventHandler;
[] spawn
{
	waitUntil {!visibleMap};
	["callEvac","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
};
};

Glad to help

Share this post


Link to post
Share on other sites

I'm back and still having a few issues with this :(

Basically, i can call the action now on the dedicated server and the chopper will fly to my chosen position. When it arrives, the crew ask for a smoke signal. I throw a smoke grenade, they see it and land on it. Now this works fine in editor and player hosted server but won't trigger on the dedicated server. I even tried giving it its own PVEH and calling it from another script but it won't work.

Init.sqf 
if (isDedicated) then
{
   [] execVM "initPVs.sqf"; //only server will create PVEH's
   //make sure you use publicVariableServer instead of publicVariable, to send traffic directly to the server, further reducing traffic
}else{ //clients create local actions
   [] execVM "radio.sqf";
   radiopack1 addAction ["<t color=""#8A3324"">" + ("Call for Evac") + "</t>",
   {
       openMap [true, false];
       hint1 = hint parsetext format ["<t size='1.2' color='#CD5C5C'> ESTABLISHING SATELLITE UPLINK </t>"];
       playsound3d ["a3\sounds_f\sfx\uav\UAV_03.wss",radiopack1];
       sleep 1;
       hint parseText format["<t size='1.2' color='#CD5C5C'> ClICK ON THE MAP TO RELAY COORDINATES TO THE PILOT </t>"];
      // publicVariable "mapclickhint";
       evac1 globalChat "Please select a rendevous destination on the map sir.";

       ["callEvac", "onMapSingleClick",
       {
        evacpad = _pos;
        [evac1,evacpad] execVM "evac.sqf";
        private ["_destination"]; 
        _destination =  "Please select a rendevous destination on the map sir.";
        message = _destination;
             publicVariable "message";


       }] call BIS_fnc_addStackedEventHandler;
       [] spawn
       {
           waitUntil {!visibleMap};
           ["callEvac","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
       };
   }, nil, 6, false];

   evac1 addAction ["<t color=""#8A3324"">" + ("Return to base") + "</t>",
   {
       //openMap [true, false];
       evac1 execVM "RTB.sqf";
       ["returnToBase", "onMapSingleClick",
       {

       }] call BIS_fnc_addStackedEventHandler;
       [] spawn
       {
          // waitUntil {!visibleMap};
           ["returnToBase","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
       };
   }, nil, 6, false];
   evac1 addAction ["<t color=""#3A6629"">" + ("Select Destination") + "</t>",
   {
       openMap [true, false];
       ["selectDesination", "onMapSingleClick",
       {

       }] call BIS_fnc_addStackedEventHandler;
       [] spawn
       {
           waitUntil {!visibleMap};
           ["selectDestination","onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
       };
   }, nil, 6, false];
};  

initPVs.sqf
//it's possible to make these PVEH's a lot more powerful by putting real code in them instead of just globalChat's
"helidomove" addPublicVariableEventHandler
{  
   _heli = _this select 1 select 0;
   _pos = _this select 1 select 1;
   if (local _heli) then { _heli domove _pos} else { _heli domove _pos};
};

"heliseesmoke" addPublicVariableEventHandler
{  
   _heli = _this select 1 select 0;
   _pos = _this select 1 select 1;
   if (local _heli) then { _heli domove _pos} else { _heli domove _pos};
};

Evac.sqf
hint "working";

    private ["_evacpad","_onroute","_arrived","_smoke","_landed"];		
   _heli = _this select 0;
   _pos = _this select 1;
   _heli setbehaviour "CARELESS";
   _heli setSpeedMode "FULL";
    _evacpad = "Land_HelipadEmpty_F" createVehicle (getpos _heli);
    _evacpad setpos _pos;
    _heli domove getpos _evacpad;
    helidomove = [_heli,_pos];
    publicVariableserver "helidomove";

    _onroute = "Ground Team 1, We have recieved your coordinates, We are dusting off and on route. Hawk 1 Out.";
    radio = _onroute;
    _heli globalChat _onroute;
    publicVariable "radio";
    while { ( (alive _heli) && !(unitReady _heli) ) } do
    {
    sleep 1;
    };


     _arrived = "Ground Team 1, We are at your coordinates, Pop green smoke on your LZ, Over!.";
     _heli globalChat _arrived;
     radio = _arrived;
     publicVariable "radio";

     waitUntil {(count ( _heli nearObjects ["SmokeshellGreen", 300])) > 0};  
     hint "i detected the smoke";
     _smokeShell = getPos _evacpad nearestObject "SmokeShellGreen";
sleep 2;
     [_heli,_smokeshell] execVM "Landing.sqf";
     sleep 1;
     deletevehicle _evacpad;

Landing.sqf
hint "landing.sqf";
private ["_landpad"];
_heli = _this select 0;
_pos = _this select 1;
_landpad = "Land_HelipadEmpty_F" createVehicle (getpos _pos);
//evacpad setpos (getpos _pos);
sleep 2;
_heli domove getpos _landpad;

heliseesmoke = [_heli,_landpad];
     publicVariableserver "heliseesmoke";

     _smoke = "Ground Team 1, We see your smoke, We're bringing her in!";
     _heli globalChat _smoke;
radio = _smoke;

     publicVariable "radio";
     hint "smoke variable should have fired";

     while { ( (alive _heli) && !(unitReady _heli) ) } do
     {
      sleep 1;
     };

     _heli Land "GET IN";
     waitUntil  { ((getPosATL _heli ) select 2)< 1 };
     _landed = "Ground Team 1, We are on the ground, Load up!";
     _heli GlobalChat _landed;
     radio = _landed;
     publicVariable "radio";
     Hint "this works";
     sleep 2;
     //waituntil {player in _heli};
	deletevehicle _landpad;

_heli domove getpos _landpad;
heliseesmoke = [_heli,_landpad];  // This would appear to be the lines of code where nothing is happening.
publicVariableserver "heliseesmoke";// Any ideas chaps?

Thanks,

Andy

Share this post


Link to post
Share on other sites

Hi again.

The chopper will not move and land on the smokeshell position not matter what i try on dedicated server.

I have change the

 Domove 

commands to waypoints now to try and fix, but still no effect.

Any scripting gurus able to shed some light?

 Evac.Sqf

   private ["_evacpad","_onroute","_arrived","_smoke","_landed"];		
   _heli = _this select 0;
   _pos = _this select 1;
   _heli setbehaviour "CARELESS";
   _heli setSpeedMode "FULL";
    _evacpad = "Land_HelipadEmpty_F" createVehicle (getpos _heli);
    _evacpad setpos _pos;
    _evacheli = group _heli;
    _wprendevous = _evacheli addWaypoint [_evacpad, 10];
    _wprendevous setWaypointType "MOVE"; 
    _wprendevous setWaypointStatements ["true", ""];
   // _heli domove getpos _evacpad;
    helidomove = [_heli,_evacpad];
    publicVariableserver "helidomove";

    _onroute = "Ground Team 1, We have recieved your coordinates, We are dusting off and on route. Hawk 1 Out.";
    radio = _onroute;
    _heli globalChat _onroute;
    publicVariable "radio";

      waitUntil { (currentWaypoint (_wprendevous select 0)) > (_wprendevous select 1) };
      while {(count (waypoints _evacheli)) > 0} do 
      { 
      deleteWaypoint ((waypoints _evacheli) select 0); 
      };
     _arrived = "Ground Team 1, We are at your coordinates, Pop green smoke on your LZ, Over!.";
     _heli globalChat _arrived;
     radio = _arrived;
     publicVariable "radio";

     waitUntil {(count ( _evacpad nearObjects ["SmokeshellGreen", 300])) > 0};  
     hint "i detected the smoke";
     _smokeShell = getPos _evacpad nearestObject "SmokeShellGreen";
sleep 1;
    // [_heli,_smokeshell] execVM "Landing.sqf";
     sleep 1;
    // deletevehicle _evacpad;
_evacpad setpos (getpos _smokeshell);
sleep 1;
//_heli domove getpos evacpad;
   // _wpsmoke = _evacheli addWaypoint [_evacpad, 10];
    //_wpsmoke setWaypointType "MOVE"; 
   // _wpsmoke setWaypointStatements ["true", ""];

//helidomove = [_heli,_evacpad];
   //  publicVariableserver "helidomove";

     _smoke = "Ground Team 1, We see your smoke, We're bringing her in!";
     _heli globalChat _smoke;
radio = _smoke;

     publicVariable "radio";
     hint "smoke variable should have fired";

     _heli Land "GET IN";
     heliland = _heli;
     publicvariableserver "heliland";
      waitUntil  { ((getPosATL _heli ) select 2)< 1 };
     _landed = "Ground Team 1, We are on the ground, Load up!";
     _heli GlobalChat _landed;
     radio = _landed;
     publicVariable "radio";
     Hint "this works";
     sleep 2;
      while {(count (waypoints _evacheli)) > 0} do 
      { 
      deleteWaypoint ((waypoints _evacheli) select 0); 
      };
	deletevehicle _evacpad;

 InitPVs.Sqf  

if (local _heli) then 
   { 
    _evacheli = group _heli; 
    _wpsmoke = _evacheli addWaypoint [_evacpad, 10];
    _wpsmoke setWaypointType "MOVE"; 
    _wpsmoke setWaypointStatements ["true", ""];
   }
   else
   {
    _evacheli = group _heli; 
    _wpsmoke = _evacheli addWaypoint [_evacpad, 10];
    _wpsmoke setWaypointType "MOVE"; 
    _wpsmoke setWaypointStatements ["true", ""];
   };
};

"heliland" addPublicVariableEventHandler
{  
   _heli = _this select 1 select 0;
   if (local _heli) then { _heli Land "GET IN";} else { _heli Land "GET IN";};
};

//    if (local _heli) then 
//    { 
//     _evacheli = group _heli; 
//     _wpsmoke = _evacheli addWaypoint [_evacpad, 10];
//     _wpsmoke setWaypointType "MOVE"; 
//     _wpsmoke setWaypointStatements ["true", ""];
//    }
//    else
//    {
//     _evacheli = group _heli; 
//     _wpsmoke = _evacheli addWaypoint [_evacpad, 10];
//     _wpsmoke setWaypointType "MOVE"; 
//     _wpsmoke setWaypointStatements ["true", ""];
//    };

Im soo stuck, its beyond funny and i am damn sure i am missing something or so close that this just needs a slight tweak.

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  

×