Admins able to spawn vehicles

Planek

New Member
Looking through a few script files for missions, I'm wondering if it's possible to add something to a mission file or the server.pbo file that tests to see if a player is an admin then spawns a vehicle if the player presses a certain key.

Something like this only

if(_isAdmin) {
onKeyPress("G") { //or whatever
createVehicle = "UH1H", 10m from me
}
}

I know there are servers that give donors a perk allowing them to receive a bike spawned next to them when they spawn. I'm just wondering how this is done and what files need to be edited to do it.
 
It's not intended to be an "IWin" button because I could easily already win with the control i have over my server. I plan to use it for many other things besides spawning vehicles next to me. I was just using that as an example that I can build on.
 
What other applications?

Spawning vehicles is inherently very difficult because of the amount of cheating that was done. They blow up, don't save and have other kind of restrictions. You need to know how to use mysql and arma together, as for the login scripting. Look up event handlers and login commands, prolly addaction aswell. binding to keys is harder then binding to radio commands, you might want to use a trigger with radio conditions instead.

If you give me a bit more information I might be able to suggest more.
 
spawning a useable Veh is easy but its only temporary and has no eventhandlers, spawning a usable Veh that is handled by hive (update damage, position, gear in database) and is using all eventhandlers (killed, damaged, getin/out) is a bit harder
to add a veh spawn player action use something like this:
Code:
{                 
  _id = player addaction ['<t color="#FF0000">' + "V " + _x + '</t>', "spawn_vehicle.sqf",[_x,player], -7, false, true, "", ""];
  _admin_action_ids = _admin_action_ids + [_id];
} foreach ["UH1H_DZ","Ural_CDF","V3S_Civ","Volha_2_TK_CIV_EP1"]

spawn_vehicle.sqf can look like this:
Code:
_handover = _this select 3; // args from action [class,player]
TriggerVehSpawn = _handover;
publicVariable "TriggerVehSpawn ";  // this triggers the serverside eventhandler

now you need to register the eventhandler
you can do this in mpmission/map/init.sqf in isServer section, can look like this:
Code:
if (isServer) then {
    hiveInUse = true;
    _serverMonitor = [] execVM "\z\addons\dayz_server\system\server_monitor.sqf"; 
    "TriggerVehSpawn" addPublicVariableEventHandler {_id = (_this select 1) execVM "serverspawnVeh.sqf"};
};

now the serverspawnVeh.sqf:
Code:
private["_object","_posiplayer","_class","_dir","_fuel"];
_posiplayer = getPos _this select 1;
_dir =    getDir _this select 1;
_class = _this select 0;
_fuel = 1;
sleep 5; // waiting for player leaves the position (no one likes a veh on his head i think) ;P
_object = createVehicle [_class, _posiplayer, [], 0, "CAN_COLLIDE"];
_object setFuel _fuel;
_object setdir _dir;
 
dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_object];

the sqf that adds the custom player actions you can call in intit.sqf to but in section (!isDedicated) like:
Code:
_loadcustomactions = [] execVM "playercustomactions.sqf";

on my server im checking the uniqueID of the player that loged in that i linked to a 'adminlevel' in a custom database table
you can set admin by checking available commands too:
Code:
_IsAdmin = serverCommandAvailable "#kick";
but there can only one admin loged in at the same time

adding a Veh to Database and make it persistent can look like this :​
(using blisshive extension to execute some custom mysql procedures)​
Code:
private["_class","_pos","_dir","_fuel","_charID","_worldspace","_ownerID","_discription","_worldspace"];
_class = _this select 0;
_pos = _this select 1;;
_dir = _this select 2;
_fuel = 1;
_charID = _this select 3;
_worldspace = [_dir,_pos];
_ownerID = _charID;
_discription = "Spawned by Admin";  // Discription for world_vehicle Table
 
/////Insert Veh into DB/////
//Wait for HIVE to be free
waitUntil{!hiveInUse};
hiveInUse = true;
_key = ["addVeh",[_class, _worldspace, _discription]];
diag_log("LEO: SERVER: Calling blishive: _key: " + str(_key));
_key call leo_hiveWrite;
sleep 0.1;
hiveInUse = false;
 
//////Read Veh from DB///////
//Get Veh page count
waitUntil{!hiveInUse};
hiveInUse = true;
_key = format["Q:%1:call Leo_proc_getVehsPageCount(%2)", (call fnc_instanceName), dayz_instance];
_result = "blisshive" callExtension _key;
_result = call compile _result;
l_pageCount = call compile ((_result select 0) select 0);
sleep 0.5;
hiveInUse = false;
diag_log("Leo: Got " + str(l_pageCount) + " pages of objects...");
 
//Load objects
waitUntil{!hiveInUse};
hiveInUse = true;
l_objList = [];
l_objCount = 0;
//_page = _pageCount;
_key = format["Q:%1:call Leo_proc_getVehs(%2, %3)", (call fnc_instanceName), dayz_instance, l_pageCount];
diag_log("Leo: Server: Load Objects: _key: " + str(_key));
_result = "blisshive" callExtension _key;
_result = call compile _result;
_end = ((count _result) - 1);
l_item = _result select _end;
if (count l_item > 0) then {
    l_objList set [count l_objList, l_item];
    l_objCount = l_objCount + 1;
    //diag_log("DEBUG: Added object " + l_item);
};
sleep 0.5;
hiveInUse = false;
 
