Jump to content

Admin tools add-on - Spawning vehicles to hive, with key in belt


PetuniaEpoch

Recommended Posts

EDIT: Updates - Thanks to ToejaM, WattE and MatthewK for spotting & highlighting issues!

Hi all.
 
This little add-on is for people that use blue phoenix's admin tools. However I'm sure if you know what you're doing, you can add this to other admin tools :)
 
Credit to Epoch for their brilliant mod, and snippets of this coding (used some of the trader scripts for this), and also inspired by what I saw of the blur tool, and how they work. This may not be coded as cleanly as it could, as I am not an SQL coder as such, I just like to figure out how things work and adapt them... Still, it works for me and I thought maybe others would find it useful so I shared :)
 
This add-on will spawn a vehicle, write it to the database, and pop the right key in your toolbelt. You MUST have room in your toolbelt though!
 
In file: AdminToolsMain.sqf
 
Find the part of the admin tools that has your main admin tools menu, should be inside one of the admin levels (mod/admin/superadmin etc)
 
Like this:
 
 

if ((getPlayerUID player) in ["xxxxxxxx","xxxxxxxx","xxxxxxxx"]) then { // super admins
adminmenu =
[
["",true],
["Scripts Menu", [2], "#USER:ToolsMenu", -5, [["expression", ""]], "1", "1"],

 
 
Add this at the end, ensuring you change the number in the square brackets ([2] in the example above), to be the next in the sequence:
 

["Spawn Vehicles With Keys", [8], "#USER:HiveVehicles", -5, [["expression", ""]], "1", "1"],

 
So for example:
 
 

if ((getPlayerUID player) in ["xxxxxxxx","xxxxxxxx","xxxxxxxx"]) then { // super admins
adminmenu =
[
["",true],
["Scripts Menu", [2], "#USER:ToolsMenu", -5, [["expression", ""]], "1", "1"],
["Spawn Vehicles With Keys", [3], "#USER:HiveVehicles", -5, [["expression", ""]], "1", "1"],

 
NOTICE how the [8] became [3], as it was after the 'Scripts Menu' item that was [2] :)
 
Next, towards the end of your admintoolsmain.sqf, but above 'showCommandingMenu "#USER:adminmenu";' entry add this:
 
 
 

// Adding hive vehicles - check the sqf file and change classnames as desired
HiveVehicles =
[
["",true],
["MI17", [2],  "", -5, [["expression", format[_EXECscript5,"hiveMI17civ.sqf"]]], "1", "1"],
["UH60", [3],  "", -5, [["expression", format[_EXECscript5,"hiveUH60.sqf"]]], "1", "1"],
["HMMV m2", [4],  "", -5, [["expression", format[_EXECscript5,"hiveHMMVm2.sqf"]]], "1", "1"],
["UH1Y", [5],  "", -5, [["expression", format[_EXECscript5,"hiveUH1Y.sqf"]]], "1", "1"],
["lil bird", [6],  "", -5, [["expression", format[_EXECscript5,"hivebird.sqf"]]], "1", "1"],
["Chinook", [7],  "", -5, [["expression", format[_EXECscript5,"hivechinook.sqf"]]], "1", "1"],
["Armed SUV", [8],  "", -5, [["expression", format[_EXECscript5,"hiveArmedSUV.sqf"]]], "1", "1"],
["Charcoal SUV", [9],  "", -5, [["expression", format[_EXECscript5,"hiveCharcoalSUV.sqf"]]], "1", "1"],
["", [-1], "", -5, [["expression", ""]], "1", "0"],
["Next page", [12], "#USER:HiveVehicles2", -5, [["expression", ""]], "1", "1"],
["Exit", [13], "", -3, [["expression", ""]], "1", "1"]
];
 
HiveVehicles2 =
[
["",true],
["Osprey", [2],  "", -5, [["expression", format[_EXECscript5,"hivemv22.sqf"]]], "1", "1"],
["", [-1], "", -5, [["expression", ""]], "1", "0"],
["Next page", [12], "#USER:HiveVehicles2", -5, [["expression", ""]], "1", "1"],
["Exit", [13], "", -3, [["expression", ""]], "1", "1"]
];
 

 
Then, in the folder 'admintools\vehicles\' you need the sqf file for each of the above vehicles.
 
I'll paste the code for the last one (hivemv22.sqf) below. You just change the filename and classname for each :)
 


private ["_veh","_location","_isOk","_vehtospawn","_part_in","_qty_in","_qty","_obj","_objectID","_objectUID","_started","_finished","_animState","_isMedic","_dir","_removed","_keyColor","_keyNumber","_keySelected","_isKeyOK","_config","_textPartIn","_textPartOut"];
 
_vehtospawn = "MV22_DZ"; 
 _charID = dayz_characterID;
 _dir = getdir vehicle player;
 _pos = getPos vehicle player;
 _pos = [(_pos select 0)+8*sin(_dir),(_pos select 1)+8*cos(_dir),0];
 _worldspace = [_dir,_pos];
 
cutText ["Starting Spawn, stand still to complete spawn.", "PLAIN DOWN"];
 
// First select key color
_keyColor = ["Green","Red","Blue","Yellow","Black"] call BIS_fnc_selectRandom;
 
// then select number from 1 - 2500
_keyNumber = (floor(random 2500)) + 1;
 
// Combine to key (eg.ItemKeyYellow2494) classname
_keySelected = format[("ItemKey%1%2"),_keyColor,_keyNumber]; 
 
_isKeyOK =  isClass(configFile >> "CfgWeapons" >> _keySelected);
 
_config = _keySelected;
_isOk = [player,_config] call BIS_fnc_invAdd;
waitUntil {!isNil "_isOk"};
if (_isOk and _isKeyOK) then {
 
_removed = ([player,_part_in,_qty_in] call BIS_fnc_invRemove);
_dir = round(random 360);

 
// CHANGE the classname below to match your vehicle (MV22_DZ) - Kudos to WaTTe for this tweak!
_location = position player findEmptyPosition [0,20,"MV22_DZ"];
 
//place vehicle spawn marker (local)
_veh = createVehicle ["Sign_arrow_down_large_EP1", _location, [], 0, "CAN_COLLIDE"];
 
_location = (getPosATL _veh);
 
PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,_keySelected];
publicVariableServer  "PVDZE_veh_Publish2";
player reveal _veh;
 
cutText [format[("Spawned a vehicle, key added to toolbelt."),_qty_in,_textPartIn,_textPartOut], "PLAIN DOWN"];
 
} else {
cutText ["You do not have enough room on your toolbelt.", "PLAIN DOWN"];
};
 
 


 
You NEED to be in the open for this to work!
 
I hope this works for you guys, it works for me!
 
I'm off out now, but will check tomorrow to see if anyone has any questions :D
 
Sorry if the instructions are not very good! This is my first attempt at a tut!
 
Mike.

Link to comment
Share on other sites

What purpose does this have?  Why would you need to do this?

A player crashed his heli the other day due to a change i'd made in the weather module, it turned pea soup foggy in under a second and he hit a hill. With this script I'm able to give him his vehicle back, without having to leave the game, open a browser, browse to phpmyadmin, locate his position, and so on :)

Link to comment
Share on other sites

Instead of having multiple files for each vehicle, just have one file that takes a variable instead:

 

Replace _vehtospawn = "MV22_DZ"; with _vehtospawn = _this select 0; and then use this menu code instead:
 

AddVehicles = 
[
	["Add Vehicle",true],
	
["SUV", [2], "", -5, [["expression", '["ArmoredSUV_PMC_DZE"] execVM "custom\addvehicle.sqf"']], "1", "1"],
["UH 1H", [3], "", -5, [["expression", '["UH1H_DZE"] execVM "custom\addvehicle.sqf"']], "1", "1"],
["Skoda", [4], "", -5, [["expression", '["Skoda"] execVM "custom\addvehicle.sqf"']], "1", "1"],
["Humvee", [5], "", -5, [["expression", '["HMMWV_DZ"] execVM "custom\addvehicle.sqf"']], "1", "1"],
["Motorbike", [6], "", -5, [["expression", '["Old_moto_TK_Civ_EP1"] execVM "custom\addvehicle.sqf"']], "1", "1"],
		["", [-1], "", -5, [["expression", ""]], "1", "0"],
			["Exit", [13], "", -3, [["expression", ""]], "1", "1"]
];

showCommandingMenu "#USER:AddVehicles"; 

Then there's no need for a seperate file per vehicle... Hope that makes sense.

Link to comment
Share on other sites

This is the edited version I use on my server which works perfectly with my menu change suggestion.

You only need this one file, the _vehtospawn = _this select 0; line takes the name of the vehicle from the variable passed to it from the menu system a few posts up that I posted :)
 

