Jump to content

Deconstruct Buildables


Snowmobil

Recommended Posts

With this you can remove every new modular buildable, except lockable doors, if you are the owner. Unfortunately, right now the ID stored as OwnerID in the database is the CharacterID. Which means after you die you can't remove any buildables that you build before you died. (You could probably write a mysql trigger that updates the characterID once you respawn.)

 

Lockable doors can be removed by everyone if they are unlocked, because the OwnerID is used to store the combination for the door.

 

I haven't really tested this thoroughly, so use at your own risk ;)

Sorry for all the quotes, text color doesn't seem to work with code.

Instructions:

 

Copy 

dayz_code\init\compiles.sqf
dayz_code\compile\fn_selfActions.sqf
dayz_code\actions\remove.sqf

to a folder in your mission.pbo. (I named it "custom")

 

init.sqf

 

progressLoadingScreen 0.4;

- call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf"; //Compile regular functions
+ call compile preprocessFileLineNumbers "custom\compiles.sqf"; //Compile regular functions
progressLoadingScreen 0.5;

 

compiles.sqf

 

fnc_inAngleSector = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_inAngleSector.sqf"; //Checks which actions for nearby casualty

- fnc_usec_selfActions = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_selfActions.sqf"; //Checks which actions for self
+ fnc_usec_selfActions = compile preprocessFileLineNumbers "custom\fn_selfActions.sqf"; //Checks which actions for self
fnc_usec_unconscious = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_unconscious.sqf";

 

fn_selfActions.sqf:

 

 

_isDestructable = _cursorTarget isKindOf "BuiltItems";

_isWreck = _typeOfCursorTarget in DZE_isWreck;
_isWreckBuilding = _typeOfCursorTarget in DZE_isWreckBuilding;
+ _isModularItem = _cursorTarget isKindOf "ModularItems" or _cursorTarget isKindOf "Land_DZE_WoodDoor_Base" or _cursorTarget isKindOf "CinderWallDoor_DZ_Base";
+ _isUnlockedDoor = (_cursorTarget isKindOf "Land_DZE_WoodDoorLocked_Base" or _cursorTarget isKindOf "CinderWallDoorLocked_DZ_Base") and {_cursorTarget animationPhase "Open_hinge" == 1};
_isRemovable = _typeOfCursorTarget in DZE_isRemovable;
_isDisallowRepair = _typeOfCursorTarget in ["M240Nest_DZ"];

 

 

//Allow player to delete objects

