Jump to content
  • 0

Player variable


juandayz

Question

tnks.

How can i set a variable on player. something like player_injured or infected.

for example i set a global variable as false  in init.sqf

run a script located in mpmissions/....... who change this variable as true. 

and thers other script who change it again as false if player decided run it.

What i need if is player logout whitout change the variable as false.. and log again this variable still be in true.

 

this is what i try:

init.sqf

Spoiler

if (r_player_x) then  {
xvariable = true;
}else{
xvariable = false;
};

scriptmpmissions.sqf

Spoiler

xvariable = true;
systemChat ("xvariable is true");
r_player_x = true;
player setVariable["x",true,true];

 

scriptmpmissions.sqf  (give the option to set xvariable as false again)

Spoiler

xvariable = false;
r_player_x = false;
player setVariable["x",false,false];

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
23 hours ago, DuMa said:

Here is an example, XP System I used to work on before.

In init.sqf,

I would do this.


if (isNil{profileNamespace getVariable["PlayerXP",0]}) then {		//Player have not played atleast once in the server, So create a new data profile for him.
	profileNamespace setVariable ["PlayerXP",0];	//Set PlayerXP = 0 in the proflename space since hes new.
	saveProfileNamespace;	//Save PlayerXP = 0.
	PlayerXP = profileNamespace getVariable ["PlayerXP",0];	//Set global Variable PlayerXP = 0 , so we dont have to use define the variable in each scripts.
}else{
	PlayerXP = profileNamespace getVariable ["PlayerXP",0];			//Player Is regular, so get data from the data profiel.
};

And to add and delete XP, I would do this in add_xp.sqf


private ["_xptoadd"];
_xptoadd = 5;

profileNamespace setVariable["PlayerXP",(PlayerXP+_xptoadd)];	//Add 5 to PlayerXP

saveProfileNamespace; 	//Save it again to the file.

 

 

 

 

this exactly what i need. i was working on a system to forces players to made pee and poo, and others things... shame i just finish the first version yesterday but i can rewrite some things using your example..

 

For example i can add a  force sleep action

if (isNil{profileNamespace getVariable["PlayerXP",0]}) then {		//Player have not played atleast once in the server, So create a new data profile for him.
	profileNamespace setVariable ["PlayerXP",0];	//Set PlayerXP = 0 in the proflename space since hes new.
	saveProfileNamespace;	//Save PlayerXP = 0.
	PlayerXP = profileNamespace getVariable ["PlayerXP",0];	//Set global Variable PlayerXP = 0 , so we dont have to use define the variable in each scripts.
}else{
	PlayerXP = profileNamespace getVariable ["PlayerXP",0];			//Player Is regular, so get data from the data profiel.
};

///////////////////////////////////check.sqf
if (dayz_Survived == 1) then {
player setVariable ["PlayerXP",1];

//spawn icon to advice about the sleep
//made players loose blood
//some others visual effects

//add on player the action to sleep
if (s_player_sleep < 0) then {
s_player_sleep = player addAction [("<t color=""#3399cc"">" + ("sleep") + "</t>"), "scripts\othersystem\sleep.sqf"];};
} else {
player removeAction s_player_sleep;
s_player_sleep = -1;
};
};
////////////////////////////
                       
                       
////////////////////
sleep.sqf

PlayerXP = player getVariable ["PlayerXP",1];	

if (PlayerXP) then {
player setVariable ["PlayerXP",0];
//code action
};

 

Link to comment
Share on other sites

  • 0
On 10. 5. 2017 at 2:43 PM, DuMa said:

Here is an example, XP System I used to work on before.

In init.sqf,

I would do this.


if (isNil{profileNamespace getVariable["PlayerXP",0]}) then {		//Player have not played atleast once in the server, So create a new data profile for him.
	profileNamespace setVariable ["PlayerXP",0];	//Set PlayerXP = 0 in the proflename space since hes new.
	saveProfileNamespace;	//Save PlayerXP = 0.
	PlayerXP = profileNamespace getVariable ["PlayerXP",0];	//Set global Variable PlayerXP = 0 , so we dont have to use define the variable in each scripts.
}else{
	PlayerXP = profileNamespace getVariable ["PlayerXP",0];			//Player Is regular, so get data from the data profiel.
};

And to add and delete XP, I would do this in add_xp.sqf


private ["_xptoadd"];
_xptoadd = 5;

profileNamespace setVariable["PlayerXP",(PlayerXP+_xptoadd)];	//Add 5 to PlayerXP

saveProfileNamespace; 	//Save it again to the file.

 

Really nice idea!

Iit's file operation so it could be expensive. @DuMa, what's your experience with saving vars this way? Any problems or craching game?

 

 

 

Link to comment
Share on other sites

  • 0
4 minutes ago, DuMa said:

 if you save a lot of variables it might cause some performance issues, and in this example we used only 1 variable we are just changing it continuously. And to be honest I haven't used this a lot.  But I did use this to save player's view distance. So they don't have to change it every time they die or relog. Also if you are really concerned about it, keep in mind the old Group System from 1.0.5.1 used this technic to save player group data. It's your choice as long as you don't offload all the variables to profile data then your fine. Also this might be unsafe to do it. Not sure. 

Make sense to me... thx for your time. Cheers

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