Take ownership of a tent

NeverUsedID

Well-Known Member
##### EDIT ####

I have created a script where you can take the ownership of every tent you find.
Tents you own dont get deleted from the cleanupscripts and you can repack every tent including tents from other survivors.

Look at Post #19 for a dirty tutorial. Will make a better one if i have more time.
If you have any questions just ask.

######## Edit

Hello,

i would like to make a script to take ownershhip of a tent, if the former owner is dead.

Iam rather new to dayzscripting.

Iam at the point where the "take Ownership" pops up if iam near a tent from a dead survivor.

this is the code:


Code:
//take Ownership tent
    if(cursorTarget isKindOf "TentStorage" and _canDo and _ownerID != dayz_characterID) then {
        if ((s_player_takeOwnership < 0) and (player distance cursorTarget < 3)) then {
            s_player_takeOwnership = player addAction [("<t color=""#FF0000"">" + ("Take        Ownership") + "</t>"), "fixes\takeOwnership.sqf",cursorTarget, 1, false, true, "",""];
          };
    } else {
        player removeAction s_player_takeOwnership;
        s_player_takeOwnership = -1;
        };

Now i want to update the owner of this tent to my own ownerid.

i tried some things like for the :
_obj = _this;
_obj setVariable ["characterID",dayz_characterID,true];
but as you see, iam not sure what iam doing here :)

As a result i want the possibility to pack the tent and i dont want that the tent i deleted after 7 days of not using it.
I use the blissdatabase. If someone has any hint for me where i can look for the solution i would be very happy :)
 
nope, iam still stuck with the _obj setVariable ["characterID",dayz_characterID,true]; code.

Dont know how to change the ownerid in the database. I need to to change the ownerid in instance_deployable.

I think setVariable is the right way, but maybe it only works after createVehicle. but then, iam just to nooby to code that.

if i need createvehicle. i need to delete the old tent before, but i realy dont have any idea how to spawn the items in it again. So i hope that there will come a "master of Arma2 coding"-guy and give me a hint how to take ownership :D
 
Maybe the take clothes script would be a startingpoint:

