Raised This Month: $51 Target: $400
 12% 

TFC Stopwatch Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
12Toastie
Junior Member
Join Date: Nov 2014
Old 10-16-2021 , 18:50   TFC Stopwatch Plugin
Reply With Quote #1

Doing a stop watch plugin.. basically you start at one part and say !start, and itll do a stopwatch until you get to the next part and do !time

problem is coming when I am doing a 1/0 switch on timerBool and that seems to not be carrying over to other functions.. pretty sure I properly made it a global? The minutes, seconds, and ticks arent carrying over to the stopTimer function and are returning 0:00.0 when i get rid of the timerBool just to allow it to function.

*I could* get away with not using the timerBool, but then I wouldnt be able to, in the future, allow them to reset their time. But ya, even without the timerBool there, the minutes, seconds and ticks are still returning 0:00.0 on stopTimer()


Did I do something wrong with setting globals???

Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include < fakemeta >
#include < hamsandwich >

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Mark"

new ticks[33]
new seconds[33]
new minutes[33]
new timerBool[33]

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_clcmd("say !start", "startTimer", 4, "", -1);
	register_clcmd("say !time", "stopTimer", 4, "", -1);
	//register_clcmd("say !origin", "stopTimer", 4, "", -1);
}

public startTimer(id){
	if(timerBool[id] == 0){
		
		new origin[33][3]
		pev(id, pev_origin, origin[id]);
		client_print(0, print_chat, "x:%f y:%f z:%f", origin[id][0], origin[id][1], origin[id][2]);
		new lowerX = floatcmp(origin[id][0], -3504.0)
		new upperX = floatcmp(origin[id][0], -2500.0)
		new lowerY = floatcmp(origin[id][1], 3180.0)
		new upperY = floatcmp(origin[id][1], 3850.0)
		new equalZ = floatcmp(origin[id][2], -187.968750)
		if((lowerX == 1) && (upperX == -1) && (lowerY == 1) && (upperY == -1) && (equalZ == 0)){
			timerBool[id] = 1
			set_task(0.1, "tickUpdate", 0, "", 0, "b", 0);
		}
	}
}

public stopTimer(id){
	if(timerBool[id] == 0){
		new origin[33][3]
		pev(id, pev_origin, origin[id]);
		client_print(0, print_chat, "x:%f y:%f z:%f", origin[id][0], origin[id][1], origin[id][2]);
		new lowerX = floatcmp(origin[id][0], -1967.0)
		new upperX = floatcmp(origin[id][0], -1681.0)
		new lowerY = floatcmp(origin[id][1], -3824.0)
		new upperY = floatcmp(origin[id][1], -2833.0)
		new equalZ = floatcmp(origin[id][2], 2020.031250)
		if((lowerX == 1) && (upperX == -1) && (lowerY == 1) && (upperY == -1) && (equalZ == 0)){
			server_cmd("say You have finshed the course in %d:0%d.%d", minutes[id], seconds[id], ticks[id]);
			timerBool[id] == 0
		}
	}
}

public tickUpdate(id){
	if(timerBool[id] == 1){
		ticks[id]++
		if(ticks[id] > 9){
			seconds[id]++
			ticks[id] = 0
		}
		if(seconds[id] > 59){
			minutes[id]++
			seconds[id] = 0
		}
		if(seconds[id] < 10){
			//client_print(0, print_chat, "%d:0%d.%d", minutes, seconds, ticks);
			set_hudmessage(255, 255,255, -1.0, 0.3, 0, 6, 12.0, 0.0, 0.0, -1)
			show_hudmessage(id, "%d:0%d.%d", minutes[id], seconds[id], ticks[id]);
		
		}
		else{
			//client_print(0, print_chat, "%d:%d.%d", minutes, seconds, ticks);
			set_hudmessage(255, 255,255, -1.0, 0.3, 0, 6, 12.0, 0.0, 0.0, -1)
			show_hudmessage(id, "%d:%d.%d", minutes[id], seconds[id], ticks[id]);
		}
	}
		
}

Last edited by 12Toastie; 10-16-2021 at 18:51.
12Toastie is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 10-17-2021 , 09:08   Re: TFC Stopwatch Plugin
Reply With Quote #2

third parameter in set_task is the task id. in your case the id in "tickupdate" is always 0 - that's the reason you get 0:00.0 in "stoptimer"

also instead of formatting "0%d" with if's and else's you can straight up format it as "%02d" to force the output to be at least 2 characters long (1 will be printed as 01, but 10 will remain 10)
jimaway is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode