Vehicles Spawns / Cleanup?

clifdayz

Well-Known Member
I wondered a while ago about how to properly create loadouts based on humanity. The problem is that in the server code server_playerLogin saves the inventory/backpack but doesn't have access to humanity. Server_playersetup has humanity, but no access to inventory/backpack.

My workarouns was to base loadout on skin, which is not perfect, but took people a while to notice. lol.

Anyway, I got some inspiration from the HeroPerks code here: http://epochmod.com/forum/index.php?/topic/11874-release-hero-perks-epoch-pre-configured/

It spawns a box and/or vehicle for heroes.
I'm having a had time with the vehicle spawns - I drive away and eventually - boom - and I'm dead. The original code looked incomplete, so I lifted some from DZMS, but still having the same issue - boom. Did I miss something obvious?

Also, here's a secondary thought - could I attach a handler to the vehicle so that only the player that it spawned with could be the driver? This would prevent "hero-vehicle-death-spamming" I'm thinking the axebus code that ejects you from the seat, assuming I can attach an arbitrary variable to the vehicle to compare player name or ID or something. On my list to check out.

Code:
        _vehClass = _vehList call BIS_fnc_selectRandom;
        _vehicle = createVehicle [_vehClass,[(_coords select 0) - 4, (_coords select 1) + 4,0],[], 0, "CAN_COLLIDE"];
        _objectID = str(round(random 999999));
        _vehicle setVariable ["ObjectID", _objectID, true];
        _vehicle setVariable ["ObjectUID", _objectID, true];

        _ranFuel = random 1;
        if (_ranFuel < .25) then {_ranFuel = .25;};
        _vehicle setFuel _ranFuel;
        _vehicle setvelocity [0,0,1];
        _vehicle setDir (round(random 360));
       
        //_vehicle setVariable ["Mission",1,true];
        dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _vehicle];

        _vehicle setVehicleLock "UNLOCKED";
 
in the server cleanup scripts, it deletes all the vehicles that shouldnt be on the map. see the line commented out in your code? //_vehicle setVariable ["Mission",1,true];
in the cleanup it checks if the variable "mission" is true and if so, then it doesnt delete the object. See step 5 here. Depending on which mod/version you are using, that code could be moved elsewhere.
 
Looks like this is now in sched_safetyVehicle.sqf
Code:
sched_safetyVehicle = {
    {
        if (vehicle _x != _x && !(vehicle _x in dayz_serverObjectMonitor) && (typeOf vehicle _x) != "ParachuteWest") then {
            diag_log [ __FILE__, "KILLING A HACKER", name _x, " IN ", typeOf vehicle _x ];
            (vehicle _x) setDamage 1;
            _x setDamage 1;
        };
    } forEach allUnits;

    objNull
};

I can certainly modify that but the DZMS code i lifted calls this line so I should be covered.

Code:
 dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _vehicle];

Maybe I can't call that from the mission? argh dayz.
I'll have to go with the workaround I guess.
 
check your logs. if its in fact the scheduler killing the hacker (you) then there will be a log message saying "killing a hacker". If not, then its some other cleanup script ..
 
I did and its definitely "KILLING A HACKER".

My next thought was maybe its being called wrong. I had it in the !isDedicated and out. When out, I get a syntax error on the first line of code in loadout.sqf that doesn't make sense. When in, I don't get the error, but neither work in regard to the vehicles.

in init.sqf - is it related to where the code is placed and/or how it is called?

