Jump to content

[How To] Add Epochs Building Scripts to Right-Click Options (by Petunia)


Recommended Posts

This little tutorial I've placed here as the question was asked by 'phone_guy' here: 

 

This tweak will allow you to add the ability to right-click on an object and build something, with EPOCH's up/down placement system and save it to the database.

 

I'm certainly NOT an SQF genius (AT ALL!) so feel free to advise changes!

 

CREDITS:

 

Right-click system by Maca!

Epoch base building script tweaks by Me!

Of course MASSIVE creds to the EPOCH guys for the base building method in the first place :D

 

 

Assumptions:

 

1) You have added the right-click options mod by Maca134 (kudos to Maca for this wicked mod!) (here: http://epochmod.com/forum/index.php?/topic/4834-add-right-click-options-to-items/)

 

2) You know a little bit about SQF

 

Instructions:

 

1) Place the following code in a file called 'buildwell.sqf'

2) Using Maca's system, call this file by a right-click option (e.g. on a waterbottle, etc)

3) For other objects, change the variable I've commented above/below

4) If you change the object built, check near the end of the file and change the congratulations message accordingly!

 

Note: I've pulled a bit of code out of the one I use on my server as I had a few extra's in there too... IF anyone gets an error with this let me know and I'll throw this version up on my test server to see what's wrong! It 'should' work perfectly though :D

 

Note 2: SOMETIMES an item may suddenly jump up in the air after being placed! It sets back to the correct position after a restart. Not sure why it does this, but as it's only sometimes AND it corrects itself after reboot, I don't mind too much! (Seems to happen LESS if you place the item a few inches lower in the ground!)

 

Here's the file:

 

/*
DayZ Base Building
Made for DayZ Epoch please ask permission to use/edit/distrubute email [email protected].
 
 
Note: Edit the _classname variable below to be the correct classname of the item you want to build, and I suggest you name the file appropiately!
 
Recommended to use alongside Maca's excellent 'right clicks' system: http://epochmod.com/forum/index.php?/topic/4834-add-right-click-options-to-items/
 
Edits by Mike of http://www.petuniaserver.com/ - Original file & all kudos to the EPOCH devs! http://www.dayzepoch.com
*/
 
private ["_location","_dir","_classname","_item","_hasrequireditem","_missing","_hastoolweapon","_cancel","_reason","_started","_finished","_animState","_isMedic","_dis","_sfx","_hasbuilditem","_tmpbuilt","_onLadder","_isWater","_require","_text","_offset","_IsNearPlot","_isOk","_location1","_location2","_counter","_limit","_proceed","_num_removed","_position","_object","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_findNearestPoles","_findNearestPole","_distance","_classnametmp","_ghost","_isPole","_needText","_lockable","_zheightchanged","_rotate","_combination_1","_combination_2","_combination_3","_combination_4","_combination","_combination_1_Display","_combinationDisplay","_zheightdirection","_abort","_isNear","_need","_objHupDiff","_needNear","_vehicle","_inVehicle","_requireplot","_objHDiff","_isLandFireDZ","_isTankTrap"];
 
// Edit the classname BELOW to change what is built
 
_classname = "Land_Misc_Well_L_EP1";
 
// Edit the classname ABOVE to change what is built
 
if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_40") , "PLAIN DOWN"]; };
DZE_ActionInProgress = true;
 
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_isWater =  dayz_isSwimming;
_cancel = false;
_reason = "";
_canBuildOnPlot = false;
 
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
 
DZE_Q = false;
DZE_Z = false;
 
DZE_Q_alt = false;
DZE_Z_alt = false;
 
DZE_Q_ctrl = false;
DZE_Z_ctrl = false;
 
DZE_5 = false;
DZE_4 = false;
DZE_6 = false;
 
DZE_cancelBuilding = false;
 
call gear_ui_init;
closeDialog 1;
 
if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
 
_item = _this;
 
// Need Near Requirements
_abort = false;
_distance = 3;
_reason = "";
 
 
if(_abort) exitWith {
cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
DZE_ActionInProgress = false;
};
 
 
_classnametmp = _classname;
//_require =  getArray (configFile >> "cfgMagazines" >> _this >> "ItemActions" >> "Build" >> "require");
_text =  getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
_ghost = getText (configFile >> "CfgVehicles" >> _classname >> "ghostpreview");
 
_lockable = 0;
 
_requireplot = DZE_requireplot;
if(isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
_requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
};
 