Code:
// Created by [GEEK SQUAD]Churchie
    // Contributors to getting it working are:| cyrq | Manatee Hunter | Deasil | OnlyblackSurvivor | Thank you!
    player removeAction s_clothes;
    s_clothes = -1;
    private["_body","_result"];
        _body = _this select 3;
        _model = typeOf _body;
    if( _model in ["Sniper1_DZ","Camo1_DZ"] ) then { _model = "Skin_" + _model;
        _result = [player,_model] call BIS_fnc_invAdd;
    if (_result) then { player playActionNow "PutDown";
    private["_name","_method","_methodStr"];
        _name = _body getVariable["bodyName","unknown"];
        _method = _body getVariable["deathType","unknown"];
        _methodStr = localize format ["str_death_%1",_method];
        _class = "Survivor2_DZ";
        _position = getPosATL _body;
        _dir = getDir _body;
        _currentAnim = animationState
        _body; private ["_weapons","_magazines","_primweapon","_secweapon"];
        _weapons = weapons _body;
        _primweapon = primaryWeapon
        _body; _secweapon = secondaryWeapon _body;
    if(!(_primweapon in _weapons) && _primweapon != "") then { _weapons = _weapons + [_primweapon]; };
    if(!(_secweapon in _weapons) && _secweapon != "") then { _weapons = _weapons + [_secweapon]; };
        _magazines = magazines _body;
    private ["_newBackpackType","_backpackWpn","_backpackMag"]; dayz_myBackpack = unitBackpack _body;
        _newBackpackType = (typeOf dayz_myBackpack);
    if(_newBackpackType != "") then { _backpackWpn = getWeaponCargo unitBackpack _body;
        _backpackMag = getMagazineCargo unitBackpack _body; };
        _currentWpn = currentWeapon _body;
        _muzzles = getArray(configFile >> "cfgWeapons" >> _currentWpn >> "muzzles");
    if (count _muzzles > 1) then { _currentWpn = currentMuzzle _body; };
            diag_log "Attempting to switch model";
            diag_log str(_weapons);
            diag_log str(_magazines);
            diag_log (str(_backpackWpn));
            diag_log (str(_backpackMag));
        _body setPosATL dayz_spawnPos;
        _oldUnit = _body;
        _group = createGroup west;
        _newUnit = _group createUnit [_class,dayz_spawnPos,[],0,"NONE"];
        _newUnit setPosATL _position;
        _newUnit setDir _dir; {_newUnit removeMagazine _x;} forEach magazines _newUnit;
        removeAllWeapons _newUnit; {
    if (typeName _x == "ARRAY") then {_newUnit addMagazine [_x select 0,_x select 1]
        } else { _newUnit addMagazine _x };
        } forEach _magazines; { _newUnit addWeapon _x; } forEach _weapons;
    if(str(_weapons) != str(weapons _newUnit)) then { { _weapons = _weapons - [_x];
        } forEach (weapons _newUnit); {
        _newUnit addWeapon _x;
        } forEach _weapons; };
    if(_primweapon != (primaryWeapon _newUnit)) then { _newUnit addWeapon _primweapon; };
    if(_secweapon != (secondaryWeapon _newUnit) && _secweapon != "") then { _newUnit addWeapon _secweapon; };
    if (!isNil "_newBackpackType") then {
    if (_newBackpackType != "") then { _newUnit addBackpack _newBackpackType;
        _oldBackpack = dayz_myBackpack; dayz_myBackpack = unitBackpack _newUnit; _backpackWpnTypes = [];
        _backpackWpnQtys = [];
    if (count _backpackWpn > 0) then { _backpackWpnTypes = _backpackWpn select 0;
        _backpackWpnQtys = _backpackWpn select 1; };
        _countr = 0; { dayz_myBackpack addWeaponCargoGlobal [_x,(_backpackWpnQtys select _countr)];
        _countr = _countr + 1;
        } forEach _backpackWpnTypes;
        _backpackmagTypes = [];
        _backpackmagQtys = [];
    if (count _backpackmag > 0) then { _backpackmagTypes =
        _backpackMag select 0;
        _backpackmagQtys = _backpackMag select 1; };
        _countr = 0; { dayz_myBackpack addmagazineCargoGlobal [_x,(_backpackmagQtys select _countr)];
        _countr = _countr + 1;
        } forEach _backpackmagTypes; }; };
            diag_log "Taking Clothes. Equipment:";
            diag_log str(weapons _newUnit); diag_log str(magazines _newUnit);
            diag_log str(getWeaponCargo unitBackpack _newUnit);
            diag_log str(getMagazineCargo unitBackpack _newUnit);
        removeAllWeapons _oldUnit; {_oldUnit removeMagazine _x;
        } forEach magazines _oldUnit; deleteVehicle _oldUnit;
        _newUnit setDamage 1;
        _newUnit setVariable["bodyName",_name,true];
        _newUnit setVariable["deathType",_method,true];
        } else {
            cutText ["You need a free slot to take clothing.", "PLAIN DOWN"];
        };
    };

looks like this script is spawning a new survivor without clothes at the same position. Will need to understand the code :)
 
Thanks for the Link, that would be a Solution. But i See one Problem: as this Script is pulled serverside, all tents will be updated, not only the tents that a player want to stay. So the server will never delete tents from database and i will get 1000 of tents over Time.

Maybe i change the stript to Check if there is toilet paper in the tent and only if its there the ownerid will be updated :)
 
Okay, have got it working. Its so easy, but as iam a scripting noob iam happy that ive got it :)

all you need is your mission.pbo.

create a folder called custom and place the takeOwnerShip.sqf there

takeOwnerShip.sqf
Code:
private["_obj"];
_obj = _this select 3;
_obj setVariable ["characterID",dayz_characterID,true];

and in your fn_selfAction.sqf right after

Code:
//Packing my tent
    if(cursorTarget isKindOf "TentStorage" and _canDo and _ownerID == dayz_characterID) then {
        if ((s_player_packtent < 0) and (player distance cursorTarget < 3)) then {
            s_player_packtent = player addAction [localize "str_actions_self_07", "\z\addons\dayz_code\actions\tent_pack.sqf",cursorTarget, 0, false, true, "",""];
        };
    } else {
        player removeAction s_player_packtent;
        s_player_packtent = -1;
        };


