Jump to content
  • 1

[VERY BASIC GUIDE] TO MAKE A NEW SCRIPT


juandayz

Question

A very basic guide to make your own script:
 

Feel free to complete this guide :)

1-IN CASE U NEED ADD ONE ITEMS REQUIRED (only one)

Spoiler

structure:

your own variable = "ITEM ID" in magazines player;


_hasitem = "FoodchickenCooked" in magazines player;

2-IN CASE U NEED ADD A ITEMS REQUIRED (more than one)

Spoiler

structure:

your own variable = [["ITEM ID",AMOUNT],["ITEM ID",AMOUNT]] call the function to check the items;


_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;

 

 

*Now into the same script you will need check if this player have the item variable so:

if (_hasitem) then {
};

so the script can be:

Spoiler

if (_hasitem) then {

//here you put  what happend if this player had the items and if u want an animation and a command to remove the item
//for example : make the animation ,put the player thirst at 100% and remove only 1 item

player playActionNow "Medic";    
dayz_thirst = 0;
player removeMagazine "FoodchickenCooked";

}else{

//here u can put a text  to say missing items
cutText [format["You will need 1xFoodchickenCooked"], "PLAIN DOWN"];
};

*Now at very top its time to define the private variables for this script so:

private = ["name of variable","name of variable"];

private = ["_hasitem"];

So at this time the script looks like:

Spoiler

private = ["_hasitem"];

_hasitem = "FoodchickenCooked" in magazines player;

if (_hasitem) then {

player playActionNow "Medic";    
dayz_thirst = 0;
player removeMagazine "FoodchickenCooked";

}else{

cutText [format["You will need 1xFoodchickenCooked"], "PLAIN DOWN"];
};

2-REMOVING ITEMS

Here you will see how to remove more than 1 item: (   remember for remove only one item you can use player removeMagazine "FoodchickenCooked";  )

item requiered:
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;

to remove this items use:

_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;

So now the whole script looks:

Spoiler

private = ["_hasitem","_remove"];

_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;

if (_hasitem) then {

player playActionNow "Medic";    
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;

}else{

cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];
};

Thers other way to say "you dont have the item required" see:

if (!_hasitem) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

***Note: the ! before the variable means  NOT   . So here the code say:  if player Dont Have (_hasitem) exitWith {};

so now the script looks:

Spoiler

private = ["_hasitem","_remove"];

_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;

if (!_hasitem) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};


if (_hasitem) then {

player playActionNow "Medic";    
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;

};

3-ADD A TIME RESTRICTION TO USE THE SCRIPT AGAIN

Now whats about if u wanna put a time restriction to execute the script?

well heres the structure:

if(_Time < _LastUsedTime) exitWith { 
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"]; 
};

But you need define what means _Time & _LastUsedTime variables  and need put where start to count.  So:

_LastUsedTime = 1200;//time in seconds before use again the script
_Time = time - lastuse; //"lastuse" is where you start to count and is equal to time so you need to put it immediately after the _hasitem variable is checked as fine...

 

see:

if (_hasitem) then {
lastuse = time;
};

Well now the whole script looks:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;

//////////////////////////


/////Negatives///////
if (!_hasitem) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};

//////////////////////

/////////////////////Proceed
if (_hasitem) then {
lastuse = time;
player playActionNow "Medic";    
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;

};

4-USING RANDOMS

Now you wanna put a random events into the script. You can use two ways:

First:

_randomCases = round(random(2));
switch (_randomCases) do {    
        case 0 :{
		//what happend here?
		};
		
		case 1 :{
		//what happend here?
		};
		};

Or the other way:

_randomNumbers = floor(random 100);//you can use any other number 100,200,50 

if (_randomNumbers <= 30) then { //if randomNumbers is less or equal to 30 then
//what happend here?
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then { //if randomNumbers is into 31 to 100 then
//what happend here?
};

So for the first example the whole script looks:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomCases"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomCases = round(random(2));
//////////////////////////


/////Negatives///////
if (!_hasitem) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed
if (_hasitem) then {
lastuse = time;
player playActionNow "Medic";

switch (_randomCases) do {    
        case 0 :{

        dayz_thirst = 0;
        _remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
        };
        
        case 1 :{
        dayz_thirst = 1;
        };
};

};       

And for the second example looks:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
//////////////////////////


/////Negatives///////
if (!_hasitem) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed
if (_hasitem) then {
lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};

if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
};
};

