Jump to content
Sign in to follow this  
LimpingWhale

Countdown timer, adding a points system & Stopping script if another is activated

Recommended Posts

Points System?

Hello, I've been messing with this Game mode I've been making for the past week or so, and I'm working on adding a points system but have NO idea where to start.

I would like it to be where you kill someone, you get x amount of points, you kill a teamate you lose x amount of points, you destroy an obj. you get x amount of points and so on.

I've tried to find guides on Youtube and google on this but I've found nothing very usefull. Same goes with the Countdown Timer.

CountDown Timer?

I want a countdown timer to be on the screen, maybe bottom right or something. I want the countdown to be activated by my 'setbomb' .sqf script and to run for x amount of time and then disappearing.

I've just started scripting, messing with addons and the editor mode in the ArmA series. So I've very knew, I know little of the basics & some more advanced stuff that I've learned.

I want the countdown timer to appear when the script is activated and disappear when the script ends\or is deactivated.

Stopping Script if another is activated?

So, on my mission, an objective will appear and you have to go plant the bomb and wait 30 seconds for it to go off. If the bomb gets deactivated the bomb won't go off. As of right now, I finished making the bomb explode after 30 seconds of it being planted but if you disarm the bomb before it explodes it still explodes. I can't seem to fix this.

What I'm planning on doing with this information!

I'm not planning on just using this information I hope to receive but also help others with the information. I hate just asking people to help me and then not giving the community anything back in return. It seems a little messed up to do. So, once I finish my map I hope to make a tutorial video on how I did a lot of the things that I completed, including the scripting portions. If you want credit for helping me with this, please say so and I'll make sure to add a credits to my video(s).

How To:

This is the section of my post I'll simplify on how to do the things above.

Adding a countdown Timer:

N\A

Adding a points system:

N\A

Ending a script with a script:

N\A

Credits:



N\A

N\A

N\A

N\A

N\A

:thanx:

Share this post


Link to post
Share on other sites

for the scores you can just use PV & EH to keep track of your scores

something like this:- (not tested but should work)

init.sqf

	if (isNil "totalscore") then { totalscore = 0 };
	publicVariable "totalscore"; 

spawn a group in something like this and add a EH to the units each kill you would get 100 points


///place a markerdown called spawnhere
_grp1 = [getmatkerpos "Spawnhere",EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call BIS_fnc_spawnGroup;

{
  _x addEventHandler ["Killed", { if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 100;}}];
} forEach (units _grp1);

then you just need to do the same for Bluefor or any task - Just do not publicVariable it to much as that will cause you some lagg i.e add the scores up :)

set a trigger up to radio A repeat

totalscore=totalscore;
publicVariable "totalscore";

Sleep 1;
titleText ["BlueFor Total Score so far is...." + str totalscore,"PLAIN DOWN"];titleFadeOut 6;

Timer I use this on dedi

INIT.sqf

END_TIME = 3600; //When mission should end in seconds.

if (isServer) then {
   [] spawn 
   {
               ELAPSED_TIME  = 0;
       START_TIME = diag_tickTime;
       while {ELAPSED_TIME < END_TIME} do 
       {
           ELAPSED_TIME = diag_tickTime - START_TIME;
           publicVariable "ELAPSED_TIME";
           sleep 1;
       };
   };
};


if!(isDedicated) then
{
   [] spawn 
   {
       while{ELAPSED_TIME < END_TIME } do
       {
           _time = END_TIME - ELAPSED_TIME;
           _finish_time_minutes = floor(_time / 60);
           _finish_time_seconds = floor(_time) - (60 * _finish_time_minutes);
           if(_finish_time_seconds < 10) then
           {
               _finish_time_seconds = format ["0%1", _finish_time_seconds];
           };
           if(_finish_time_minutes < 10) then
           {
               _finish_time_minutes = format ["0%1", _finish_time_minutes];
           };
           _formatted_time = format ["%1:%2", _finish_time_minutes, _finish_time_seconds];

           hintSilent format ["Time left:\n%1", _formatted_time];
           sleep 1;
       };
   };
}; 

or a maker time might work better place a maker down called Time_left

then run thsi when you need to

timer.sqf

////run from SERVER not client as using marker/////
if(not isServer) exitWith{};
_hour = 2;
_minute = 0;
_second = 0;
_runtime = 0;
mission_accomplished = false;

while {((_hour > 0) or (_minute > 0) or (_second > 0)) and !(mission_accomplished)} do {

if (_second == 0 AND (_minute > 0 OR _hour > 0)) then {
	_second = 59;
	if (_minute > 0) then {
		_minute = _minute - 1;
	} else {
		if (_hour > 0) then {
			_hour = _hour - 1;
			_minute = 59;
		};
	};
} else {
	_second = _second - 1;
};
"Time_left" setMarkerText format["Timeleft to Complete Mission = %1 : %2 : %3",_hour, _minute,_second];
sleep 1;
_runtime = _runtime + 1;
};