insert:

Code:
//##################rafael take Ownership tent
    if(cursorTarget isKindOf "TentStorage" and _canDo and _ownerID != dayz_characterID) then {
        if ((s_player_takeOwnership < 0) and (player distance cursorTarget < 3)) then {
            s_player_takeOwnership = player addAction [("<t color=""#FF0000"">" + ("Take Ownership") + "</t>"), "custom\takeOwnership.sqf",cursorTarget, 1, false, true, "",""];
                };
    } else {
        player removeAction s_player_takeOwnership;
        s_player_takeOwnership = -1;
        };
    //#########################

and after

Code:
player removeAction s_player_packtent;
    s_player_packtent = -1;

insert:

Code:
//######### rafael TakeOwership
        player removeAction s_player_takeOwnership;
    s_player_takeOwnership = -1;
    //####################

In game you will get "takeOwnership" as option near a tent from a dead player.

But be warned, iam a noob and dont have tested it very much.
 
this works but its for any tent if player is alive or dead and does not save to the server as after reset you need to take ownership again but good work so far
 
Thanks for your input. Have to fix that is for all tents. As i read the code again i see it :)

But much more important: how do i save this to survive a serverreset ?
 
I Have some questions regarding blissdatabase and ingame tablenames.

if i have this sql table (instance_deployable)


d deployable_id owner_id instance_id unique_id worldspace inventory last_updated created Hitpoints Fuel Damage
2 1 22 1 100221218560330 [330,[10022.1,2185.64,0.01]] [[[],[]],[[],[]],[[],[]]] 2013-05-04 15:07:49 2013-05-04 11:49:03 [] 0

how can i get the info which ownerid the survivor has who interact with the tent and how do i get unique_id of the tent from inside a .sqf-file ?

deploableid is 100221218560330 in this example.

i thought about getVariable, but whats the name of the variable ?
 
Code:
    _objectID = _object getVariable ["ObjectID","0"];
    _uid = _object getVariable ["ObjectUID","0"];
 
Thx !

ive tried a lot, but i havent got it working. Tried things with mission.pbo and server.pbo... no chance.

tried things like:

