Bliss:Saving Newly Created Vehicles to the DB, almost

Xyberviri

Valued Member!
This thread is out of date and is only valid for DayZ version 1.7.5.1 on Bliss/Reality. Any other versions may not work as expected.
-X
So i have been playing around with this custom procedure i created in mysql so that newly created vehicles will save to my database, however the issue im having at the moment is the stored procedure will crap out the call to mysql.

So basically the below code will save 1 vehicle and the i need to do something to clear the db and let it know that the stored call is done.

here is the code and a test mission in case anyone wants to play with this. The event handlers work and the vehicle saves to the dbase completely, the only issue is it holds on to MySQL after the first run so any subsequent use of this script doesn't work. obviously this is a major error as it can crash the server. im pretty sure it has to do with the fact im using a stored procedure that is basically two queries so i probably screwed that up.

Code:
CREATE DEFINER=`dayz`@`localhost` PROCEDURE `proc_saveVehicle`(IN `p_worldvehicleid` BIGINT(20))[/U][/S][/U][/S]
[S][U]BEGIN[/U][/S]
[S][U]INSERT INTO `instance_vehicle`(`world_vehicle_id`,`last_updated`, `created`) VALUES (p_worldvehicleid,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);[/U][/S]
[S][U]select LAST_INSERT_ID();[/U][/S]
[S][U]END

saveVehicle.sqf
Code:
private ["_targetObj","_targetClass","_targetPos","_saveWorldVehicleID","_instanceVehicleID","_key","_data","_result","_status","_count"];[/U][/S][/U][/S]
[S][U]_targetObj = _this;[/U][/S]
[S][U]_targetClass = typeOf _targetObj;[/U][/S]
[S][U]_targetPos = getPos _targetObj;[/U][/S]
 
[S][U]_saveWorldVehicleID = 0;[/U][/S]
[S][U]_instanceVehicleID = 0;[/U][/S]
 
[S][U]diag_log("xSAVE: Attempting to save "+ str(_targetClass)+" at "+str(_targetPos));[/U][/S]
 