Hope that get your started :)

Edited by 1PARA{God-Father}
  • Like 1

Share this post


Link to post
Share on other sites

Well, it's a bit hard to help you without knowing what you are already capable of doing with scripting.

If you have no clue about scripting in any way whatsoever, I suggest you first learn to use some basic commands, make some working scripts (with any functionality, as long as you understand why they do what they do), and once you understand the commands, syntax, and how it all fits together, you can start asking about how to make specific features.

Share this post


Link to post
Share on other sites

They just added the BIS_fnc_countdown function to the dev branch yesterday. Might play around with that too.

Share this post


Link to post
Share on other sites

Here is a way that you could write some score functions.

addScore = {
private["_add","_scr","_newscr"];
_add = _this select 0;
_scr = player getvariable "score";

_newscr = _score + _scr;

player setvariable ["score",_newscr,true];
};
rmScore = {
private["_add","_scr","_newscr"];
_rm = _this select 0;
_scr = player getvariable "score";

if(_rm > _scr) then {
	_newscr = 0;
} else {
	_newscr = _newscr - _rm; 
};

player setvariable ["score",_newscore,true];
};

To call these functions:

//Add 23 Points
[23] call addScore;

//Remove 22 Points
[22] call rmScore;

NOTE: Add this to your init.sqf file

player setvariable ["score",0,true];

Edited by dcthehole
add the call example

Share this post


Link to post
Share on other sites

how would I have to set this up so if blufor killed opfor they gain (x) points and if they killed a teammate they lose (x) points and viceversa?

also, for destroying objectives, capture flags, etc.

//Add 23 Points

[23] call addScore;

//Remove 22 Points

[22] call rmScore;

< ?

Thanks, and sorry for my lack of knowledge about this subject.

---------- Post added at 18:14 ---------- Previous post was at 17:46 ----------

File "init.sqf"

This will work on editor mode... sorta. it doesn't end the mission. in MP it gives me this error:

'...!()isdedicated) then