private ["_worldspace","_charID","_veh","_location","_isOk","_vehtospawn","_part_in","_qty_in","_qty","_obj","_objectID","_objectUID","_started","_finished","_animState","_isMedic","_dir","_helipad","_removed","_keyColor","_keyNumber","_keySelected","_isKeyOK","_config","_textPartIn","_textPartOut"];
 _vehtospawn = _this select 0; 
 _activatingPlayer = player;
 _charID = dayz_characterID;
 _dir = getdir vehicle player;
 _pos = getPos vehicle player;
 _pos = [(_pos select 0)+8*sin(_dir),(_pos select 1)+8*cos(_dir),0];
 _worldspace = [_dir,_pos];
 
cutText ["Starting Spawn, stand still to complete spawn.", "PLAIN DOWN"];
 
// First select key color
_keyColor = ["Green","Red","Blue","Yellow","Black"] call BIS_fnc_selectRandom;
 
// then select number from 1 - 2500
_keyNumber = (floor(random 2500)) + 1;
 
// Combine to key (eg.ItemKeyYellow2494) classname
_keySelected = format[("ItemKey%1%2"),_keyColor,_keyNumber]; 
 
_isKeyOK =  isClass(configFile >> "CfgWeapons" >> _keySelected);
 
_config = _keySelected;
_isOk = [player,_config] call BIS_fnc_invAdd;
waitUntil {!isNil "_isOk"};
if (_isOk and _isKeyOK) then {
 
_removed = ([player,_part_in,_qty_in] call BIS_fnc_invRemove);
_dir = round(random 360);
 
_helipad = nearestObjects [player, ["HeliHCivil","HeliHempty"], 100];
if(count _helipad > 0) then {
	_location = (getPosATL (_helipad select 0));
} else {
	_location = [(position player),0,20,1,0,2000,0] call BIS_fnc_findSafePos;
};
 
//place vehicle spawn marker (local)
_veh = createVehicle ["Sign_arrow_down_large_EP1", _location, [], 0, "CAN_COLLIDE"];
 
_location = (getPosATL _veh);
 
PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,_keySelected,_activatingPlayer];
publicVariableServer  "PVDZE_veh_Publish2";
player reveal _veh;
 