[S][U]//Wait for HIVE to be free[/U][/S]
[S][U]waitUntil{!hiveInUse};[/U][/S]
[S][U]hiveInUse = true;[/U][/S]
[S][U]//Send request[/U][/S]
[S][U]_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '%2' LIMIT 1:[""%1""]:", _targetClass,1];[/U][/S]
[S][U]diag_log ("xSAVE: Query: " + str(_key));[/U][/S]
[S][U]_data = "HiveEXT" callExtension _key;[/U][/S]
[S][U]sleep 0.1;[/U][/S]
[S][U]hiveInUse = false;[/U][/S]
[S][U]//Release HIVE[/U][/S]
[S][U]_result = call compile format ["%1", _data];[/U][/S]
[S][U]diag_log ("xSAVE: STATUS: " + str(_result));[/U][/S]
[S][U]    _status = _result select 0;[/U][/S]
[S][U]    if (_status == "CustomStreamStart") then {[/U][/S]
[S][U]        _count = _result select 1; //Number of Rows[/U][/S]
[S][U]        waitUntil{!hiveInUse};[/U][/S]
[S][U]        hiveInUse = true; [/U][/S]
[S][U]            for "_i" from 1 to _count do {    [/U][/S]
[S][U]            //Loop though the results[/U][/S]
[S][U]                diag_log ("xSAVE: Retreving World Vehicle ID with:  " + str(_key));[/U][/S]
[S][U]                _data = "HiveEXT" callExtension _key;[/U][/S]
[S][U]                _result = call compile format ["%1", _data];[/U][/S]
[S][U]                _saveWorldVehicleID = _result select 0;[/U][/S]
[S][U]            };[/U][/S]
[S][U]            sleep 0.1;[/U][/S]
[S][U]        hiveInUse = false;[/U][/S]
 
[S][U]        diag_log ("xSAVE: Found world_vehicle.id: " + str(_saveWorldVehicleID));[/U][/S]
[S][U]            //Now we have the world vehicle id, we can save this to the database[/U][/S]
[S][U]            if (_saveWorldVehicleID > 0 ) then {[/U][/S]
[S][U]                waitUntil{!hiveInUse};[/U][/S]
[S][U]                hiveInUse = true;[/U][/S]
[S][U]                _key = format["CHILD:999:CALL `proc_saveVehicle` ('?'):[%1]:",_saveWorldVehicleID];[/U][/S]
[S][U]                diag_log ("xSAVE: Attempting to write to hive with:  " + str(_key));[/U][/S]
[S][U]                _data = "HiveEXT" callExtension _key;[/U][/S]
[S][U]                sleep 0.2;        [/U][/S]
[S][U]                hiveInUse = false;[/U][/S]
                       
       
[S][U]                _result = call compile format ["%1", _data];[/U][/S]
[S][U]                diag_log ("xSAVE: STATUS: " + str(_result));[/U][/S]
[S][U]                _status = _result select 0;[/U][/S]
[S][U]                if (_status == "CustomStreamStart") then {[/U][/S]
[S][U]                _count = _result select 1;[/U][/S]
           
[S][U]                    waitUntil{!hiveInUse};[/U][/S]
[S][U]                    hiveInUse = true;[/U][/S]
[S][U]                    for "_i" from 1 to _count do {[/U][/S]
[S][U]                    _data = "HiveEXT" callExtension _key;[/U][/S]
[S][U]                    _result = call compile format ["%1", _data];[/U][/S]
[S][U]                    diag_log ("Vehicle ID Result" + str(_result));[/U][/S]
[S][U]                    _instanceVehicleID = _result select 0;[/U][/S]
[S][U]                    };[/U][/S]
[S][U]                    sleep 0.1;[/U][/S]
[S][U]                    hiveInUse = false;[/U][/S]
[S][U]                };[/U][/S]
 
[S][U]                _targetObj setVariable ["lastUpdate",time];[/U][/S]
[S][U]                _targetObj setVariable ["ObjectID", str(_instanceVehicleID), true];[/U][/S]
[S][U]                _targetObj setVariable ["CharacterID", "0", true];[/U][/S]
[S][U]                _targetObj setVariable ["ObjectUID", "0", true];[/U][/S]
       
[S][U]                _hitpoints = _targetObj call vehicle_getHitpoints;[/U][/S]
[S][U]                _dam = 0.5;[/U][/S]
[S][U]                _targetObj setFuel 0.5;[/U][/S]
[S][U]                {[/U][/S]
[S][U]                    _selection = getText(configFile >> "cfgVehicles" >> typeOf _targetObj >> "HitPoints" >> _x >> "name");[/U][/S]
[S][U]                    [_targetObj,_selection,_dam] call object_setFixServer;[/U][/S]
[S][U]                } forEach _hitpoints;[/U][/S]
[S][U]                _targetObj call fnc_vehicleEventHandler;      [/U][/S]
[S][U]                dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_targetObj];[/U][/S]
[S][U]                [_targetObj,"all"] call server_updateObject;[/U][/S]
[S][U]            };[/U][/S]
[S][U]            //End Save  [/U][/S]
[S][U]    };


I attached the mission file i have been playing around with, it adds a spawn test function that lets you spawn a uh1h anywhere and then trys to add it to the database, it can add the first uh1h but the 2nd just craps it out with a C++/Mysql error...