5-ADD A TOOL REQUIRED

_inventory = items player;
_hastools = "ItemToolbox" in _inventory;

if !(_hastools) exitWith {
	cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if (_hastools) then {

};

So now the script looks:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;

//////////////////////////


/////Negatives///////
if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed
if (_hasitem && _hastools) then {
lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};

if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
};
};       

6-Allow The script only if player is an hero

Now you want procced with the script only if player is an hero.. so:

_PlayerHumanity = (player getVariable"humanity");

if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_PlayerHumanity > 5000) then {
};

So the whole script now is:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed
if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {
lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
};
};
};

7-ADD A COIN COST

Whats about if u wanna put a coins cost to execute it?

_costs = 200;
if !([ player,_costs] call SC_fnc_removeCoins) then {
		titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
	} else {
	titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];
};

So now script looks:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed
if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
};
};
};
};

8-Nearest Required

Now a nearest required from an objet or AI.

_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["TK_CIV_Woman01_EP1"], 4] > 0; //TK_CIV_Woman01_EP1 is an AI id

if (_nearestRestriction) then {
};

you can use it  to execute scripts only into plot area...

for example:

_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0; 

if (_nearestRestriction) then {
};

or to restrict if is present

for example if is a plot pole in the area you cant execute the script

_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0; 

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

So now the script is:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["TK_CIV_Woman01_EP1"], 4] > 0;

//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed

if (_nearestRestriction) then {

if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
};
};
};
};
};

in negative case.. (if u cannot execute the script if the objet plot area is present then the script must be):

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0;

//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed

 

if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
};
};
};
};

 


9-Give something to the player

here you can use:

player addMagazine "item id";

so for example if u wanna give gold money then:

player addMagazine "ItemBriefcase100oz";

if u wanna give coins money then:

_add = [player, 1000] call SC_fnc_addCoins;

if u wanna give a random item then:

_add = ["ItemSodaOrangeSherbet","HandGrenade_west","ItemSodaEmpty"] call BIS_fnc_selectRandom;

player addMagazine _add;

 

So for the 1st example script looks: (give gold)

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0;
//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed

 

if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;

player addMagazine "ItemBriefcase100oz";
};
};
};
};

for the 2nd example looks: (give coins)

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos","_add"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0;
//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed

 

if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;

_add = [player, 1000] call SC_fnc_addCoins; //1000 coins
};
};
};
};

for the 3rd example (give random item)

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos","_add"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0;

_add = ["ItemSodaOrangeSherbet","HandGrenade_west","ItemSodaEmpty"] call BIS_fnc_selectRandom;
//////////////////////////


/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed

 

if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;

player addMagazine _add;
};
};
};
};

10-Create a small function

Now you need use random events and repeat a large or medium secuence.. to not write twice.. use a small functiion.. see:

///Function
function_spawncrate = {
_cratemodels=["USBasicWeapons_EP1","LocalBasicAmmunitionBox"] call BIS_fnc_selectRandom;
 
_variete = ["ItemSodaOrangeSherbet","HandGrenade_west"] call BIS_fnc_selectRandom;
_stone = ["CinderBlocks","MortarBucket","PartOreSilver"] call BIS_fnc_selectRandom;
_wood = ["PartPlywoodPack","PartWoodPile","PartWoodLumber"] call  BIS_fnc_selectRandom;
_farm =  ["FoodchickenRaw","FoodCanCorn","FoodrabbitRaw","ItemKiloHemp","FoodCanCurgon"] call BIS_fnc_selectRandom;
_aiweapon = ["M16A2","M4A1"] call BIS_fnc_selectRandom;
 
         _crate1 = objNull;
            if (true) then{
               

                _this = createVehicle [_cratemodels, [8352.9189, 5950.7417, -3.0517578e-005], [], 0, "CAN_COLLIDE"];
                _crate1 = _this;
               
                 clearWeaponCargoGlobal _crate1;
                 clearMagazineCargoGlobal _crate1;      
                 _crate1 addWeaponCargoGlobal [_aiweapon, 1];
                 _crate1 addmagazinecargoglobal [_variete, 2];
                 _crate1 addmagazinecargoglobal [_wood, 5];
                 _crate1 addmagazinecargoglobal [_stone, 3];
                 _crate1 addmagazinecargoglobal [_farm, 3];
                 _crate1 setVariable ["permaLoot",true];
            };
            
             sleep 400;
 
                deleteVehicle _crate1;  

};
////////////////////////////////END FUINCTON

 