_isAllowedUnderGround = 1;
if(isNumber (configFile >> "CfgVehicles" >> _classname >> "nounderground")) then {
_isAllowedUnderGround = getNumber(configFile >> "CfgVehicles" >> _classname >> "nounderground");
};
 
_offset =  getArray (configFile >> "CfgVehicles" >> _classname >> "offset");
if((count _offset) <= 0) then {
_offset = [0,1.5,0];
};
 
_isPole = (_classname == "Plastic_Pole_EP1_DZ");
_isLandFireDZ = (_classname == "Land_Fire_DZ");
 
_distance = DZE_PlotPole select 0;
_needText = localize "str_epoch_player_246";
 
if(_isPole) then {
_distance = DZE_PlotPole select 1;
};
 
// check for near plot
_findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
_findNearestPole = [];
 
{
if (alive _x) then {
_findNearestPole set [(count _findNearestPole),_x];
};
} foreach _findNearestPoles;
 
_IsNearPlot = count (_findNearestPole);
 
// If item is plot pole and another one exists within 45m
if(_isPole and _IsNearPlot > 0) exitWith {  DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"]; };
 
if(_IsNearPlot == 0) then {
 
// Allow building of plot
_canBuildOnPlot = true;
 
} else {
// Since there are plots nearby we check for ownership and then for friend status
 
// check nearby plots ownership and then for friend status
_nearestPole = _findNearestPole select 0;
 
// Find owner
_ownerID = _nearestPole getVariable["CharacterID","0"];
 
// diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
 
// check if friendly to owner
if(dayz_characterID == _ownerID) then {  //Keep ownership
// owner can build anything within his plot except other plots
if(!_isPole) then {
_canBuildOnPlot = true;
};
 
} else {
// disallow building plot
_canBuildOnPlot = false;
};
};
 
// _message
if(!_canBuildOnPlot) exitWith {  DZE_ActionInProgress = false; cutText [format["Woah there survivor! This ain't your patch, someone's plot pole is nearby!"], "PLAIN DOWN",3]; };
 
_missing = "";
 
_location = [0,0,0];
_isOk = true;
 
// get inital players position
_location1 = getPosATL player;
_dir = getDir player;
 
// if ghost preview available use that instead
if (_ghost != "") then {
_classname = _ghost;
};
 
_object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
 
_object attachTo [player,_offset];
 
_position = getPosATL _object;
 
cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
 
_objHDiff = 0;
 
while {_isOk} do {
 
_zheightchanged = false;
_zheightdirection = "";
_rotate = false;
 
if (DZE_Q) then {
DZE_Q = false;
_zheightdirection = "up";
_zheightchanged = true;
};
if (DZE_Z) then {
DZE_Z = false;
_zheightdirection = "down";
_zheightchanged = true;
};
if (DZE_Q_alt) then {
DZE_Q_alt = false;
_zheightdirection = "up_alt";
_zheightchanged = true;
};
if (DZE_Z_alt) then {
DZE_Z_alt = false;
_zheightdirection = "down_alt";
_zheightchanged = true;
};
if (DZE_Q_ctrl) then {
DZE_Q_ctrl = false;
_zheightdirection = "up_ctrl";
_zheightchanged = true;
};
if (DZE_Z_ctrl) then {
DZE_Z_ctrl = false;
_zheightdirection = "down_ctrl";
_zheightchanged = true;
};
if (DZE_4) then {
_rotate = true;
DZE_4 = false;
_dir = 180;
};
if (DZE_6) then {
_rotate = true;
DZE_6 = false;
_dir = 0;
};
 
if(_rotate) then {
_object setDir _dir;
_object setPosATL _position;
//diag_log format["DEBUG Rotate BUILDING POS: %1", _position];
};
 
if(_zheightchanged) then {
detach _object;
 
_position = getPosATL _object;
 
if(_zheightdirection == "up") then {
_position set [2,((_position select 2)+0.1)];
_objHDiff = _objHDiff + 0.1;
};
if(_zheightdirection == "down") then {
_position set [2,((_position select 2)-0.1)];
_objHDiff = _objHDiff - 0.1;
};
 
if(_zheightdirection == "up_alt") then {
_position set [2,((_position select 2)+1)];
_objHupDiff = _objHupDiff + 1;
};
if(_zheightdirection == "down_alt") then {
_position set [2,((_position select 2)-1)];
_objHDiff = _objHDiff - 1;
};
 
if(_zheightdirection == "up_ctrl") then {
_position set [2,((_position select 2)+0.01)];
_objHupDiff = _objHupDiff + 0.01;
};
if(_zheightdirection == "down_ctrl") then {
_position set [2,((_position select 2)-0.01)];
_objHDiff = _objHDiff - 0.01;
};
 
_object setDir (getDir _object);
 
if((_isAllowedUnderGround == 0) and ((_position select 2) < 0)) then {
_position set [2,0];
};
 
_object setPosATL _position;
 
//diag_log format["DEBUG Change BUILDING POS: %1", _position];
 
_object attachTo [player];
 
};
 
sleep 0.5;
 
_location2 = getPosATL player;
 
if(DZE_5) exitWith {
_isOk = false;
detach _object;
_dir = getDir _object;
_position = getPosATL _object;
//diag_log format["DEBUG BUILDING POS: %1", _position];
deleteVehicle _object;
};
 
if(_location1 distance _location2 > 5) exitWith {
_isOk = false;
_cancel = true;
_reason = "You've moved to far away from where you started building (within 5 meters)";
detach _object;
deleteVehicle _object;
};
 
if(abs(_objHDiff) > 5) exitWith {
_isOk = false;
_cancel = true;
_reason = "Cannot move up or down more than 5 meters";
detach _object;
deleteVehicle _object;
};
 
if (player getVariable["combattimeout", 0] >= time) exitWith {
_isOk = false;
_cancel = true;
_reason = (localize "str_epoch_player_43");
detach _object;
deleteVehicle _object;
};
 
if (DZE_cancelBuilding) exitWith {
_isOk = false;
_cancel = true;
_reason = "Cancelled building.";
detach _object;
deleteVehicle _object;
};
};
 
//No building on roads unless toggled
if (!DZE_BuildOnRoads) then {
if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
};
 
// No building in trader zones
if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
 
if(!_cancel) then {
 
_classname = _classnametmp;
 
// Start Build
_tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
 
_tmpbuilt setdir _dir;
 
// Get position based on object
_location = _position;
 
if((_isAllowedUnderGround == 0) and ((_location select 2) < 0)) then {
_location set [2,0];
};
 
_tmpbuilt setPosATL _location;
 
 
cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
 
_limit = 1;
 
if (DZE_StaticConstructionCount > 0) then {
_limit = DZE_StaticConstructionCount;
}
else {
if (isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
_limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
};
};
 
player playActionNow "Medic";
[player,"repair",0,false,10] call dayz_zombieSpeak;
[player,10,true,(getPosATL player)] spawn player_alertZombies;
sleep 3;
 
cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
 
if (_isPole) then {
[] spawn player_plotPreview;
};
 
_tmpbuilt setVariable ["OEMPos",_location,true];
 
_tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
 
_charID = dayz_characterID;
_activatingPlayer = player;
 
PVDZE_veh_Publish2 = [_tmpbuilt,[_dir,_location],_classname,true,_charid,_activatingPlayer];
publicVariableServer  "PVDZE_veh_Publish2";
 
// Customise the message below
 
cutText [format["Nice one! You now have a shiny new water well!"], "PLAIN DOWN",3];
 
// Customer the message above
 
player reveal _tmpbuilt;
DZE_ActionInProgress = false;
 
} else {
cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
DZE_ActionInProgress = false;
};
 
DZE_ActionInProgress = false;
 

 
Link to comment
Share on other sites

why not just one script and then call the script with a class name variable instead?? i can post the way to do it if you want or you could try it yourself and if you get stuck i can help? There is alot of waste code left in that code you have posted (private variables to start with) that are not in use or needed.

 

Also if you are running build snapping you could use that player_build.sqf as a base script and then pass the class name as a variable from the right click script, and make the exceptions in that player_build.sqf for the custom class names via public/global variable check. this way you keep your mission file as small as possible

Link to comment
Share on other sites

why not just one script and then call the script with a class name variable instead?? i can post the way to do it if you want or you could try it yourself and if you get stuck i can help? There is alot of waste code left in that code you have posted (private variables to start with) that are not in use or needed.

 

Also if you are running build snapping you could use that player_build.sqf as a base script and then pass the class name as a variable from the right click script, and make the exceptions in that player_build.sqf for the custom class names via public/global variable check. this way you keep your mission file as small as possible

Link to comment
Share on other sites

Sounds great! I look forward to those improvements, I'll probably use them myself!

 

I wasn't going to share my version yet, as I've not had time to clean it and use as I'd like really, but as phone_guy asked for help with this, I thought I'd sahre anyway :D

 

Nice ideas you guys had! Lookin forward to seeing those changes

Link to comment
Share on other sites

also in the one iv'e put together (running tests as i write this) i've put in so you can add admins to a special array so they can build without animation and upgrade without parts in inventory. You still need the original part you want to build

 

and just so we are clear. the version i'm going to release will only work if you have snapping running on your server

 

I will post a separate topic as it will need some install instructions and then drop the link here.

Link to comment
Share on other sites

also in the one iv'e put together (running tests as i write this) i've put in so you can add admins to a special array so they can build without animation and upgrade without parts in inventory. You still need the original part you want to build

 

and just so we are clear. the version i'm going to release will only work if you have snapping running on your server

 

I will post a separate topic as it will need some install instructions and then drop the link here.

Link to comment
Share on other sites

i don't follow, you question have nothing to do with players downloading custom pbo's. they will get your custom pbo when they join the server. so i don't get what it is that you want to aboid and what it is you want to do

 

or do you mean like copy it and give it another class name in the core files?? then no, not possible as you need to edit CfgMagazines.hpp

Link to comment
Share on other sites

  • 1 month later...

Thanks for this, Petunia.

 

To fix odd rotations and jumps (that gets fixed after restart), to save to database you should use:

PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location],_classname];
publicVariableServer "PVDZE_obj_Publish";