Code:
if (!isDedicated) then {
[OTHER STUFF]
herospawn = compile preprocessFileLineNumbers "loadouts\loadout.sqf";
waitUntil {!isNil ("PVDZ_plr_LoginRecord")};
// supposed to be the value _isNew from server_playerlogin.sqf
//if (PVCDZ_plr_Login select 5) then
//{
    waitUntil {!isNil ("dayz_serverObjectMonitor")}; // Added this while testing. doesn't help
    player spawn herospawn;
//};
 
Last edited:
Looks like it works, but my OCD doesn't allow me to not understand why the other method doesn't. Interestingly, you've had this discussion before: http://opendayz.net/threads/mission-spawned-vehicles-and-1-8-3.21315/

I generally understand the API, but its the framework and how to execute things that I am still trying to get. The DZAI/DZMS code is called in server_monitor.sqf. map files are added in server_functions.sqf.

[] call compile preprocessFileLineNumbers "\z\addons\dayz_server\DZAI\init\dzai_initserver.sqf";

[] ExecVM "\z\addons\dayz_server\DZMS\DZMSInit.sqf";

Should this loadout code go into the server side in serverplayersetup.sqf, which is where the final login is done??
It seem logical, but then how do I call it? I've seen 3 methods already (call compile, ExecVM, spawn).

Can you POINT me in the right direction?
 
dayz framework is like a snake, hidden in a can of worms, dropped into a rats nest ... very confusing on what calls what, when where and why.


call compile takes the passed code and and executes it. the file its called from does not continue, it waits until the called code is finished. imagine the code is inserted inline where the call statement is.
execvm and spawn both execute the code in a new thread so the calling script continues and may finish before the new thread.
assume you have this code which will loop forever adding to count.
Code:
while (true) do (
count = count + 1
)
in your init.sqf,file as your server starts, if you use call the init.sqf will wait until the call returns ...,which is never, so your init.sqf will never complete and your server will never load. in initialization files as you mention, call makes sure the file is completed before moving on to the next one. ..,and makes use of the return value if needed

spawn and execvm start the code in a new thread and your calling file continues .
spawn executes a block of code, while execvm executes an sqf file.
you cannot do this:
execvm { hint "this wont work"}
but,you can do this
spawn { hint "this WILL work"}

so there you go
only use call if you need to use the return value in the calling script or make sure one thing is completed before continuing on ...,such as init files
use spawn if you are using a block of code
use execvm if you are using a sqf file.
 
very helpful as always. my programming skills are very rusty.
While I'd like to move this to the server side, its working well, except for one error in the RPT that I can't figure out for the life of me:
Code:
8:35:15 Error in expression <"ItemSodaMzly","ItemSodaRabbit"];