script looks:

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos","_variete","_stone","_wood","_farm","_aiweapon","_crate1"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0;
//////////////////////////


///Function
function_spawncrate = {
_cratemodels=["USBasicWeapons_EP1","LocalBasicAmmunitionBox"] call BIS_fnc_selectRandom;
 
_variete = ["ItemSodaOrangeSherbet","HandGrenade_west"] call BIS_fnc_selectRandom;
_stone = ["CinderBlocks","MortarBucket","PartOreSilver"] call BIS_fnc_selectRandom;
_wood = ["PartPlywoodPack","PartWoodPile","PartWoodLumber"] call  BIS_fnc_selectRandom;
_farm =  ["FoodchickenRaw","FoodCanCorn","FoodrabbitRaw","ItemKiloHemp","FoodCanCurgon"] call BIS_fnc_selectRandom;
_aiweapon = ["M16A2","M4A1"] call BIS_fnc_selectRandom;
 
         _crate1 = objNull;
            if (true) then{
               

                _this = createVehicle [_cratemodels, [8352.9189, 5950.7417, -3.0517578e-005], [], 0, "CAN_COLLIDE"];
                _crate1 = _this;
               
                 clearWeaponCargoGlobal _crate1;
                 clearMagazineCargoGlobal _crate1;      
                 _crate1 addWeaponCargoGlobal [_aiweapon, 1];
                 _crate1 addmagazinecargoglobal [_variete, 2];
                 _crate1 addmagazinecargoglobal [_wood, 5];
                 _crate1 addmagazinecargoglobal [_stone, 3];
                 _crate1 addmagazinecargoglobal [_farm, 3];
                 _crate1 setVariable ["permaLoot",true];
            };
            
             sleep 400;
 
                deleteVehicle _crate1;  

};
////////////////////////////////END FUINCTON

 

/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed

 

if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
call function_spawncrate;
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
call function_spawncrate;
player addMagazine "ItemBriefcase100oz";
};
};
};
};

 

other way is call an external script into main script see:

[] execVM 'path\to\external\script.sqf';

so the variant to not make the small function as above is call this external.sqf 

your main.sqf

Spoiler

private = ["_hasitem","_remove","_LastUsedTime","_Time","_randomNumbers","_inventory","_hastools","_PlayerHumanity","_costs","_nearestRestriction","_playerPos"];

////////////////////Section to define all variables
_hasitem = [["cinder_wall_kit",2], ["ItemWoodFloor",3]] call player_checkItems;
_LastUsedTime = 1200;
_Time = time - lastuse;
_randomNumbers = floor(random 100);
_inventory = items player;
_hastools = "ItemToolbox" in _inventory;
_PlayerHumanity = (player getVariable"humanity");
_costs = 200;
_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0;
//////////////////////////

 

 

/////Negatives///////
if (_PlayerHumanity < 5000) exitWith {
cutText [format["Need be a hero"], "PLAIN DOWN"];};

if (_nearestRestriction) exitWith {
cutText [format["Not in plot area"], "PLAIN DOWN"];};
};

if (!_hasitem ) exitWith {cutText [format["You will need 2xcinder_wall_kit and 3xItemWoodFloor"], "PLAIN DOWN"];};

if !(_hastools) exitWith {
    cutText [format["Must be equiped with 1x toolbox in your toolbet."], "PLAIN DOWN"];};

if(_Time < _LastUsedTime) exitWith {
    cutText [format["wait %1 seconds !",(round(_Time - _LastUsedTime))], "PLAIN DOWN"];
};
//////////////////////

/////////////////////Proceed


if (_PlayerHumanity > 5000) then {

if (_hasitem && _hastools) then {

if !([ player,_costs] call SC_fnc_removeCoins) then {
        titleText [format["Needs %1 %2.",_costs,CurrencyName] , "PLAIN DOWN", 1];
    } else {
    titleText [format["Pay %1 %2 for this",_costs,CurrencyName] , "PLAIN DOWN", 1];    


lastuse = time;
player playActionNow "Medic";

if (_randomNumbers <= 30) then {
dayz_thirst = 0;
[] execVM 'path\to\external\external.sqf';
_remove = [["cinder_wall_kit",2],["ItemWoodFloor",3]] call player_removeItems;
};
if (_randomNumbers <= 100 && _randomNumbers > 31) then {
dayz_thirst = 1;
[] execVM 'path\to\external\external.sqf';
player addMagazine "ItemBriefcase100oz";
};
};
};
};