- if(_isDestructable or _isWreck or _isRemovable or _isWreckBuilding) then {

+ if(_isDestructable or _isWreck or _isRemovable or _isWreckBuilding or _isModularItem or _isUnlockedDoor) then {

 

 

if(_player_deleteBuild) then {

if (s_player_deleteBuild < 0) then {
s_player_deleteBuild = player addAction [format[localize "str_actions_delete",_text], "\z\addons\dayz_code\actions\remove.sqf",_cursorTarget, 1, true, true, "", ""];
+ s_player_deleteBuild = player addAction [format[localize "str_actions_delete",_text], "custom\remove.sqf",_cursorTarget, 1, true, true, "", ""];
};

 

remove.sqf

 

 

_objOwnerID = _obj getVariable["CharacterID","0"];

_isOwnerOfObj = (_objOwnerID == dayz_characterID);
 
+ _isModularItem = _obj isKindOf "ModularItems" or _obj isKindOf "Land_DZE_WoodDoor_Base" or _obj isKindOf "CinderWallDoor_DZ_Base";
+ _isLockableDoor = _obj isKindOf "Land_DZE_WoodDoorLocked_Base" or _obj isKindOf "CinderWallDoorLocked_DZ_Base";
+ if(_isModularItem and !_isOwnerOfObj) exitWith {TradeInprogress = false; cutText ["Cannot remove item: You're not the owner.", "PLAIN DOWN"];};
 
if(_obj getVariable ["GeneratorRunning", false]) exitWith {TradeInprogress = false; cutText ["Cannot remove running generator.", "PLAIN DOWN"];};

 

 

// Double check that object is not null

if(!isNull(_obj)) then {
 
+                if (_isLockableDoor and {_obj animationPhase "Open_hinge" == 0}) exitWith {TradeInprogress = false; cutText ["Cannot remove locked door.", "PLAIN DOWN"];};
 
                 deleteVehicle _obj;
Link to comment
Share on other sites

Try this:

CREATE TRIGGER update_owner
AFTER INSERT ON character_data
FOR EACH ROW
BEGIN
    UPDATE object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
           (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);
END;
Haven't tested it though.
Link to comment
Share on other sites

 

Try this:

CREATE TRIGGER update_owner
AFTER INSERT ON character_data
FOR EACH ROW
BEGIN
    UPDATE object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
           (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);
END;
Haven't tested it though.

 

 

BOOM

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN
    UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
           (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);
END//
DELIMITER ;
Link to comment
Share on other sites

 

BOOM

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN
    UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
           (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);
END//
DELIMITER ;

the code works and updated the database to my new character id but when i went to go test deleting it told me i was not owner. i did everything stated above

Link to comment
Share on other sites

_isModularItem and _isUnlockedDoor are not added to private? Also, you can change all the characterID to the playerUID in the remove,build,selfactions, etc files to make it write the playerUID to the database for permanent owner.

 

Why didn't the devs do this in the official release? I'm sure there must be a reason , can anyone shed some light on this? If its not an issue then I'll start replacing all the CharacterIDs with PlayerUID :)

Link to comment
Share on other sites

Works for me, I did one edit, made the variables private so there is no conflict any where.

 

Also careful doing my suggestion of changing them to PUID, there are many places where that shouldnt be so, and many files you need to over ride to make it work.

Link to comment
Share on other sites

before this was working for me but now it's not iam not able to remove stuff i built after i die and there is a server restart still tells me i aint the owner

 

edit: i found out using this

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN
UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
(SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);
END//
DELIMITER ;

 

changes my players door combos and sometimes safes so i removed it and havent had anymore problems with that sadly now tho they cant remove the stuff they build

Link to comment
Share on other sites

Yea forgot about combos... you'd also have to check Classname if its not a lockable door/safe.

 

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN

SET @lockables = 'Classname1, Classname2, Classname3';
UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE FIND_IN_SET(Classname, @lockables) = 0 AND 

CharacterID IN (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);

END//
DELIMITER ;

Link to comment
Share on other sites

Yea forgot about combos... you'd also have to check Classname if its not a lockable door/safe.

 

DELIMITER ;

DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;

DELIMITER //

CREATE TRIGGER dayz_epoch.`update_owner`

AFTER INSERT ON dayz_epoch.character_data

FOR EACH ROW

BEGIN

SET @lockables = 'Classname1, Classname2, Classname3';

UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE FIND_IN_SET(Classname, @lockables) = 0 AND 

CharacterID IN (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);

END//

DELIMITER ;

 

 

so for classname1 i use MetalFloor_DZ, etc or am i reading it wrong

Link to comment
Share on other sites

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN
    UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
		(SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID)
	AND NOT (Classname LIKE '%door%' OR Classname LIKE '%vault%' OR Classname LIKE '%box%');
END//
DELIMITER ;

Update now it don't update vault, doors and lockbox

Link to comment
Share on other sites

other players are allowed to remove these types without being the owner so how would i go about blocking it so they cant remove it but just the owner

 

Land_HBarrier1_DZ

Land_HBarrier3_DZ

 

edit: also i did use that code above

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN
UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE CharacterID IN
        (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID)
    AND NOT (Classname LIKE '%door%' OR Classname LIKE '%vault%' OR Classname LIKE '%box%');
END//
DELIMITER ;

 

and one of our friends codes changed again the classname was cinderwalldoorlocked_dz

 

but in the code above it shouldnt be updating anything with the word door so idk whats up

Edited by theballin7
Link to comment
Share on other sites

Hi guys,

 

The below is an excerpt from remove.sqf whch includes refunding a ItemGeneric when a modular item is deconstructed.

        if(_isWreck) then {

            // Find one random part to give back

            _refundpart = ["PartEngine","PartGeneric","PartFueltank","PartWheel","PartGlass","ItemJerrycan"] call BIS_fnc_selectRandom;

            _selectedRemoveOutput set [count _selectedRemoveOutput,[_refundpart,1]];

        } else {

            if(_isWreckBuilding) then {

                _selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");

            } else {

                if(_isModularItem or _isLockableDoor) then {

                    _refundpart = ["PartGeneric"] call BIS_fnc_selectRandom;

                    _selectedRemoveOutput set [count _selectedRemoveOutput,[_refundpart,1]];                    

                } else {

                    _selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");

                    _preventRefund = (_objectID == "0" && _objectUID == "0");

                };

            

            };

        };

Anyone have a problem where the modular items return after server restart?

 

Cheers.

Link to comment
Share on other sites

Stupid question...where are you guys inserting this code?!?!?

 

DELIMITER ;
DROP TRIGGER IF EXISTS dayz_epoch.`update_owner`;
DELIMITER //
CREATE TRIGGER dayz_epoch.`update_owner`
AFTER INSERT ON dayz_epoch.character_data
FOR EACH ROW
BEGIN

SET @lockables = 'Classname1, Classname2, Classname3';
UPDATE dayz_epoch.object_data SET CharacterID = NEW.CharacterID WHERE FIND_IN_SET(Classname, @lockables) = 0 AND 

CharacterID IN (SELECT CharacterID FROM character_data WHERE PlayerUID = NEW.PlayerUID);

END//
DELIMITER ;

Link to comment
Share on other sites

other players are allowed to remove these types without being the owner so how would i go about blocking it so they cant remove it but just the owner

 

Land_HBarrier1_DZ

Land_HBarrier3_DZ

 

 

in remove.sqf you can add the name of the obj as follows.  this will make the item only removable by owner
 
 
_isModularItem = _obj isKindOf "ModularItems" or _obj isKindOf "Land_DZE_WoodDoor_Base" or _obj isKindOf "CinderWallDoor_DZ_Base" or _obj isKindof "Sandbag1_DZ" or _obj isKindof "Land_HBarrier1_DZ" or _obj isKindof "Land_HBarrier3_DZ" or _obj isKindof "MetalPanel_DZ";
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
×
×
  • Create New...