//Spawn objects
l_countr = 0;
{
    //Parse individual vehicle row
    l_countr = l_countr + 1;
 
    l_idKey = call compile (_x select 0);
    l_type = _x select 1;
    l_ownerID = _x select 2;
    l_pos = call compile (_x select 3);
    l_dir = (l_pos) select 0;
    l_pos = (l_pos) select 1;
    l_intentory = call compile (_x select 4);
    l_hitPoints = call compile (_x select 5);
    l_fuel = call compile (_x select 6);
    l_damage = call compile (_x select 7);
 
    if (l_damage < 1) then {
 
 
        //Create it
        l_object = createVehicle [l_type, l_pos, [], 0, "CAN_COLLIDE"];
        l_object setVariable ["lastUpdate",time];
        l_object setVariable ["ObjectID", l_idKey, true];
        l_object setVariable ["CharacterID", l_ownerID, true];
        l_object setVariable ["ObjectUID", "0", true];
 
        clearWeaponCargoGlobal  l_object;
        clearMagazineCargoGlobal  l_object;
 
        l_object setdir l_dir;
        l_object setDamage l_damage;
 
        if (l_object isKindOf "AllVehicles") then {
            {
                l_selection = _x select 0;
                l_dam = _x select 1;
                if (l_selection in dayZ_explosiveParts and l_dam > 0.8) then {l_dam = 0.8};
                [l_object,l_selection,l_dam] call object_setFixServer;
            } forEach l_hitpoints;
            l_object setvelocity [0,0,1];
            l_object setFuel l_fuel;
 
            l_object addEventHandler ["HandleDamage", { _this call vehicle_handleDamage }];
            l_object addEventHandler ["Killed", { _this call vehicle_handleKilled }];
            l_object addEventHandler ["GetOut", { _this call vehicle_handleInteract }]; // @Bliss\addons\dayz_server\init\server_functions.sqf  Ln 35
            l_object addEventHandler ["GetIn", { _this call vehicle_handleInteract }];
 
        };
 
        //Monitor the object
        dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,l_object];
        diag_log("Spawned: " + str(l_idKey) + " " + l_type + " dayz_serverObjectMonitor:" + str(dayz_serverObjectMonitor));
    };
// check Veh variables
  _oLastUpD = l_object getVariable ["lastUpdate",0];
  _oID = l_object getVariable ["ObjectID",0];
  _oUID = l_object getVariable ["ObjectUID","0"];
  _oChID = l_object getVariable ["CharacterID",0];
  _oLastDam = l_object getVariable ["lastDamage",0];
  diag_log ("Leo: Server: Spawn Veh:>> l_object: " + str(l_object) + " Type: " + str(typeOf l_object) + " _oLastUpD: " + str(_oLastUpD) + " _oID: " + str(_oID) + " _oUID" + str(_oUID) + " _oChID" + str(_oChID) + " _oLastDam: " + str(_oLastDam));
} forEach l_objList;
 
Thanks for the leolilu, might try some of this out.

I've been wanting AN-2's on the map, but having them save to the hive is a pain as people get them stuck in all kinds of crazy places.

Have you had any issues with vehicles blowing up?

PS: Sorry to partially hi-jack the thread!
 
im using the persistant spawn und have no issues with that
i think the temp spawns can have issues like no damage handler/self repairing, i wasnt testing this much
 
Hello everyone and thank you leolilu for the code examples. As far as i understand it is possible to add custom scripts to missions (in this case chernarus mission file (*.PBO)) by executing them using execVM just like your code does:
Code:
_loadcustomactions = [] execVM "playercustomactions.sqf";
The problem i encountered is that the menu never shows the option "test" when i add the following line of code to "playercustomactions.sqf"
Code:
player addAction ["test", "scripts\myscript.sqf"];
. It seems that my script is never called, although commands like
Code:
player globalChat "TEST"
work (sometimes).
 
Have you tried BIS forums? If you avoid mentioning dayz they are pretty friendly.

Also I deleted my original reply because it wasn't actually what I was trying to say:
Is a script like this in the mission files exploitable easily?
 
Have you tried BIS forums? If you avoid mentioning dayz they are pretty friendly.

No i didn't until now because i was afraid they'll give me an answer like "DayZ related questions belong on the DayZ forums" and then simply close my thread.
 
Hello everyone and thank you leolilu for the code examples. As far as i understand it is possible to add custom scripts to missions (in this case chernarus mission file (*.PBO)) by executing them using execVM just like your code does:
Code:
_loadcustomactions = [] execVM "playercustomactions.sqf";
The problem i encountered is that the menu never shows the option "test" when i add the following line of code to "playercustomactions.sqf"
Code:
player addAction ["test", "scripts\myscript.sqf"];
. It seems that my script is never called, although commands like
Code:
player globalChat "TEST"
work (sometimes).

Hi :)

you need to loop the addaction request coz the scripts in 'init.sqf' are called before any player is in the game
try out this code in you playercustomactions.sqf:
Code:
_test_action_id = -1;
 
while {true} do {
    if (_test_action_id < 0) then {
      _test_action_id = player addAction ["test", "scripts\myscript.sqf"];
    };
    sleep 2;
};
 
If you start the Server + Client with -showScriptErrors , it will be easier to find out what is going wrong.
Sometimes there is only a missing "]",")" or ";" that make you trouble :)
take a look in your serverlog (arma2oaserver.rpt)

/Leo
 
Back
Top