and you can put into external.sqf same codes as function_spawncrate

external.sqf

Spoiler

private ["_cratemodels","_variete ","_stone","_wood ","_farm","_aiweapon","_crate1"];

_cratemodels=["USBasicWeapons_EP1","LocalBasicAmmunitionBox"] call BIS_fnc_selectRandom;
 
_variete = ["ItemSodaOrangeSherbet","HandGrenade_west"] call BIS_fnc_selectRandom;
_stone = ["CinderBlocks","MortarBucket","PartOreSilver"] call BIS_fnc_selectRandom;
_wood = ["PartPlywoodPack","PartWoodPile","PartWoodLumber"] call  BIS_fnc_selectRandom;
_farm =  ["FoodchickenRaw","FoodCanCorn","FoodrabbitRaw","ItemKiloHemp","FoodCanCurgon"] call BIS_fnc_selectRandom;
_aiweapon = ["M16A2","M4A1"] call BIS_fnc_selectRandom;
 
         _crate1 = objNull;
            if (true) then{
               

                _this = createVehicle [_cratemodels, [8352.9189, 5950.7417, -3.0517578e-005], [], 0, "CAN_COLLIDE"];
                _crate1 = _this;
               
                 clearWeaponCargoGlobal _crate1;
                 clearMagazineCargoGlobal _crate1;      
                 _crate1 addWeaponCargoGlobal [_aiweapon, 1];
                 _crate1 addmagazinecargoglobal [_variete, 2];
                 _crate1 addmagazinecargoglobal [_wood, 5];
                 _crate1 addmagazinecargoglobal [_stone, 3];
                 _crate1 addmagazinecargoglobal [_farm, 3];
                 _crate1 setVariable ["permaLoot",true];
            };
            
             sleep 400;
 
                deleteVehicle _crate1;  

11-Some "Commands"

sleep  ( you can use it to leave in "stand by" your script for some seconds )

example: ( wait 40 seconds and proceed to delete a crate called _crate1 )

 sleep 40;
 deleteVehicle _crate1;  

also you can use a variable to define the time and make wait the variable with sleep command:

_wait_time = 40;

sleep _wait_time;

deleteVehicle _crate1;

Other way to let the script in "stand by" is use waitUntil command.

for example wait for nearest player from an objet:

_distance = 10;
waitUntil {(player distance _xobjet) < _distance};
//proceed with the rest of the script

so with waitUntil also you can wait to complete some conditions as above, where script wait for player 10 mts near the _xobjet

 

removeAllWeapons player;  //leave a player without weapons
removeBackpack player;  //without backpack
{player removeMagazine _x} forEach magazines player;  //without items

player setVariable['USEC_BloodQty',12000,true]; //set blood amount on player

r_player_infected = true; //infect player

[player,-100] call player_humanityChange;//modify humanity of the player

12-Count amount of item _

Now you need count how many items had this player in his inventory, to stop giving same item for example if thers more than 2

_bloodbagAmount = {_x == "ItemBloodbag"} count magazines player;

if (_bloodbagAmount > 2) exitWith { 
    cutText [format["WARNING: %1, YOure Full of bloodbags", name player], "PLAIN DOWN"];
};

13-Leave the script if player is in combat

if (dayz_combat == 1)  exitWith  { 
    cutText [format["IN COMBAT."], "PLAIN DOWN"];
};

14-Attach to

_player = player;//create a _player variable
_mark = "RoadFlare" createVehicle getPosATL _player;//create a roadflare called _mark with the same location of _player
_mark attachTo [_player, [0,0,0]];//attach _mark to _player with 0/0/0 axis values

In this case we create a "RoadFlare" in the _player position and proceed to attach it with the player

Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0
1 hour ago, kingpapawawa said:

_playerPos = getPosATL player;
_nearestRestriction = count nearestObjects [_playerPos, ["Plastic_Pole_EP1_DZ"], 30] > 0; 

if (_nearestRestriction) then {
};

@juandayz your post is really helpful. Can you tell me how to add to this to check if the person is on the plot pole and not just near one?

https://github.com/EpochModTeam/DayZ-Epoch/blob/master/SQF/dayz_code/compile/fn_selfActions.sqf#L403-L404

Link to comment
Share on other sites

  • 0