:(

Code:
2013-01-22 01:22:05 Database: [Error] Error 2014 (Commands out of sync; you can't run this command now) in MySQLQuery SQL: 'select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = 'UH1H_DZ' and world_vehicle.world_id = '1' LIMIT 1'
 

Attachments

  • dayz_999.chernarus.pbo
    57.8 KB · Views: 26
Alright so basically i can't call the stored procedure because its going to crap out the server. so i need to create a normal insert x using child 998 then change my stored procedure line into a select Max(id) where world_vehicle id = the last one inserted...

back on track
 
This allows you to create a vehicle and it takes over the rest adding it to dayz, this requires you to patch your sever to not destroy spawned vehicles, how to set this up is outside the scope of this specific post.

Create a vehicle using what ever scripting method your using, then add the following spawn to it, its best to do this as soon as it is created so the database can also track inventory changes.

Code:
_veh = _type createVehicle _Pos;
_veh spawn server_saveVehicle;

You need to put this in your server_functions.sqf file:

Code:
//Xyberviri Functions
server_saveVehicle =    compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_saveVehicle.sqf"; //Saves _this Vehicle to the instance_vehicle if it has a valid world id.
"dayzSaveVehicle" addPublicVariableEventHandler {_id = (_this select 1) spawn server_saveVehicle};  //This is a event handler to call this function from client side

Save the file as the following: dayz_server.pbo\compile\fnc_saveVehicle.sqf
Code:
private ["_targetObj","_targetClass","_targetPos","_saveWorldVehicleID","_instanceVehicleID","_key","_data","_result","_status","_count"];
_targetObj = _this;
_targetClass = typeOf _targetObj;
_targetPos = getPos _targetObj;
 
_saveWorldVehicleID = 0;
_instanceVehicleID = 0;
 
diag_log("xSAVE: Attempting to save "+ str(_targetClass)+" at "+str(_targetPos));
 
//Wait for HIVE to be free
waitUntil{!hiveInUse};
hiveInUse = true;
//Send request
_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '%2' LIMIT 1:[""%1""]:", _targetClass,1];
diag_log ("xSAVE: Query: " + str(_key));
_data = "HiveEXT" callExtension _key;
sleep 0.1;
hiveInUse = false;
//Release HIVE
_result = call compile format ["%1", _data];
diag_log ("xSAVE: STATUS: " + str(_result));
    _status = _result select 0;
    if (_status == "CustomStreamStart") then {
        _count = _result select 1; //Number of Rows
        waitUntil{!hiveInUse};
        hiveInUse = true;
            for "_i" from 1 to _count do {
            //Loop though the results
                diag_log ("xSAVE: Retreving World Vehicle ID with:  " + str(_key));
                _data = "HiveEXT" callExtension _key;
                _result = call compile format ["%1", _data];
                _saveWorldVehicleID = _result select 0;
            };
            sleep 0.1;
        hiveInUse = false;
 
        diag_log ("xSAVE: Found world_vehicle.id: " + str(_saveWorldVehicleID));
            //Now we have the world vehicle id, we can save this to the database
            if (_saveWorldVehicleID > 0 ) then {
                waitUntil{!hiveInUse};
                hiveInUse = true;
                _key = format["CHILD:999:INSERT INTO `instance_vehicle`(`world_vehicle_id`,`last_updated`, `created`) VALUES ('?','CURRENT_TIMESTAMP','CURRENT_TIMESTAMP'):[%1]:",_saveWorldVehicleID];
                diag_log ("xSAVE: Attempting to write to hive with:  " + str(_key));
                _data = "HiveEXT" callExtension _key;
                _result = call compile format ["%1", _data];
                diag_log ("xSAVE: STATUS: " + str(_result));
                sleep 0.1;
                _key = format["CHILD:999:SELECT `id` FROM `instance_vehicle` WHERE `world_vehicle_id`='?' ORDER BY `id` DESC LIMIT 1:[%1]:",_saveWorldVehicleID];
                _data = "HiveEXT" callExtension _key;
                sleep 0.1;
                hiveInUse = false;
 
                _result = call compile format ["%1", _data];
                diag_log ("xSAVE: STATUS: " + str(_result));
                _status = _result select 0;
                if (_status == "CustomStreamStart") then {
                _count = _result select 1;
   
                    waitUntil{!hiveInUse};
                    hiveInUse = true;
                    for "_i" from 1 to _count do {
                    _data = "HiveEXT" callExtension _key;
                    _result = call compile format ["%1", _data];
                    diag_log ("Vehicle ID Result" + str(_result));
                    _instanceVehicleID = _result select 0;
                    };
                    sleep 0.1;
                    hiveInUse = false;
                };
 
                _targetObj setVariable ["lastUpdate",time];
                _targetObj setVariable ["ObjectID", str(_instanceVehicleID), true];
                _targetObj setVariable ["CharacterID", "0", true];
                _targetObj setVariable ["ObjectUID", "0", true];
 
                _hitpoints = _targetObj call vehicle_getHitpoints;
                _dam = 0.01;
                _targetObj setFuel 1;
                {
                    _selection = getText(configFile >> "cfgVehicles" >> typeOf _targetObj >> "HitPoints" >> _x >> "name");
                    [_targetObj,_selection,_dam] call object_setFixServer;
                } forEach _hitpoints;
                _targetObj call fnc_vehicleEventHandler;
                dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_targetObj];
                [_targetObj,"all"] call server_updateObject;
            };
            //End Save
    };

Ill create a pkg update here in a little bit once its all tested. the 2nd CURRENT_TIMESTAMP doesn't do anything from there for some reason, im thinking the only reason the first does anything is because im calling the server update so that's actually updating the time stamp, so the insert query can probably be smiled down or killed all together.

I will probably set the created date to a static one so that server admins will at least know that vehicle was created though this function.

my next goal it to competently shift over to using this to spawn vehicles with wasteland as the vehicle spawner to see how long it takes to get to 700 vehicles and the performance impact on the server.

currently this code only works on chernarus, if you want to use it on another word you need to change the first _key line to match your world id of your world_vehicle table, right now im too lazy to update this cause im pretty stoked this is working and am testing bugs currently.

Code:
_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '%2' LIMIT 1:[""%1""]:", _targetClass, <WORLDIDGOESHERE >];
 

Attachments

  • dayz_999.chernarus.pbo
    58.3 KB · Views: 50
I was going to change the damage assigned from _dam = 0.5 to _dam = damage _targetObj; however i wasn't sure if that was screwing up the damage handler. so i left i changed it to 0.01 and left it alone at that, i figure its a small price to pay cause those vehicles are spawned bran new anyway, plus thats why i said assign it as soon as possible in case the script you use to spawn it assigns damage in some way
 
Great work Xyberviri, have been following your progress on this. I am a bit stuck though, wonder if you can help me get this going.

I am assuming that we are adding this to the Bliss dayz_server.pbo, as that is the only place I can find the relevant files. The main issue I am having is after compiling it I get these errors in my .rpt file and the first error comes up on the server console. Naturally I can not join the server:
Code:
13:27:34 Warning Message: Script z\addons\dayz_server\init\server_functions.sqf not found
13:27:34 Warning Message: Script z\addons\dayz_server\system\server_monitor.sqf not found
I have found this before when messing with the original dayZ code or Bliss code and trying to re-compile and run.

I did download your .pbo from here and got the same error..
 
It sounds like we need to get your server_code.pbo file repacked, it wont file that file if its unpacked.

these entries should go here in the server_functions.sqf file:
Code:
server_updateNearbyObjects =    compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_updateNearbyObjects.sqf";
spawn_wrecks = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_wrecks.sqf";
spawn_carePackages = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_carePkgs.sqf";
fnc_plyrHit  = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_plyrHit.sqf";
spawn_wrecks = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_wrecks.sqf";
 
server_saveVehicle =    compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_saveVehicle.sqf"; //Saves _this Vehicle to the instance_vehicle if it has a valid world id.
"dayzSaveVehicle" addPublicVariableEventHandler {_id = (_this select 1) spawn server_saveVehicle};  //This is a event handler to call this function from client side
 
//Get instance name (e.g. dayz_1.chernarus)
fnc_instanceName = {

Then you should have this file we created in "dayz_server\compile", then right click on the dayz_server folder and repack it to a pbo file and then restart the server. While your in this file you should modify your server_cleanup.fsm because if you intend to spawn vehicles and save them you still have to modify this file so it wont blow up newly created vehicles.

This is a modified version of that file if you need one to use or reference:
https://docs.google.com/file/d/0By9zTEuk5q1EdU9hVXloUVBTSFE/edit

Now once you put that in there, you can make your vehicle like you normally do via what ever coding method and then just add
Code:
_veh spawn server_saveVehicle;
and it will save it to the instance vehicle table.

make sure to modify the actual script if your playing on a non chernarus map.
 
Well, I've added that to the server I'm working on. So far no crashes, or headaches, but sadly I don't know if it really works because the vehicles keep disappearing after a few seconds.
 
First thank you for your intrests in this script, next the second question i have to ask is, can the vehicle you are tring to save spawn by default on your map, will it eventually spawn given enough chance, If so then the next thing to ask is what island are you on, if your on anything other than chernarus then you need to modify this line of code:

_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '%2' LIMIT 1:[""%1""]:", _targetClass, <WORLDIDGOESHERE >];
changing "<WORLDIDGOESHERE >" to your world id,


when you try to save it there should be some lines that read "xSave" something like this indicates its working:
Code:
20:50:00 "xSAVE: Query: "CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '1' LIMIT 1:["car_sedan"]:""
20:50:00 "HIVE: WRITE: "CHILD:305:271:[0,[9972.44,2208.48,0.117033]]:0.5:""
20:50:00 "WRITE: ["PASS"]"
20:50:00 "HIVE: WRITE: "CHILD:303:271:[[["Binocular"],[1]],[[],[]],[[],[]]]:""
20:50:00 "WRITE: ["PASS"]"
20:50:00 "HIVE: WRITE: "CHILD:306:271:[["glass1",0.5],["glass2",0.5],["glass3",0.5],["glass4",0.5],["wheel_1_1_steering",0.5],["wheel_1_2_steering",0.5],["wheel_2_1_steering",0.5],["wheel_2_2_steering",0.5],["motor",0.5],["sklo predni P",0.5],["sklo predni L",0.5],["karoserie",0.5],["palivo",0.5],["wheel_1_4_steering",0.5],["wheel_2_4_steering",0.5],["wheel_1_3_steering",0.5],["wheel_2_3_steering",0.5]]:0.608467:""
20:50:00 "WRITE: ["PASS"]"
20:50:00 "xSAVE: STATUS: ["CustomStreamStart",1]"
20:50:00 "xSAVE: Retreving World Vehicle ID with:  "CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '1' LIMIT 1:["car_sedan"]:""
20:50:00 "xSAVE: Found world_vehicle.id: 73"
20:50:00 "xSAVE: Attempting to write to hive with:  "CHILD:999:INSERT INTO `instance_vehicle`(`world_vehicle_id`,`last_updated`, `created`) VALUES ('?','CURRENT_TIMESTAMP','CURRENT_TIMESTAMP'):[73]:""
20:50:00 "xSAVE: STATUS: ["CustomStreamStart",0]"
20:50:00 "xSAVE: STATUS: ["CustomStreamStart",1]"
20:50:00 "Vehicle ID Result[272]"

Something like this indicates your trying to save something that is not setup somewhere correctly. either the insert is going to the wrong instance or the vehicle is missing from the world_instance+vehicle table.

Code:
20:50:05 "xSAVE: Query: "CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '1' LIMIT 1:["car_hatchback"]:""
20:50:05 "xSAVE: STATUS: [307]"
20:50:05 Error in expression <status = _result select 0;
if (_status == "CustomStreamStart") then {
_count = >
20:50:05  Error position: <== "CustomStreamStart") then {
_count = >
20:50:05  Error Generic error in expression
20:50:05 File z\addons\dayz_server\compile\fnc_saveVehicle.sqf, line 24


basically the world Id is what i need next to trouble shoot this and then also the instance id, and if you can check you mysql php table, check the vehicle_instance table and see if the default instance id matches the instance id for your map.

sorry for the issues, im still working out all the bugs on this method to make it as easy to use as possible.
 
I found a way out of the vehicle spawn issue. I'm currently testing your script in our server (US936).. I'll keep you updated on how that goes. It's running taviana map
 
the key with this is that the vehicles are already in the world_vehicle and vehicle table and have a matching world id.

im working on revising the script at the moment to get it fully working with some redundancy checks
 
Good work, I hope Bliss is ready for 1.5, I want to update as soon as possible. You just know the database is going to change though :)
 
Good work, I hope Bliss is ready for 1.5, I want to update as soon as possible. You just know the database is going to change though :)

Bliss isn't compatible with 1.5, when it comes out im going to see about what code has changed.
 
Well, no update on the file if it worked or not. The owner changed maps as soon as I implemented it o_O. For the little while it ran, I think it managed to write a Huey and a Little Bird in the database.
 
Updated code:
This can go in the server_monitor.sqf,
Code:
//Xyberviri Functions
server_lastVehicleID = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_lastVehicleID.sqf";    //This gets the last vehicle id that was saved to the hive, this does not wait for a connect so make sure you use it carefully!!!
server_saveVehicle =    compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_saveVehicle.sqf";      //Saves _this Vehicle to the instance_vehicle if it has a valid world id.
"dayzSaveVehicle" addPublicVariableEventHandler {_id = (_this select 1) spawn server_saveVehicle};                  //This is a event handler to call this function from client side

fnc_lastVehicleID.sqf
Code:
private ["_key","_data","_result","_status","_lastInstanceID"];
_lastInstanceID=0;
_key = format["CHILD:999:SELECT `id` FROM `instance_vehicle` WHERE `instance_id`='?' ORDER BY `id` DESC LIMIT 1:[%1]:",dayZ_instance];
_data = "HiveEXT" callExtension _key;             
_result = call compile format ["%1", _data];
_status = _result select 0;
    if (_status == "CustomStreamStart") then {
        _data = "HiveEXT" callExtension _key;
        _result = call compile format ["%1", _data];
        _lastInstanceID = _result select 0;
    };
_lastInstanceID

fnc_saveVehicle.sqf:
Code:
//////////////////////////////////////////////////
// fnc_saveVehicle.sqf                                                  //
// This saves vehicles to the instance_vehicle table      //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
private ["_targetObj","_targetClass","_targetPos","_saveWorldVehicleID","_instanceVehicleID","_key","_data","_result","_status","_count","_lastSavedID"];
_targetObj = _this;
_isVehicle = _this isKindOf "AllVehicles";
_targetClass = typeOf _targetObj;
_targetPos = getPos _targetObj;
 
_saveWorldVehicleID = 0;
_instanceVehicleID = 0;
_lastSavedID = 0;
 
if (!_isVehicle) exitwith {diag_log("xSAVE(0): An Attempt to save a non vehicle object was made, object sent: "+ str(_this)+" class "+str(_targetClass)+" is not type AllVehicles");};
 
//Wait for HIVE to be free
waitUntil{!hiveInUse};
hiveInUse = true;
_lastSavedID = call server_lastVehicleID;
diag_log("xSAVE(0): Attempting to save "+ str(_targetClass)+" at "+str(_targetPos)+", last saved id "+str(_lastSavedID));
//Send request
_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '%2' LIMIT 1:[""%1""]:", _targetClass,1];
//_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '%2' and world_vehicle.world_id = '%1' LIMIT 1;",1,_targetClass];
diag_log ("xSAVE(1): Looking up World_Vehicle.id: " + str(_key));
_data = "HiveEXT" callExtension _key;
_result = call compile format ["%1", _data];
//diag_log ("xSAVE(1): Result: " + str(_result)); 
    _status = _result select 0;
    if (_status == "CustomStreamStart") then {
        _count = _result select 1; //Number of Rows
        diag_log ("xSAVE(2): Receiving Data from Hive, "+str(_count)+" results were sent.");
        //waitUntil{!hiveInUse};
        //hiveInUse = true;     
            for "_i" from 1 to _count do {         
            //Loop though the results
                //diag_log ("xSAVE(2): Retreving World Vehicle ID with:  " + str(_key));
                _data = "HiveEXT" callExtension _key;
                _result = call compile format ["%1", _data];
                _saveWorldVehicleID = _result select 0;
                //diag_log ("xSAVE(2): received:  " + str(_saveWorldVehicleID));
            };
     
        diag_log ("xSAVE(3): Attempting to save with world_vehicle.id: " + str(_saveWorldVehicleID));
            //Now we have the world vehicle id, we can save this to the database
            if (_saveWorldVehicleID > 0 ) then {
                _key = format["CHILD:999:INSERT INTO `instance_vehicle`(`world_vehicle_id`,`last_updated`, `created`,`instance_id`) VALUES ('?','CURRENT_TIMESTAMP','CURRENT_TIMESTAMP','%2'):[%1]:",_saveWorldVehicleID,dayZ_instance];   
                //diag_log ("xSAVE(3): Attempting to write to hive with:  " + str(_key));
                _data = "HiveEXT" callExtension _key;
                _result = call compile format ["%1", _data];
                //diag_log ("xSAVE(3): STATUS: " + str(_result));
 
                _key = format["CHILD:999:SELECT `id` FROM `instance_vehicle` WHERE `world_vehicle_id`='?' ORDER BY `id` DESC LIMIT 1:[%1]:",_saveWorldVehicleID];
                _data = "HiveEXT" callExtension _key;
             
                _result = call compile format ["%1", _data];
                _status = _result select 0;
                //diag_log ("xSAVE(3): Attempting to find vehicle id: " + str(_status));
                if (_status == "CustomStreamStart") then {
                _count = _result select 1;
                 
                    //waitUntil{!hiveInUse};
                    //hiveInUse = true;
                    for "_i" from 1 to _count do {
                    _data = "HiveEXT" callExtension _key;
                    _result = call compile format ["%1", _data];
                    //diag_log ("xSAVE(4): Vehicle ID Result" + str(_result));
                    _instanceVehicleID = _result select 0;
                    };
                 
                    diag_log ("xSAVE(4): Found ID for this object " + str(_instanceVehicleID));
                 
                    if(_lastSavedID == _instanceVehicleID) then {
                        diag_log ("xSAVE(5): WARNING: Object not saved found ID: " + str(_instanceVehicleID)+" matches previously found id "+str(_lastSavedID));
                    }               
                    else {
                        if (_instanceVehicleID > 0) then {
                            diag_log ("xSAVE(5): ObjectID" + str(_instanceVehicleID)+" saved to Dbase successfully.");
                            _targetObj setVariable ["lastUpdate",time];
                            _targetObj setVariable ["ObjectID", str(_instanceVehicleID), true];
                            _targetObj setVariable ["CharacterID", "0", true];
                            _targetObj setVariable ["ObjectUID", "0", true];
                     
                            _hitpoints = _targetObj call vehicle_getHitpoints;
                            _dam = getDammage _targetObj; //pulling existing damaage of vehicle set it before saving it. or apply it individually to each hit point after the eh is set.
                            //_dam = 0.5;
                            //_targetObj setFuel 0.5; //fuel should be set by creation not here.
                            //Loop though all the hit points on the vehicle and apply the damage.
                            {
                            _selection = getText(configFile >> "cfgVehicles" >> typeOf _targetObj >> "HitPoints" >> _x >> "name");
                            [_targetObj,_selection,_dam] call object_setFixServer;
                            } forEach _hitpoints;
                            //Assign eH vehicle.
                            _targetObj call fnc_vehicleEventHandler;           
                            //Add to server object monitor
                            dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_targetObj];
                            //Tell the server to update this now.
                            [_targetObj,"all"] call server_updateObject;
                        };
                    };
                };
            };
        //End Save       
    };