{

[] spawn

{

while{|#|Elapsed_time < EndTime } do

{

_time = c...'

error undefined variable in expression: elapsed_time

file mpmissions\__cur_mp.stratis\init.sqf, line 23

and also doesn't show up the timer or end mission.

NOTE: I changed the 3600 to 60 to test. Do i have to change another time so it ends on 0 from 60?

Edited by LimpingWhale

Share this post


Link to post
Share on other sites
for the scores you can just use PV & EH to keep track of your scores

spawn a group in something like this and add a EH to the units each kill you would get 100 points


///place a markerdown called spawnhere
_grp1 = [getmatkerpos "Spawnhere",EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call BIS_fnc_spawnGroup;

{
  _x addEventHandler ["Killed", { if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 100;}}];
} forEach (units _grp1);

I don't know what adding a EH (Eventhandler?) to units is\means, same with PV (publicvariable?). and I do not know where to add this 'code'

---------- Post added at 20:33 ---------- Previous post was at 18:58 ----------

Is there any information on how to use the BIS_fnc_countdown function? I have literally no idea where to start with it.

Edited by LimpingWhale

Share this post


Link to post
Share on other sites

@LimpingWhale

 

I found out how to use BIS_fnc_countdown:

/*

	Author: Karel Moricky



	Description:

	Trigger countdown



	Parameter(s):

		0: NUMBER - countdown in seconds

		1: BOOL - true to set the value globally



	Returns:

	NUMBER

*/



private ["_countdown","_isGlobal"];

_countdown = [_this,0,0,[0,true]] call bis_fnc_param;

_isGlobal = [_this,1,true,[true]] call bis_fnc_param;



switch (typename _countdown) do {

	case (typename 0): {

		private ["_servertime"];

		_servertime = if (ismultiplayer) then {servertime} else {time};

		switch true do {

			case (_countdown < 0): {

				missionnamespace setvariable ["bis_fnc_countdown_time",nil];

				if (_isGlobal) then {publicvariable "bis_fnc_countdown_time";};

				-1

			};

			case (_countdown == 0): {

				private ["_time"];

				_time = missionnamespace getvariable "bis_fnc_countdown_time";

				if (isnil "_time") then {

					-1

				} else {

					(_time - _servertime) max 0

				};

			};

			case (_countdown > 0): {

				private ["_time"];

				_time = _servertime + _countdown;

				missionnamespace setvariable ["bis_fnc_countdown_time",_time];

				if (_isGlobal) then {publicvariable "bis_fnc_countdown_time";};

				_time

			};

			default {

				-1

			};

		};

	};

	case (typename true): {

		([] call bis_fnc_countdown) > 0

	};

	default {

		-1

	};

};

Now when used in the initServer.sqf file like this:

// Mission End
[600, true] call BIS_fnc_countdown; //start mission Countdown

it seems to work fine, even on Dedicated Severs.

 

Problem is, when I want to show the player this timeout in initPlayerLocal.sqf:

// Show Tickets Status
[] call BIS_fnc_showMissionStatus; 

It does only work on my client if I host the game (from editor -> as MP mission) and it counts down from 10min to 0min.

 

But on the dedicated server I get weird numbers (1030min) that grow if I restart the server 3min later, it will show (1033min) If I then restart the server 5min later it will show (1038min).

 

I can however call the BIS_fnc_countdown funciton in the initPlayerLocal.sqf but then the timer goes wild and triggers my end conditions somehow too early.

 

 I think something is broken with the showMissionStatus function... I think there is a step missing by substracting the time of the server (from midnight?) or something like that.

Share this post


Link to post
Share on other sites

As far as countdowns go:

DE_fnc_countdown = {
/*
	Creates a countdown in the main Display,
	color changes from white, to green, to yellow, then to red as the counter comes down (each 1/4 interval)
	After the timer is over, counter is deleted, and code is run

	Parameters:
	 1. INT  - Length of countdown (in seconds)
	 2. BOOL - True if text should be colored, false if it should be white
	 3. ANY  - Arguments to be passed to the code that will be called
	 4. CODE - Code that is called after the countdown is completed
*/
	disableSerialization;
	_ctrl = (findDisplay 46) ctrlCreate ["RscText", 000111000]; // "SOS" in morse
	_ctrl ctrlSetPosition [
		0.9 * safeZoneW + safeZoneX,
		0.9 * safeZoneH + safeZoneY,
		0.1 * safeZoneW,
		0.1 * safeZoneH
	];
	_ctrl ctrlCommit 0;	_ctrl ctrlSetTextColor [1,1,1,1];
	_countDown = _this select 0;
	_secondsPassed = 0;
	while {_countDown > _secondsPassed} do
	{
		_time = time; _timeLeft = _countDown - _secondsPassed; _text = [];
		{
			_interval = floor(_timeLeft / _x);
			_timeLeft = _timeLeft % _x;
			_arr = toArray (str _interval);
			if (count _arr < 2) then {	_arr = [48] + _arr; };
			{ _text pushBack _x; } forEach _arr;
			if (_forEachIndex != 3) then { _text pushBack 58; };
		}forEach [86400, 3600, 60, 1];

		waitUntil {time > _time + 1};
		_ctrl ctrlSetText (toString _text);
		_secondsPassed = _secondsPassed + 1;

		if (_this select 1) then
		{
			switch (true) do
			{
				case (_secondsPassed <   (_countDown / 4)): { _ctrl ctrlSetTextColor [1,1,1,1]; };
				case (_secondsPassed < 2*(_countDown / 4)):	{ _ctrl ctrlSetTextColor [0,1,0,1]; };
				case (_secondsPassed < 3*(_countDown / 4)):	{ _ctrl ctrlSetTextColor [1,1,0,1]; };
				case (_secondsPassed < 4*(_countDown / 4)):	{ _ctrl ctrlSetTextColor [1,0,0,1]; };
			};
		};
	};
	_time = time;
	waitUntil {time > _time + 1};
	ctrlDelete _ctrl;

	(_this select 2) call (_this select 3);
};

To use:

sleep 0.1; //only use sleep if trying to call the function right at mission start
[40, false, "WTF", {hint _this}] call DE_fnc_countDown;

It does not validate input. It does not synchronize across clients.

 

It can be called or spawned. (note that, if called, the script which calls it will halt until the countdown ends)

 

Also, this thread should not have been revived

  • Like 1

Share this post


Link to post
Share on other sites
Guest

Thanks for reviving a 3 years old thread guys.

Share this post


Link to post
Share on other sites

@harmdhast Not useful. Not at all. Thread was unanswered. How is anybody gonna find solutions on here leaving things unanswered?

@dreadedentity Thanks for the explanation. "Does not synchronize across clients" does that mean there's no possibility to show each client the current state of the countdown? That was my question about BIS_fnc_showMissionStatus.

You explained the DE_fnc_countdown. Should we only use this one instead of BIS_fnc_countdown? Why?

Thank you.

Share this post


Link to post
Share on other sites
Guest

You can sync it between clients with the remoteExec fnc

Share this post


Link to post
Share on other sites

Thanks @harmdhast!

 

Where would I execute it? If I'm not wrong, if it's called in the initServer.sqf, wouldn't it only be launched only at server start?

 

What I don't understand is the second parameter explained with 1: BOOL - true to set the value globally. Shouldn't it already be correct for all clients?

 

I've tried to reconnect after the server has started for an hour, and strangely it worked and showed the right time.

 

I'll try running it with and report back.

 

UPDATE: Just tried the following in initServer.sqf:

[600, true] remoteExec ["BIS_fnc_countdown"]; //start mission Countdown

Problem is, my end.sqf script triggers at start of the mission, ending it immediately.

Share this post


Link to post
Share on other sites

i'm interested too in a timer shown on screen, running when a trigger is TRUE and stopping if trigger gets FALSE.

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  

×