14 minutes ago, gernika said:

@juandayz  @salival i have a question too. How i can choose a random player in a script executed from the dayz_server.pbo and check if this player is  in a safezone?

mmm if i understand you well.. you can try it

 _rand_player    = playableUnits call BIS_fnc_selectRandom;//choose a random player

and about the safezone,, i remember some time ago i give you a code in one of your posts to check the safezones, you can use it. so its looks:

private ["DEFINE ALL VARIABLES HERE","",""];

_safezones = [[6325,7807,0],[4063,11664,0],[11447,11364,0],[1606,7803,0],[12944,12766,0],[4361.4937,2259.9526,0], [12060,12640,0]];	
_safezonesRad = 150;
_inSafezone = false;
_rand_player  = playableUnits call BIS_fnc_selectRandom;//choose a random player
_playerName = name _rand_player;

/////////////CHECK IF THE RAND PLAYER IS IN A SAFEZONE
{if (_rand_player distance _x < _safezonesRad) then {
_inSafezone = true;
};
} forEach _safezones;

if((isPlayer _rand_player) && !_inSafezone ) then {
[nil,nil,rTitleText,format["%1 is the rand_player",_playerName], "PLAIN",10] call RE;
//your code here

}else{
[nil,nil,rTitleText,format["%1 cannot be the rand_player cuz he´s in a safezone",_playerName], "PLAIN",10] call RE;
//what happend if the rand player is in safezones.
};

 

Link to comment
Share on other sites

  • 0
On 2016-09-29 at 3:49 PM, juandayz said:

A very basic guide to make your own script:
 

13-Leave the script if player is in combat


if (dayz_combat == 1)  exitWith  { 
    cutText [format["IN COMBAT."], "PLAIN DOWN"];
};

 

Think since 1061 this should be updated :P

if (player getVariable["combattimeout",0] >= diag_tickTime) exitWith {"You are in combat." call dayz_rollingMessages;};

 

Link to comment
Share on other sites

  • 0

Hey Juan!..

Ok... total noob in the game and my friends rent a server.   I am "navigating" in the code but I am lost in the pbo compiling part.  I am using the pbo manager to depbo them, and edit the files (init and basic configs so far) but when I use the pbo manager to "paste" the new file and put it up in the server.... the game has error and I have to put back the backup.

Right now, I am trying to modify the basic inside "dayz_code.pbo"

Any help would be more than welcome.

Thanks

Link to comment
Share on other sites

  • 0
13 minutes ago, LadyVal said:

Hey Juan!..

Ok... total noob in the game and my friends rent a server.   I am "navigating" in the code but I am lost in the pbo compiling part.  I am using the pbo manager to depbo them, and edit the files (init and basic configs so far) but when I use the pbo manager to "paste" the new file and put it up in the server.... the game has error and I have to put back the backup.

Right now, I am trying to modify the basic inside "dayz_code.pbo"

Any help would be more than welcome.

Thanks

You can't edit anything in the dayz_code.pbo. dayz_code is Client. If you want to modify anything from dayz_code you need to move it to your mission and edit the paths for the file. Or add an additional path to overwrite some things. Depends on if it is a function or not.

Let's say you want to have a custom compiles.sqf, so you can edit a lot of paths. It would be stupid to copy the whole file from your dayz_code.pbo to your mission since it would heavily increase the file size and just be useless since all paths are already done in the original file. Instead you make a custom one and only overwrite the paths you need. How do you do this? Go to your mission.pbo and create a dayz_code folder inside. Inside the dayz_code folder, create an init folder. In the init folder, create a compiles.sqf. Now you have a custom compiles.sqf where you can put your custom paths in. But for now, this file isn't called from anywhere, that's why you have to go to your init.sqf and add the file path for it below the original one so it loads the original one first and only overwrite those that are mentioned in your custom compiles.sqf.

A bit more tricky is editing a function because functions aren't split in variables. In one huge variable so you can't just overwrite things. Instead you move the original function (like fn_selfActions.sqf) from your dayz_code.pbo into your mission and replace the original path with the new one since the old one is no longer used.

All in all, never edit the dayz_code.pbo if you aren't an Epoch Dev.

Link to comment
Share on other sites

  • 0

Sorry for all the question (I imagine you guys rolling eyes) jajaja....

So, for example, if i want that halo jumping as a respawn option to allow ppl to halo to some cities I chose, the routine is inside dayz_code... I should set that routine in mission?

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...