Code:
_key = format["CHILD:999:"UPDATE `instance_deployable` SET `owner_id` = %1 WHERE `unique_id` = ?:[%2]:",dayz_characterID,_uid];
    diag_log ("HIVE: WRITE: ChangedOwner "+ str(_key));
    _key call server_hiveWrite;
    _object setVariable ["needUpdate",false,true];

in different ways.... but i dont get it.

in mission.pbo nothing happend. in server.pbo it says when i execute the action "object not found"

Once, i manipulated server_updateobject.sqf with new _type "owner" it seems to work, but ive got a syntaxerrormessage in "format["CHILD:999:"UPDATE `instance...." after i fixed this ive got "object not found" everytime. No other message in the serverlogfile.

I think i will come back to this topic later. I hope my skills are better than :D
 
WHY NOT INSTEAD OF USEING CODE why not just modify the owner in your bliss DB if your not sure how to do that i will be happy to help you out witht he DB work... my skype name is bruceleiroy1
 
WHY NOT INSTEAD OF USEING CODE why not just modify the owner in your bliss DB if your not sure how to do that i will be happy to help you out witht he DB work... my skype name is bruceleiroy1

Thank you for your offer and sry for my late response. Had to fix other scripts for serverrelaunch.

I think a good startingpoint is this script:

http://opendayz.net/threads/tent-duping-issue.8504/

It will change the ownerid from dead survivors back to the living id.

But: i dont want that every tent is staying for ever. So my idea is the following.

instead of changing every tentstorgage to the new living survivor id first check for toiletpaper in the tent. If toiletpaper is there remove it and change the survivorid.

With this method only tents where the player want that the tent is staying alive will last forerver. if the player is killed again and dont place a toiletpaper again the tent will removed by the cleanupscript after 3 days.

But, i realy dont have a clue how to code this in mysql/php.
 
i could teach you a few things that will help you like , custom loadouts , spawnign vehicles, adding the ADmin backpack to admin characters, moving players etc... its all relatively simple hit me up on skype some time you have my skype name
 
I found this on the dayz wiki:

"Update the owner of all tents on the server
This updates the owner id of each tent allowing a survivor who put a tent down but then died to regain the ability to pack it up again."

UPDATE instance_deployable d LEFT JOIN (
SELECT DISTINCT d.owner_id, s.unique_id
FROM instance_deployable d
LEFT JOIN survivor s ON s.id = d.owner_id
WHERE s.is_dead =1
) AS dead ON dead.owner_id = d.owner_id
LEFT JOIN survivor live ON live.unique_id = dead.unique_id
SET d.owner_id = live.id WHERE live.is_dead =0

If it works I guess it could somehow be added to the server housekeeping so that every restart the query is executed?

Tbh tho I think it would be a better solution to just allow anyone to pack a tent, anytime. They can carry off all the stuff inside one so why not take the tent? If the argument is greifing well I can run them over with a vehicle so..
 
Ive got it working via ingame code. Now you can go to any tent and take ownership of the tent including update of Database...

I will make a tutorial if people are interested in it.
 
Quick and dirty tutorial:

Mission.pbo file:

create a file custom\takeOwnership.sqf

Code:
//take ownership of a tent. www.die-philosoffen.com - NeverUsedID
private["_survivorID","_objectUID","_key"];
 
_obj = _this select 3;
 
//get ObjetzUID from object
_objectUID    = _obj getVariable["ObjectUID","0"];
 
//get player who used take ownership
_survivorID  = dayz_characterID;
 
//set owner on clientsite
_obj setVariable ["characterID",dayz_characterID,true];
 
//set owner on sqlserver (it use a publicvariable in publicEH.sqf:
// "dayzChangeOwner" addPublicVariableEventHandler {_id = (_this select 1) spawn server_changeOwner}; //in serveronly section
dayzChangeOwner = [_survivorID, _objectUID];
publicVariable "dayzChangeOwner";
 
//send message to player
cuttext ["Owned tents do not despawn while your character is alive","PLAIN DOWN",2];

in your overwritten fn_selfActions.sqf add after "//Packing my tent" command:

Code:
 //take Ownership tent
    if(cursorTarget isKindOf "TentStorage" and _canDo and _ownerID != dayz_characterID) then {
        if ((s_player_takeOwnership < 0) and (player distance cursorTarget < 3)) then {
            s_player_takeOwnership = player addAction [("<t color=""#FF0000"">" + ("Take Ownership") + "</t>"), "custom\takeOwnership.sqf",cursorTarget, 1, false, true, "",""];
                        //s_player_takeOwnership = player addAction [localize "str_actions_self_07", "\z\addons\dayz_code\actions\tent_pack.sqf",cursorTarget, 0, false, true, "",""];
        };
    } else {
        player removeAction s_player_takeOwnership;
        s_player_takeOwnership = -1;
        };

In your Server.pbo:

create new file compile\server_changeOwner.sqf

Code:
//Rafael TakeOwnership
/*
[_survivorID,_objectUID] spawn server_changeOwner;
*/
 
diag_log ("entering changeOwner...");
 
private ["_key","_survivorID","_objectUID"];
 
_survivorID = _this select 0;
_objectUID =    _this select 1;
_key = format["CHILD:999:UPDATE `instance_deployable` SET `owner_id` = '%1' WHERE `unique_id` = ?:[%2]:",_survivorID,_objectUID];
diag_log ("HIVE: WRITE: ChangedOwner "+ str(_key));
_result = _key call server_hiveReadWrite;
diag_log ("HIVE: RESULT: ChangedOwner "+ str(_result));

edit init\server_functions.sqf and add

Code:
server_changeOwner =        compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_changeOwner.sqf";

directly after:

Code:
server_spawnCrashSite  =    compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_spawnCrashSite.sqf";

This code is serveripware :) That means if you use this code: post the server ip where this code is running in this thread.
 
Why not just change it so anyone can take a tent if they can see it? Seems bizarre that people can empty a tent of all the gear and yet not just take the tent too...
 
Back
Top