sleep 0.01; 
hiveInUse = false;
 
Here is the rpt log from the server saving some vehicles to the database. If you look you can see that the damage is now checked on the vehicle and its applied to the whole vehicle now. We can see that as soon as the vehicle was saved it started doing udpates with the location, inventory and damage.

Code:
 3:19:51 "xSAVE(0): Attempting to save "hilux1_civil_3_open" at [2411.79,6159.18,0.237976], last saved id 370"
3:19:51 "xSAVE(1): Looking up World_Vehicle.id: "CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '1' LIMIT 1:["hilux1_civil_3_open"]:""
3:19:51 "xSAVE(2): Receiving Data from Hive, 1 results were sent."
3:19:51 "xSAVE(3): Attempting to save with world_vehicle.id: 40"
3:19:51 "xSAVE(4): Found ID for this object 371"
3:19:51 "xSAVE(5): ObjectID371 saved to Dbase successfully."
3:19:51 "HIVE: WRITE: "CHILD:305:371:[2,[2411.79,6159.18,0.13089]]:0.567458:""
3:19:51 "WRITE: ["PASS"]"
3:19:51 "HIVE: WRITE: "CHILD:303:371:[[["Binocular"],[1]],[[],[]],[[],[]]]:""
3:19:51 "WRITE: ["PASS"]"
3:19:51 "HIVE: WRITE: "CHILD:306:371:[["motor",0.0838187],["sklo predni P",0.0838187],["sklo predni L",0.0838187],["karoserie",0.0838187],["palivo",0.0838187],["wheel_1_1_steering",0.0838187],["wheel_2_1_steering",0.0838187],["wheel_1_4_steering",0.0838187],["wheel_2_4_steering",0.0838187],["wheel_1_3_steering",0.0838187],["wheel_2_3_steering",0.0838187],["wheel_1_2_steering",0.0838187],["wheel_2_2_steering",0.0838187],["glass1",0.0838187],["glass2",0.0838187],["glass3",0.0838187],["glass4",0.0838187]]:0.0838187:""
3:19:51 "WRITE: ["PASS"]"
3:19:51 "xSAVE(0): Attempting to save "car_sedan" at [13469.8,5909.53,0.0717983], last saved id 371"
3:19:51 "xSAVE(1): Looking up World_Vehicle.id: "CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '1' LIMIT 1:["car_sedan"]:""
3:19:51 "xSAVE(2): Receiving Data from Hive, 1 results were sent."
3:19:51 "xSAVE(3): Attempting to save with world_vehicle.id: 73"
3:19:51 "xSAVE(4): Found ID for this object 372"
3:19:51 "xSAVE(5): ObjectID372 saved to Dbase successfully."
3:19:51 "HIVE: WRITE: "CHILD:305:372:[0,[13469.8,5909.53,0.0375278]]:0.837119:""
3:19:51 "WRITE: ["PASS"]"
3:19:51 "HIVE: WRITE: "CHILD:303:372:[[[],[]],[[],[]],[[],[]]]:""
3:19:51 "WRITE: ["PASS"]"
3:19:51 "HIVE: WRITE: "CHILD:306:372:[["motor",0.0164926],["sklo predni P",0.0164926],["sklo predni L",0.0164926],["karoserie",0.0164926],["palivo",0.0164926],["wheel_1_1_steering",0.0164926],["wheel_2_1_steering",0.0164926],["wheel_1_4_steering",0.0164926],["wheel_2_4_steering",0.0164926],["wheel_1_3_steering",0.0164926],["wheel_2_3_steering",0.0164926],["wheel_1_2_steering",0.0164926],["wheel_2_2_steering",0.0164926],["glass1",0.0164926],["glass2",0.0164926],["glass3",0.0164926],["glass4",0.0164926]]:0.0164926:""
3:19:51 "WRITE: ["PASS"]"
 