cutText [format[("Spawned a vehicle, key added to toolbelt."),_qty_in,_textPartIn,_textPartOut], "PLAIN DOWN"];
 
} else {
cutText ["You do not have enough room on your toolbelt.", "PLAIN DOWN"];
};
Link to comment
Share on other sites

Sorry - been busy with work so now had time to reply

 

the _heli is a throwback from one of the sources of the script (traders files from client side pbo!) Sorry about that - hey, it's not the cleanest script, I know :D

 

Thanks for the suggested tweaks! It's great you did that as I only have basic knowledge of SQF, so getting this to work was pretty tough for me (works perfect how I have it, but do have more sqf files than I need! (one for each vehicle in the spawn list, lol).

 

Really appreciate your tweaks tho! Thanks :)

 

 

What was this for ? 

 

_helipad = nearestObjects [player, ["HeliHCivil","HeliHempty"], 100];

 

I know what it supposed to be for, but why is it in your code if you're not using it ? 

Link to comment
Share on other sites

As Heyward said - replacing vehicles due to glitches is the main reason.

 

However we are also going to use it on ours to hand out a prize at some weekend server events etc :)

 

Mainly it's glitch fixing though - I got tired of going to traders to buy replacements and such like. This way:

 

1) It's quicker & easier to fix glitches - which means

 

2) It's easier to recruit trusted players to help out with some BASIC admin duties 

 

Stuff like that really.

 

 

What purpose does this have?  Why would you need to do this?

Link to comment
Share on other sites

You have an error in the private array at the top,

 

replace it with this:

private ["_veh","_location","_isOk","_vehtospawn","_part_in","_qty_in","_qty","_obj","_objectID","_objectUID","_started","_finished","_animState","_isMedic","_dir","_helipad","_removed","_keyColor","_keyNumber","_keySelected","_isKeyOK","_config","_textPartIn","_textPartOut"];
"_config","","_textPartIn"

That is where the error is :)

 

It doesnt seem to cause a problem spawning the vehicles though.

Link to comment
Share on other sites

Any idea how to remove key section? If I want to spawn not locked vehicles in area where are less vehicles

 

 

 UNTESTED

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,_keySelected,_activatingPlayer];

to 

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,0,_activatingPlayer];

I changed the _keySelected to 0  ... If I got that wrong , somebody correct me now please. 

Of course, you'll need to clean up the rest of the code to remove unwanted function calls etc... 

Link to comment
Share on other sites

hi,

i modified the script a little because spawning didnt work in small areas in woods or cities

so i did this:

remove:

    _location = [(position player),0,20,1,0,2000,0] call BIS_fnc_findSafePos;

add:

_location = position player findEmptyPosition [0,20,"UAZ_RU"];

20 is the radius around the player where he looks for a free spot, at the end write the vehicle classname, he specifically checks if there is enough space for the vehicle that you want to spawn!

 

