Jump to content
  • 0

[Solved] Running Script Once(For a new player)


Dealman

Question

I've been playing around a bit and I need to find a way for my script to only run once when the player first joins my server. Currently, the code is run every time the player is spawned.

 

Is this something that's possible? I've tried getting and setting a variable, but the variable is lost when the player goes back to the lobby.

 

Any suggestions are greatly welcome!

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

It is definitely possible to do through the dayz_server.pbo.
In theory, you could edit server_playerLogin.sqf located in the dayz_server.pbo/compile folder and add a line when the player is identified as a new spawn.
Inside of the file, line 70ish, there's

_newPlayer = _primary select 1;

Now if this does what it suggests, then all you need to do is attach this variable to the player when the login is successful.

where line 81 is the start of the if (!_isNew) statement and we want the else function located on line 93 (may be subject to change line numbers) to include a check in the following model:
 

if (!_isNew) then {
//returning, do stuff
} else {
//use the _newPlayer variable in here
}

EDIT:
It seems like this is taken care of by the end of the file:

dayzPlayerLogin = [_charID,_inventory,_backpack,_survival,_isNew,dayz_versionNo,_model,_isHiveOk,_newPlayer,_isInfected];
(owner _playerObj) publicVariableClient "dayzPlayerLogin";

See if you can get the variable _newPlayer through the mission.

Link to comment
Share on other sites

  • 0

Thanks for the quick reply!

 

I didn't manage to fetch any variable through the mission, but I'm relatively new to coding for ArmA 2 in general, so I might very well have done it wrong.

 

I tried to edit server_playerLogin.sqf but I couldn't get it to work. I tried to set my variable to true if the player is not new and to false if they are new. However, the code is still run upon joining the server.

if (!_isNew) then {
	//RETURNING CHARACTER		
	_inventory = 	_primary select 4;
	_backpack = 	_primary select 5;
	_survival =		_primary select 6;
	_model =		_primary select 7;
	_hiveVer =		_primary select 8;
	
	if (!(_model in AllPlayers)) then {
		_model = "Survivor2_DZ";
	};
	
	_playerObj setVariable["hasSeenVideo", true];
	
} else {
	if (DZE_PlayerZed) then {
		_isInfected = _primary select 3;
	} else {
		_isInfected = 0;
	};
	_playerObj setVariable["hasSeenVideo", false];
...

And the mission-side code;

_videoHasPlayed = player getVariable["hasSeenVideo", false];

if(!_videoHasPlayed) then {
	waitUntil{alive player};
	waituntil{!isnull(finddisplay 46)};
	sleep 5;
	_CustomGpsVideo = ["Video\Intro_Video.ogg", 1.04] spawn bis_fnc_customGPSvideo;
	player setVariable["hasSeenVideo", true, false];
};

My guess is that _playerObj isn't actually the player...? And as such, it's set to false as default value via the mission-side code?

 

Also, do you know what exactly defines the player as a "new player"? Whether or not they exist in the database, I'd assume?

Link to comment
Share on other sites

  • 0

Removed the edits I did to server_playerLogin and added "_videoHasPlayed = dayzPlayerLogin select 9;" to my mission-side code. The video won't play at all, tried to delete all traces related to my Player ID in the database. In case that would make sure my Player ID is considered new.

Link to comment
Share on other sites

  • 0

Cool! Greatly appreciate your help. I'll get a friend to join my server just to ensure that it is a new player, see if it works!

Try out _videoHasPlayed = dayzPlayerLogin select 8;

I was 1 number off previously from the _newPlayer variable.

Testing this out now on my server

EDIT:

Does not work.

Trying out another thing, one minute.

EDIT 2:

dayzplayerlogin on a respawn yields:

["1",[],[],[0,0,0],true,"2.0","Survivor2_DZ",true,false,0]

dayzplayerlogin on a new player yields:

["1",[],[],[0,0,0],true,"2.0","Survivor2_DZ",true,true,0]

The 9th value of the array changes to "true" if the player has never been in the server before.

"dayzplayerlogin select 8" should be able to retrieve that new player value from within the mission file.

Link to comment
Share on other sites

  • 0

Alright, I'm trying it out. But do you know what makes a player considered new? Is it whether they're a fresh spawn, or is it something tied to whether the Player ID has logged in before...?

 

It would seem it's the database that defines whether a player is new or not. It does indeed work now. Thanks a lot! Owe you one  :)

 

Edit:

 

While at it, might I ask if you're familiar with the script known as "MountedSlots"? It's a script used by TakiLife RPG missions, which lets players get into the rear of trucks and still be able to look around and shoot - using attachTo.

 

However, the code's very messy for a beginner like me so I ended up trying to write my own and I've pretty much managed to replicate it with my own solution - but I'm having great trouble getting the mouse aiming to move.

 

I did manage to be able to look around, albeit if you look around very slowly. Or else the game will bug tremendously and ultimately give you a bright-blue screen. :P

 

Is this anything you'd be interested in helping me out with? I'd gladly share it with the community upon completion, I think it would be a very welcome addition to the DayZ Community. :)

Link to comment
Share on other sites

  • 0

Alright, I'm trying it out. But do you know what makes a player considered new? Is it whether they're a fresh spawn, or is it something tied to whether the Player ID has logged in before...?

 

It would seem it's the database that defines whether a player is new or not. It does indeed work now. Thanks a lot! Owe you one  :)

 

Edit:

 

While at it, might I ask if you're familiar with the script known as "MountedSlots"? It's a script used by TakiLife RPG missions, which lets players get into the rear of trucks and still be able to look around and shoot - using attachTo.

 

However, the code's very messy for a beginner like me so I ended up trying to write my own and I've pretty much managed to replicate it with my own solution - but I'm having great trouble getting the mouse aiming to move.

 

I did manage to be able to look around, albeit if you look around very slowly. Or else the game will bug tremendously and ultimately give you a bright-blue screen. :P

 

Is this anything you'd be interested in helping me out with? I'd gladly share it with the community upon completion, I think it would be a very welcome addition to the DayZ Community. :)

I actually have been working on my own previously, but I have not completed it.

If you're up for sending me some files, go right ahead, but I will use the old code I have and try to get it to work.

Will report on it via message later tonight.

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

×
×
  • Create New...