instead of:

PVDZE_veh_Publish2 = [_tmpbuilt,[_dir,_location],_classname,true,_charid,_activatingPlayer];
publicVariableServer  "PVDZE_veh_Publish2";

But this also means, you have to use custom variables and update dayz_allowedObjects

Link to comment
Share on other sites

  • 3 weeks later...

Past couple of days I've noticed I can't access the contributions Maca134 made. None of the scripting info posts I had bookmarked for studying later when I got everything else ironed out work anymore.

 

Does anyone have functioning info to share with adding right-click'able options to an item? Specifically, to add view distance.

Without access to Maca134s mod to help with these type of extensions, I suspect I'm stuck at "step one"  ='(

 

I wanna lock the view distance into my server in the init.sqf @ 5000 (what me and my buddies all play with) but it would leave my sons PC out in the cold

Link to comment
Share on other sites

Past couple of days I've noticed I can't access the contributions Maca134 made. None of the scripting info posts I had bookmarked for studying later when I got everything else ironed out work anymore.

 

Does anyone have functioning info to share with adding right-click'able options to an item? Specifically, to add view distance.

Without access to Maca134s mod to help with these type of extensions, I suspect I'm stuck at "step one"  ='(

 

I wanna lock the view distance into my server in the init.sqf @ 5000 (what me and my buddies all play with) but it would leave my sons PC out in the cold

http://epochservers.com/viewtopic.php?f=14&t=13

Link to comment
Share on other sites

  • 1 month later...

Hiya, I just saw that WGC GeekGarage has given up on writing scripts for Arma 2 and I was working on something similar so I wanted to know if you were ok with me expanding on your idea in similar manner? I wanted to keep things modular and easily added to and so far, my idea works, I just haven't added too many things to the buildable list. Once I get it all together I could send you a link to my test server to check it out before giving your blessing on the mod to your script. Tried to send you a message but I think your inbox is full ;)

Link to comment
Share on other sites

  • 2 months later...

Hey!

 

Man, sorry for the CRAZY delay in replying to you!

 

OF COURSE it's okay to use what I did! Mostly I just modded other files anyway so, as long as you give creds all good (to epoch devs really, not too bothered for myself as they did the real work!). :D

 

 

Hiya, I just saw that WGC GeekGarage has given up on writing scripts for Arma 2 and I was working on something similar so I wanted to know if you were ok with me expanding on your idea in similar manner? I wanted to keep things modular and easily added to and so far, my idea works, I just haven't added too many things to the buildable list. Once I get it all together I could send you a link to my test server to check it out before giving your blessing on the mod to your script. Tried to send you a message but I think your inbox is full ;)

Link to comment
Share on other sites

  • 3 months later...
  • 3 months later...

Bumperoni

 

Anybody know how to add a cost to this process?

 

I'm using ZSC 3.0 no banking, and would like to add a cost to each buildable. IE 100 coins for a fireplace, 500 for a bed, 2500 for a helipad.

 

Anybody got any ideas?

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
  • Discord

×
×
  • Create New...