Please help me out, I have managed to get the extra files and edits in by adding them to the package then compiling with Bliss. I have also used your .pbo download.

Everything loads up and I am creating a vehicle with:
Code:
_playerpos = getPos player;
_pos0 = _playerpos select 0;
_pos1 = _playerpos select 1;
_pos2 = _playerpos select 2;
_player =  _this select 3;
_pos0=_pos0+3;
_pos1=_pos1+3;
_newPos = [_pos0,_pos1,_pos2];
_type="UH1H_DZ";
_veh = _type createVehicle _newPos;
_veh spawn server_saveVehicle;
hint format ["Veh Create Script Ran: %1", _veh];
sleep 5;
This works and creates a vehicle and even returns a value for _veh in the hint :
veh_script_result.jpg


veh_script.jpg


Nothing in the log or database though, no errors just the line that the vehicle is being cleaned up ? I have confirmed that the edits and new files are in the .pbo by un-packing it after..

My .pbo is in D:\arma2\@bliss_1.chernarus\addons\dayz_server.pbo.

Am I missing something obvious in the vehicle creation script ? thanks for looking.. I am pulling my hair out here :)
 
Dude im so sorry i got home after dinner and just knocked out until a little while ago, i just need to wait tilll tje wife gets off the pc here in a bit and then i can help out, the issue is you need to get rid of the server_savevehicle and put "dayzsavevehicle = _veh;" and then call "publicvarible "dayzsavevehicle";" which will make the server execute server_savevehicle on the server side on what ever vehicle is in dayzsavevehicle varible
 
Back
Top