willithappen 194 Posted January 31, 2016 Hello, I am trying to make a MHQ script, firstly I am trying to have a marker that updates when the vehicle moves. Now, i understand this is more advanced than you may think it needs to but, I want it to work with an infinite amount of MHQ's so new ones can be spawned in via the vehicle spawner I use aswell as if they are spawned via other scripts hence the script searching for the below vehicle and then setting it up. I have tried have the marker create and have the name of the marker be the name of the vehicle HOWEVER I get a type object expected string error. I also am unsure of how I can then make the marker update on the vehicle that was assigned. EDIT: I have sorted the issue [sort of] with making the marker name be the name of the vehicle so it can be used over and over without defining a name of the marker myself, however, the script isn't repeating itself for some reason and Isn't adding a marker to all vehicles, it only does so for the first vehicle that is spawned. while {true} do { sleep 1; { if ((typeOf _x) in ["rhsusf_M1083A1P2_B_M2_d_MHQ_fmtv_usarmy"]) then { if (!(_x getVariable ["isSetupMHQ", false])) then { _x setVariable ["isSetupMHQ", true]; _x addaction ["<t color=""#1a1aff"">" +"Gear Menu", "Roles\Open.sqf"]; _vehnameformarker = vehicleVarname _x; _markerstr = createMarker [_vehnameformarker, _x]; _markerstr setMarkerShape "ICON"; _markerstr setMarkerType "mil_arrow2"; _markerstr setMarkerText "Mobile HQ"; while {true} do { // Update Markerpos to vehicle every x seconds }; }; }; } forEach vehicles; }; Share this post Link to post Share on other sites
Larrow 2822 Posted January 31, 2016 //initServer.sqf MHQ_updatePeriod = 1; //time in seconds between marker updates fnc_addMHQ = { params[ "_veh", [ "_text", "Mobile HQ" ], [ "_icon", "mil_arrow2" ] ]; //If we are adding the first MHQ initialise marker array if ( isNil "MHQ_markers" ) then { MHQ_markers = []; }; //Setup marker _markerName = [ ( str _veh splitString ":" ) select 0, vehicleVarName _veh ] select ( vehicleVarName _veh != "" ); _marker = createMarker [ _markerName, getPos _veh ]; _marker setMarkerShape "ICON"; _marker setMarkerType _icon; _marker setMarkerText _text; //Add vehicle action for all clients and JIP _JIP = [ "ADD", _veh ] remoteExec [ "fnc_MHQAction", 0, true ]; //Add marker to the update array _nul = MHQ_markers pushBack [ _veh, _marker, _JIP ]; //Start update loop if it has not been started if ( isNil "MHQ_update" ) then { MHQ_update = [] spawn { while { true } do { { _x params[ "_veh", "_marker", "_JIP", "_rem" ]; //If the marker has not been marked for removeall //and the vehicle is valid if ( isNil "_rem" && { !isNull _veh } ) then { //update marker _marker setMarkerPos getPos _veh; }else{ //Otherwise remove marker deleteMarker _marker; //Remove JIP action remoteExec [ "", _JIP ]; //Remove action from clients [ "REM", _veh ] remoteExec [ "fnc_MHQAction", 0 ]; //Flag marker for removeall at end of loop MHQ_markers set [ _forEachIndex, -1 ]; }; }forEach MHQ_markers; //Remove all flagged markers MHQ_markers = MHQ_markers - [ -1 ]; //If no markers left exit loop if ( count MHQ_markers isEqualTo 0 ) exitWith { MHQ_update = nil; }; sleep MHQ_updatePeriod; }; }; }; }; fnc_removeMHQ = { params[ "_removeVeh" ]; { _x params [ "_veh", "_marker", "_JIP" ]; if ( _veh isEqualTo _removeVeh ) exitWith { //Mark vehicle for removeall MHQ_markers set [ _forEachIndex, [ _veh, _marker, _JIP, -1 ] ]; }; }forEach MHQ_markers; }; //initPlayerLocal.sqf fnc_MHQAction = { params[ "_state", "_veh", "_action" ]; switch ( _state ) do { case "ADD" : { _veh setVariable [ "MHQ_ID", _veh addAction ["<t color=""#1a1aff"">" +"Gear Menu", "Roles\Open.sqf"] ]; }; case "REM" : { if !( isNull _veh ) then { _veh removeAction ( _veh getVariable "MHQ_ID" ); }; }; }; };And then when ever you create a vehicle call the server function .... [myVehicle] call fnc_addMHQand if you need to remove it [myVehicle] call fnc_removeMHQThink that works out right. Have not put it through much testing though 1 Share this post Link to post Share on other sites
willithappen 194 Posted January 31, 2016 Appreciate it larrow, works very well and when spawning with the vehicle spawner it works perfectly. Share this post Link to post Share on other sites
Guest Posted February 1, 2016 Or client sided with map opening EH. + Low usage of ressources (only when map is active), Quick pos update without server lag. - Need to setup it for each player, Need to find a Way for GPS support Share this post Link to post Share on other sites
willithappen 194 Posted February 1, 2016 Or client sided with map opening EH. + Low usage of ressources (only when map is active), Quick pos update without server lag. - Need to setup it for each player, Need to find a Way for GPS support Only problem with the above is I plan on using it not just for markers but for teleporting to and from them to base. And The amount of MHQ's active at once isn't really the pure reason for doing the way above, its more the fact that due to having a vehicle spawner, I needed them to work with any vehicle of certain types aswell as for after the persistent database I am using reloads, it won't save the object's name. Share this post Link to post Share on other sites
kbbw123 115 Posted February 1, 2016 I advise you to make them local markers as they wil work for everyone and not really the server. now the server has to update it every second and distribute it. My mission dev team and I usually make things like vehicle markers and playermarkers local in order to save some performance on the server Share this post Link to post Share on other sites
willithappen 194 Posted February 1, 2016 Larrow, First of all deepest apologies for all the questions Im trying to populate a combobox using the example you made on this post: https://forums.bistudio.com/topic/156858-dialogs-rsc-listbox-rsc-combo-box/ Using the comboA example [First time using combobox's, I use list box's for several things and they seem very similar"] I am trying to have all of the markers that are created show up in the combobox. Even if populating the combobox worked, I am unsure as to how to then run the teleport script with the marker name as the name of the destination in _nameofmarkerhere/ These are the pieces of code I currently have WH_MHQControls.sqf [test.sqf in above example] disableSerialization; _comboMHQ = 21002; //store display, passed from onLoad _display = _this select 0; //Add to our lb and combo lists { _index = lbAdd [_comboMHQ, _x]; } forEach ["ONE","TWO","THREE"]; //set an event to fire when a selection is made in comboA (_display displayCtrl _comboMHQ) ctrlAddEventHandler ["LBSelChanged","_this execVM 'WH_MHQPicked.sqf'"]; WH_MHQMenu.hpp [description.ext, but used in a .hpp] class WH_MHQCombo { movingEnable = 1; idd = 10001; onLoad = "_this ExecVM 'WH_MHQControls.sqf'"; class controlsBackground { controls[]= { MHQ_Combo, MHQ_Accept, MHQ_Cancel }; class MHQ_Combo: RscCombo { idc = 21002; x = 0.375; y = 0.4; w = 0.225; h = 0.04; colorSelect[] = {0,0,1,1}; rowHeight = 0.01; }; class MHQ_Accept: RscButtonMenuOK { x = 0.5; y = 0.36; w = 0.1; h = 0.04; }; class MHQ_Cancel: RscButtonMenuCancel { x = 0.375; y = 0.36; w = 0.125; h = 0.04; }; }; }; //TP_to.sqf // Get the destination. _dest = (_this select 3) select 0; // Get a random direction _dir = random 359; player SetPos [(getMarkerPos _dest select 0)-8*sin(_dir),(getMarkerPos _dest select 1)-8*cos(_dir)]; //_x addAction ["Teleport - HQ","TP_To.sqf",["_nameofmarkerhere"]]; Share this post Link to post Share on other sites
Larrow 2822 Posted February 1, 2016 Heres a quick rewrite to make it handle client side.Description.ext class CfgFunctions { class MHQ { tag = "LARs"; class MHQ { file = "functions"; class addMHQ {}; class removeMHQ {}; class clientAddMHQ {}; class clientRemoveMHQ {}; }; }; }; functions/fn_addMHQ.sqf //[ [ veh, text, icon ], west ] call LARs_fnc_addMHQ; //[ [ veh ], west ] call LARs_fnc_addMHQ; if !( isServer ) exitWith { _this remoteExec [ "LARs_fnc_addMHQ", 2 ]; }; params[ "_details", [ "_side", 0 ] ]; if ( isNil "MHQS" ) then { MHQS = []; }; _JIP_ID = _details remoteExec [ "LARs_fnc_clientAddMHQ", _side, true ]; _nul = MHQS pushBack [ _details, _side, _JIP_ID ]; Added ability to specify the side as well so its only sent to the clients of that specific side.functions/fn_removeMHQ.sqf if !( isServer ) exitWith { _this remoteExec [ "LARs_fnc_removeMHQ", 2 ]; }; params[ "_removeVeh" ]; { _x params[ "_details", "_side", "_JIP_ID" ]; _details params [ "_veh" ]; if ( _veh isEqualTo _removeVeh ) exitWith { _veh remoteExec [ "LARs_fnc_clientRemoveMHQ", _side ]; MHQS set [ _forEachIndex, -1 ]; remoteExec [ "", _JIP_ID ]; }; }forEach MHQS; MHQS = MHQS - [ -1 ]; if ( count MHQS isEqualTo 0 ) then { MHQS = nil; }; functions/fn_clientAddMHQ.sqf MHQ_updatePeriod = 1; params[ "_veh", [ "_text", "Mobile HQ" ], [ "_icon", "mil_arrow2" ] ]; //If we are adding the first MHQ initialise marker array if ( isNil "MHQ_markers" ) then { MHQ_markers = []; }; //Setup marker _markerName = [ ( str _veh splitString ":" ) select 0, vehicleVarName _veh ] select ( vehicleVarName _veh != "" ); _marker = createMarkerLocal [ _markerName, getPos _veh ]; _marker setMarkerShapeLocal "ICON"; _marker setMarkerTypeLocal _icon; _marker setMarkerTextLocal _text; //Add vehicle action _MHQ_ID = _veh addAction ["<t color=""#1a1aff"">" +"Gear Menu", "Roles\Open.sqf"]; //Add marker to the update array _nul = MHQ_markers pushBack [ _veh, _marker, _MHQ_ID ]; //Start update loop if it has not been started if ( isNil "MHQ_update" ) then { MHQ_update = [] spawn { while { true } do { waitUntil{ visibleMap || visibleGPS }; { _x params[ "_veh", "_marker", "_MHQ_ID", "_rem" ]; //If the marker has not been marked for removeall //and the vehicle is valid if ( isNil "_rem" && { !isNull _veh } ) then { //update marker _marker setMarkerPosLocal getPos _veh; }else{ //Otherwise remove marker deleteMarkerLocal _marker; //Remove action if !( isNull _veh ) then { _veh removeAction _MHQ_ID; }; //Flag marker for removeall at end of loop MHQ_markers set [ _forEachIndex, -1 ]; }; }forEach MHQ_markers; //Remove all flagged markers MHQ_markers = MHQ_markers - [ -1 ]; //If no markers left exit loop if ( count MHQ_markers isEqualTo 0 ) exitWith { MHQ_update = nil; }; sleep MHQ_updatePeriod; }; }; }; functions/fn_clientRemoveMHQ.sqf params[ "_removeVeh" ]; { _x params [ "_veh", "_marker", "_MHQ_ID" ]; if ( _veh isEqualTo _removeVeh ) exitWith { //Mark vehicle for removeall MHQ_markers set [ _forEachIndex, [ _veh, _marker, _MHQ_ID, -1 ] ]; }; }forEach MHQ_markers; Only a quick rewrite and put through very little testing but think should be good to go. Share this post Link to post Share on other sites
willithappen 194 Posted February 1, 2016 Hey larrow, have converted all code to above, works fine, still having issues with teleporting to/listing all the markers that exist. Tried using forEach [MHQ_markers]; AND TRIED forEach [MHQS]; Share this post Link to post Share on other sites
Larrow 2822 Posted February 1, 2016 Heres a quick test mission using the the new code and UI. Also added a small check to both addMHQ and removeMHQ just to make sure they are run on the server so as not to break functionality if run on the wrong machine. 1 Share this post Link to post Share on other sites
willithappen 194 Posted February 2, 2016 Hey there larrow, works perfectly, just made a loop in my initplayerserver to make it run on all vehicles so after my persistence script reloads it will run on those vehicles. Many, many, many thanks for the test mission, I learnt a few things about having the accept/ok button work with a selection which is very useful. Share this post Link to post Share on other sites