Jump to content
Sign in to follow this  
HazJ

Timer Script

Recommended Posts

I need a little help with my timer script please as I am going crazy. :D

The server (hosted or dedi) dies when a second player loads in to the game. I presume this is because of the constant loop (every second) with PV command however I need to still loop it but not sure how exactly. Any help is much appreciated! :)

Init.sqf contains:

if (isNil "BluforScore") then {BluforScore = 0;};
if (isNil "OpforScore") then {OpforScore = 0;};
if (isNil "GameTime") then {GameTime = 1800;};
TimeLimitReached = false;
nul = [] execVM "Scripts\HUD.sqf";

I have tried to execute HUD.sqf on only the client/server/etc but no difference at all which is probably because I am doing it wrong? :confused:

HUD.sqf contains:

waitUntil {alive player};

disableSerialization;

cutRsc ["HUD", "PLAIN"];

[] spawn {
while {true} do {
Countdown = [((GameTime) / 60) + .01, "HH:MM"] call BIS_fnc_timeToString;
Timer = format ["%1", Countdown];
publicVariable "Timer";
GameTime = GameTime - 1;
sleep 1;
if (GameTime == 0 || GameTime < 1) exitWith {TimeLimitReached = true; publicVariable "TimeLimitReached";};
};
};

while {true} do {
_Display = uiNamespace getVariable "HUD";
_BluforScore = format ["Score: %1", BluforScore];
_OpforScore = format ["Score: %1", OpforScore];
_Side = format ["Side: %1", playerSide];
_Health = format ["Health: %1", (((1 - damage player) * 100) - ((1 - damage player) * 100 mod 1))];
_NoFAKs = {"FirstAidKit" == _x} count (items player);
_FAKs = format ["FAKs: %1%", _NoFAKs];
_Score = format ["Score: %1", score player];
_ClientFPS = format ["Client FPS: %1", round diag_fps];
_ServerFPS = "Server FPS: N/A";
if (isServer) then {_ServerFPS = format ["Server FPS: %1", round diag_fps];};
(_Display displayCtrl 10) ctrlSetText _BluforScore;
(_Display displayCtrl 20) ctrlSetText _OpforScore;
/*
(_Display displayCtrl 30) ctrlSetText _Side;
(_Display displayCtrl 40) ctrlSetText _Health;
(_Display displayCtrl 50) ctrlSetText _FAKs;
(_Display displayCtrl 60) ctrlSetText _Score;
*/
(_Display displayCtrl 70) ctrlSetText _ClientFPS;
(_Display displayCtrl 80) ctrlSetText _ServerFPS;
(_Display displayCtrl 0000) ctrlSetText Timer;
sleep 0.5;
};

I also need help with getting the server FPS to show for clients but this can wait for now I guess.

Dirty Haz

Share this post


Link to post
Share on other sites

HAZ, you don't want to be PV-ing that every second dude - best way is to get the server to keep hold of the public/global variable timer - and then send one call out to start the timer locally on all clients computers - who will all run it locally. The server will do what ever comes at the end of that timer anyway - so synching exactly to the ms is not really going to matter.

for JIP, just get them to request, or get the server to send out, a call to run the timer script - with a PV of the timer so they almost synch with the timer for everyone else - this obviously when someone joins - this would be the most efficient way i think.

I think i did this - without the JIP in Fockers cache hunt - rip it out of there

mike

Share this post


Link to post
Share on other sites

Even without the PV commands, it still crashes the server when a second player joins in. I will try what you said now though. Thanks! :)

Dirty Haz

Share this post


Link to post
Share on other sites

Sort of working now I guess, no server crashes but nobody can see the actual updated time on HUD except for the host/server? How can I fix this?

Dirty Haz

Share this post


Link to post
Share on other sites

it seems on a dedicated that everything needs fired up once to set it for the local players... so i always start my hud's in the initPlayerLocal.sqf and then shut it back off.. seems to be the only way to get it to work on a dedi.. could be wrong though.

[] spawn RONIN_fnc_countDownTimer_hud;
sleep 0.1;
//ALL PLAYER HUD'S OFF FOR STARTUP
cutRsc ['default','PLAIN'];

all mine work on dedicated.. no problems.

Share this post


Link to post
Share on other sites

Hmmm, what exactly do I put in my initPlayerLocal.sqf file?

Dirty Haz

Share this post


Link to post
Share on other sites
Hmmm, what exactly do I put in my initPlayerLocal.sqf file?
it seems on a dedicated that everything needs fired up once to set it for the local players... so i always start my hud's in the initPlayerLocal.sqf and then shut it back off.. seems to be the only way to get it to work on a dedi.. could be wrong though.

[] spawn RONIN_fnc_countDownTimer_hud;
sleep 0.1;
//ALL PLAYER HUD'S OFF FOR STARTUP
cutRsc ['default','PLAIN'];

of course rename the function to your name.

and i do run the hud's from both spawn.. calls.. and keypresses.

example code:

//	RONIN
//	by loki
//	Mar. 2014
//
//	countDownTimer_playerKeyPress.sqf

// -----------------------------
//	countDownTimer
//
//	nice little hint to see what key is pressed for onKey commands
//	waituntil {!(IsNull (findDisplay 46))};
//	_keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", "hint str _this"];

//	The primary display uses IDD 46. (eg: findDisplay 46). 
//	This will return displayNull on a dedicated server (so be sure to check isDedicated if using this in a waitUntil condition).
//
//	http://community.bistudio.com/wiki/findDisplay

// -----------------------------
[] call compile preProcessFile "RONIN\rGUI\countDownTimer_hud.sqf";

if (!isDedicated) then
{
//using (scroll lock) to open and close for test
(findDisplay 46) displayAddEventHandler ["KeyDown",

"
	press_pStatsKey = player getvariable ['press_pStats',true];
	publicVariable 'press_pStats';

	keyDown = (_this select 1);

	if (keyDown == 70 AND press_pStatsKey) then 
	{
		cutRsc ['default','PLAIN'];
		player setvariable ['press_pStats',false];
		publicVariable 'press_pStats';
	} 
	else 
	{
		if (keyDown == 70) then 
		{
			[] spawn fn_hudcountDownTimer;
			player setvariable ['press_pStats',true];
			publicVariable 'press_pStats';
		};
	};


"
]; 
};

OR

//start the countDownTimer
[] spawn RONIN_fnc_countDownTimer;

edit:

and just for shits and giggles.. i do have all my hud functions in the cfgFunctions proper. always helps to be neat.

class RONIN 
{

class rHUDs 
{
class countDownTimer_hud 
{
	//RONIN_fnc_countDownTimer_hud
	description="rHUDs: Function for countDownTimer_hud.";
	file = "RONIN\rGUI\countDownTimer_playerKeyPress.sqf";
};
 };
};

Edited by Loki

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×