regards waTTe

Link to comment
Share on other sites

  • 2 weeks later...

Hey ToejaM! - Thanks for the bugfix! Laziness on my part not checking the private variables list :D Cheers - good catch :) I'll update the OP now.

 

You have an error in the private array at the top,

 

replace it with this:

private ["_veh","_location","_isOk","_vehtospawn","_part_in","_qty_in","_qty","_obj","_objectID","_objectUID","_started","_finished","_animState","_isMedic","_dir","_helipad","_removed","_keyColor","_keyNumber","_keySelected","_isKeyOK","_config","_textPartIn","_textPartOut"];
"_config","","_textPartIn"
That is where the error is :)

 

It doesnt seem to cause a problem spawning the vehicles though.

 

MatthewK - Nice! Thanks, I'll test that myself! Have you had a chance to try it? 

UNTESTED

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,_keySelected,_activatingPlayer];
to 

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,0,_activatingPlayer];
I changed the _keySelected to 0  ... If I got that wrong , somebody correct me now please. 

Of course, you'll need to clean up the rest of the code to remove unwanted function calls etc...

 

WaTTe - Perfect! I'll update the OP now! Thanks :D

hi,

i modified the script a little because spawning didnt work in small areas in woods or cities

so i did this:

remove:

    _location = [(position player),0,20,1,0,2000,0] call BIS_fnc_findSafePos;
add:

_location = position player findEmptyPosition [0,20,"UAZ_RU"];
20 is the radius around the player where he looks for a free spot, at the end write the vehicle classname, he specifically checks if there is enough space for the vehicle that you want to spawn!

 

regards waTTe

 

Hey KamikazeXeX, glad you find it useful :D

Credits to OP for this, such an amazingly handy script! Added it into my Epoch Panthera server and working great, i now have admin apache

Link to comment
Share on other sites

hey there, an even better option would be:

_location = position player findEmptyPosition [0,20,_vehtospawn];

since you wouldnt have to modifiy the line for each vehicle ...

Link to comment
Share on other sites

  • 2 weeks later...

you could combine this script with this one ... theres a bug in this i never had time to fix tho, but you could use this to select wich vehicle you want instead of having a script for each type of vehicle.

 

what this script does, is that it pulls all vehicles (you defined) from the config, then filters the ones you dont want  and finally shows you a list to choose from

 

http://pastebin.com/hF1t8pQ1

 

the bug is that it will spawn multiple vehicles if list is aborted with no selection and new vehicle is selected and spawned after, depending on how many times you aborted, it will spawn that amount ... pretty sure it wont be hard to fix tho

 

this is not my work tho (i belive hangeder made this?), its just something i have used and is posting

Link to comment
Share on other sites

 UNTESTED

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,_keySelected,_activatingPlayer];

to 

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,false,0,_activatingPlayer];

I changed the _keySelected to 0  ... If I got that wrong , somebody correct me now please. 

Of course, you'll need to clean up the rest of the code to remove unwanted function calls etc... 

 

This seems to be the correct syntax for no key:

 

PVDZE_veh_Publish2 = [_veh,[_dir,_location],_vehtospawn,true,0,player];

 

(or for your script, the last variable could also be _activatingPlayer...)

 

On a separate note, do we really need ALL those private variables? Like "_animState" and "_isMedic", for example?  There seems to be a lot of unused variables (and some miscellaneous unused code in yours and the original post... like "_removed = ([player,_part_in,_qty_in] call BIS_fnc_invRemove);"? ).

 

Thanks,

GT

Link to comment
Share on other sites

you could combine this script with this one ... theres a bug in this i never had time to fix tho, but you could use this to select wich vehicle you want instead of having a script for each type of vehicle.

 

what this script does, is that it pulls all vehicles (you defined) from the config, then filters the ones you dont want  and finally shows you a list to choose from

 

http://pastebin.com/hF1t8pQ1

 

the bug is that it will spawn multiple vehicles if list is aborted with no selection and new vehicle is selected and spawned after, depending on how many times you aborted, it will spawn that amount ... pretty sure it wont be hard to fix tho

 

this is not my work tho (i belive hangeder made this?), its just something i have used and is posting

 

Maybe setting the variable "vhnlist" to Nil at the beginning will stop the extra vehicles on abort?

 

I'll give it a shot, nice script.

 

GT

Link to comment
Share on other sites