if (_humanity < -2000) then {
_backpackList>
8:35:15   Error position: <_humanity < -2000) then {
_backpackList>
8:35:15   Error Undefined variable in expression: _humanity
8:35:15 File mpmissions\dayz_1337.Chernarus\loadouts\loadout.sqf, line 37

Calls from init.sqf
Code:
    player_loadout = compile preprocessFileLineNumbers "loadouts\loadout.sqf";

    player spawn player_loadout;

Top of loadouts.sqf
I've tried various things, using player instead of _player=this; I've tried declaring _humanity as private or not. I tried making the long lists on one line or multiple lines.
Code:
private ["_isHero", "_foodList","_drinkList","_backpackList","_pistolList","_riflelist","_meleeList","_extraMagsList","_extraWeaponsList","_msg", "_vehList", "_vehClass","_ammo","_rifle","_pistol","_vehicle","_objectID","_box", "_melee"];
_player = _this;

_humanity = _player getVariable ["humanity",0];

        _backpackList = [];
        _pistolList = [];
        _riflelist = [];
        _meleeList = [];
      
        _extraMagsList = [];
        _extraWeaponsList = [];
      
        _foodCount = 0;
        _drinkCount = 0;
      
//        _msg = "";
        _vehList = [];

_foodList = ["FoodNutmix","FoodCanBakedBeans","FoodCanSardines","FoodCanFrankBeans","FoodCanPasta","FoodCanBadguy","FoodCanBoneboy","FoodCanCorn","FoodCanCurgon",
"FoodCanDemon","FoodCanFraggleos","FoodCanBeef","FoodCanHerpy","FoodCanDerpy","FoodCanOrlok","FoodCanPowell","FoodCanTylers","FoodCanUnlabeled","FoodPistachio",
"FoodChipsSulahoops","FoodChipsMysticales","FoodCandyAnders","FoodCandyLegacys","FoodCandyMintception","FoodCanRusStew","FoodCanRusPork","FoodCanRusPeas","FoodCanRusMilk",
"FoodCanRusCorn","FoodCakeCremeCakeClean"];

_drinkList = ["ItemWaterBottleBoiled","ItemWaterbottle","ItemSodaLirik","ItemSodaPeppsy","ItemSodaMtngreen","ItemSodaR4z0r","ItemSodaClays","ItemSodaSmasht","ItemSodaDrwaste",
"ItemSodaLemonade","ItemSodaLvg","ItemSodaMzly","ItemSodaRabbit"];

    // BANDIT
if (_humanity < -2000) then {
        _backpackList = [];
        _pistolList = [];
        _riflelist = [];
        _meleeList = ["MeleeBaseBallBatNails", "MeleeBaseBallBatBarbed","MeleeBaseBallBat"];
      
        _extraMagsList = [];
        _extraWeaponsList = ["ItemWatch"];

        _foodCount = 0;
        _drinkCount = 0;
      
        _msg = "You are a BANDIT.";
        if (_humanity < -25000) then {
            _backpackList = ["DZ_Assault_Pack_EP1","DZ_ALICE_Pack_EP1"];
            _pistolList = ["PDW_DZ", "Makarov_DZ"];
            _riflelist = ["Bizon_SD_DZ","AKM_DZ"];
            _foodCount = 2;
            _drinkCount = 2;
            _msg = "You are a DEDICATED BANDIT.";
        };
      
    };

[AND MORE]
 
its undefined. the private keyword sets the variable scope to that codeblock. so it just removes the chance of having a variable have been defined as something else already in another file. think of it as clearing the variable value.
your issue is that the code that defines _humanity is failing ... hence its not defined as any value. in this case:
_humanity = _player getVariable ["humanity",0];
since you are setting the default as 0 and _humanity is not set to that, then the _player object must be null.
if the script is client side then,just use player instead,of _player = _this
 
I think I remembered what the error with your vehicle exploding is.
dayz_serverObjectMonitor ... after you add the vehicle to this array you have to use publicvariable to send the array to the server ...
 
I also think this is the wait in init.sqf:

Code:
    waitUntil {!isNil ("PVDZ_plr_LoginRecord")};
When I tried to put the code into the server side (80% successful), I noticed that even after server_playerSetup.sqf, all of the player object was still not setup (location/worldspace) for example. PVDZ_plr_LoginRecord looks to be set in the 3rd and final part of login.

If I was just spawning blindly, it wouldn't matter server/mission, but I have the box delete when the player gets 5 away from it. I could probably rediscover the crate with nearestobjects and do the same, but i'd still have code in both places anyway. I do check for objects near the player before spawning to prevent hero spamming.

Now I just have to spawn these only after you die AND attach a handler to the vehicle so maybe only the hero/owner can be in the drivers seat.
 
maybe that would all make sense if you posted the code and what its supposed to do.
Dont know what you mean about "hero spamming" unless its from a bandits automatic rifle :p. But no, seriously, I have no idea what you are doing with all this stuff.
 
I am spawning a crate + vehicle, so hero-spamming meant someone abusing it by spawning, getting killed, respawning with more gear, etc.
 
Last edited:
i understand ... maybe. i believe you are overthinking this. i can fool with this at home in an hour or so.
what i dont understand is why you are calling the same code from both the client init.sqf and the server? everything you need for this is client side ... unless i am missing something.

... in an hour or two ...
 
Damn, I edited but you had read it. I don't call both, I had been working one and then the other. I think I have it just about complete. Hope you see this, I have other questions.
 
Latest looks like its working but I haven't 100% tested all situations yet:

init.sqf
Code:
//---------------------------------------------------------------
// SKIGOGGLES - LOADOUT   
    player_loadout = compile preprocessFileLineNumbers "loadouts\mloadout.sqf";
//---------------------------------------------------------------

if (!isDedicated) then {
    waitUntil {!isNil ("PVDZ_plr_LoginRecord")};
//    if (PVCDZ_plr_Login select 4) then {
        [player, position player] spawn player_loadout;
//    };

mloadout.sqf (on mission side) - it just looks for the box and deletes when the player moves away.
http://pastebin.com/1D1qQRBQ

server_playerSetup.sqf
Code:
// SKIGOGGLES - LOADOUT
[_playerObj, (_worldspace select 1)] execVM "\z\addons\dayz_server\loadouts\loadout.sqf";
// SKIGOGGLES


loadout.sqf (server side) all the setup and spawning. Also attach the type of Hero/bandit/survivor to the player object so I can display on the mission side so I don't have to check humanity again (and maintain 2 sets of code).
http://pastebin.com/WDBc7SNw
 
Back
Top