I've gotten this working with Phoenix tools (including creating the dynamic list of vehicles so you don't have to hardcode any of them), but still haven't figured out two things... the duping issues when you exit out of the menu without selecting something or hitting the exit option, and for some reason when I spawn a vehicle without a key, it kills my ability to use traders.  When I log out and log back in, I can use them until I enter the vehicle that I spawned.  Once I do that, my trader menu won't work again.  If I restart the server, the vehicle is where I left it, and I can enter it and use the trader as normal. So, it seems like it's not making it into the database fully until restart?  I'll upload my code for you to check out in separate posts since it's quite a bit of code.  It is very cool though to be able to generate a full list of all vehicles on the fly and be able to spawn them with or without keys.  Only glitches at this point are those stated above.

Link to comment
Share on other sites

Here's the code for my menu:

// Adding temporary vehicles 
DynamicVehicles =
[
["",true],
		["Get Temp Vehicle List", [2], "", -5, [["expression", format[_EXECscript5,"spawntempvehicle.sqf"]]], "1", "1"],
		["Get UnKeyed Vehicle List", [3], "", -5, [["expression", format[_EXECscript5,"spawnunkeyedvehicle.sqf"]]], "1", "1"],
		["Get Keyed Vehicle List", [4], "", -5, [["expression", format[_EXECscript5,"spawnkeyedvehicle.sqf"]]], "1", "1"],
		["", [-1], "", -5, [["expression", ""]], "1", "0"],
				["Exit", [13], "", -3, [["expression", ""]], "1", "1"]
];

 this is the code I use to create the list... the only difference in this for each of the spawn files is the name of the "add" file I use.  I'll upload each of those individually.

#define KINDOF_ARRAY(a,b) [##a,##b] call {_veh = _this select 0;_types = _this select 1;_res = false; {if (_veh isKindOf _x) exitwith { _res = true };}forEach _types;_res}

_n2sh = 10;
_n2c = "Select Temp Vehicle:";
exitscript = true;
selecteditem = "";
shnext = false;
vhnlist = Nil;
_veh = "";

if (isNil "vhnlist") then {
        vhnlist = [];
        _kindOf = ["Tracked","Wheeled","Air","Ship","Car","Truck","Motorcycle"];
        _filter = ["BIS_Steerable_Parachute","ParachuteBase","Steerable_Parachute_EP1","pook_H13_Base"];
        _cfgvehicles = configFile >> "cfgVehicles";
        titleText ["Generating Vehicle List... Please Wait...","PLAIN DOWN"];
        for "_i" from 0 to (count _cfgvehicles)-1 do {
                        _vehicle = _cfgvehicles select _i;
                        if (isClass _vehicle) then {
                                _veh_type = configName(_vehicle);
                                if ((getNumber(_vehicle >> "scope")==2) and (getText(_vehicle >> "picture")!="") and (KINDOF_ARRAY(_veh_type,_kindOf)) and !(KINDOF_ARRAY(_veh_type,_filter))) then {
                                vhnlist set [count vhnlist,_veh_type];
                        };
                };
        };
        titleText ["List is ready...","PLAIN DOWN"];titleFadeOut 5;
};
 
shnext = false;
 
shnmenu = {
        _pmenu = [["",true],[_n2c, [-1], "", -5, [["expression", ""]], "1", "0"]];
        for "_i" from (_this select 0) to (_this select 1) do {
                _arr = [format['%1',vhnlist select (_i)], [_i - (_this select 0) + 2],  "", -5, [["expression", format["selecteditem = vhnlist select %1;",_i]]], "1", "1"];
                _pmenu set [_i+2, _arr];
        };
        _pmenu set [(_this select 1)+2, ["", [-1], "", -5, [["expression", ""]], "1", "0"]];
        if (count vhnlist >  (_this select 1)) then {
                _pmenu set [(_this select 1)+3, ["Next", [12], "", -5, [["expression", "shnext = true;"]], "1", "1"]];
        } else {
                _pmenu set [(_this select 1)+3, ["", [-1], "", -5, [["expression", ""]], "1", "0"]];
        };
        _pmenu set [(_this select 1)+4, ["Exit", [13], "", -5, [["expression", "selecteditem = 'exitscript';"]], "1", "1"]];
        showCommandingMenu "#USER:_pmenu";
};
 
_j=0;
if (_n2sh>9) then {_n2sh=10;
};
 
while {selecteditem==""} do {
        [_j,(_j+_n2sh) min (count vhnlist)] call shnmenu;
        _j=_j+_n2sh;
        WaitUntil {
                selecteditem!="" or shnext
        };
        shnext = false;
};
 
 
 
 
if (selecteditem != "exitscript" and selecteditem != "") then {
        [selecteditem] execVM "admintools\Vehicles\addtempvehicle.sqf";
};

all the "add" files in next post...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...