PDA

View Full Version : [CS:GO] I Don't Understand The Basic Concept of a Bhop Timer


aexi0n
11-07-2014, 18:44
Alright, first off I'd like to thank everyone that has helped me thus far in my development of my bhop plugin. Both getting the HUD and Speed working correctly, and efficiently! I really appreciate the help, but this is the last piece to the puzzle.

I've honestly avoided this for quite sometime now, simply because I just can't grasp how to do it via sourcepawn. I've been trying to make a timer that records the time a player takes to get through a course. (zone A to zone b)

This is what I have currently, but I'm sure I'm not doing it correctly. This is how I would go about it in C++, but could someone assist me on what is the correct way to do this in sourcepawn? ALSO: I'm looking to have it display minutes, seconds, miliseconds.



public StartTimer()
{
for(new s = 1; s<= 60; s++)
{
seconds++;
if(seconds == 60)
{
for(new m = 1; m <= 60; m++)
{
minutes++;
seconds = 0;
if(minutes == 60)
{
for (new h = 1; h <= 60; h++)
{
hours++;
minutes = 0;
seconds = 0;
}
}
}
}
}
}

public StopTimer()
{
seconds = 0;
minutes = 0;
hours = 0;
}


tl;dr I need help creating a timer that starts counting in minutes:seconds:miliseconds format the player's time. Starting the timer when he exits Zone A, and stopping it when he reaches Zone B.

DJ Data
11-07-2014, 18:55
This should cover your Zones problem https://forums.alliedmods.net/showthread.php?p=2023591

aexion
11-07-2014, 19:14
This should cover your Zones problem https://forums.alliedmods.net/showthread.php?p=2023591

Thanks, but I have already got my own zones set-up, pretty much everything has been coded except for the actual timer itself. Right now it just displays Timer: 0:00:00, and turns red when leaving the start zone, and white when entering the finish zone. Just would like some insight on how this is done correctly.

Mitchell
11-08-2014, 03:53
Thats not a timer, that's a loop. loops will fire in the same tick.

aexi0n
11-08-2014, 11:15
Thats not a timer, that's a loop. loops will fire in the same tick.

Damn, No wonder I can't get it to work. I've been looking around an see a lot of people use the GetEngineTime(), but I'm not sure exactly how it would look in code. Would I store the GetEngineTime() when the leave the start zone in X, and the GetEngineTime() when they enter the end zone in Y, then X-Y = time? but then how would I display the timer on their hud? :(

Mitchell
11-08-2014, 14:04
Damn, No wonder I can't get it to work. I've been looking around an see a lot of people use the GetEngineTime(), but I'm not sure exactly how it would look in code. Would I store the GetEngineTime() when the leave the start zone in X, and the GetEngineTime() when they enter the end zone in Y, then X-Y = time? but then how would I display the timer on their hud? :(

Try looking at CreateTimer(..);

aexi0n
11-08-2014, 22:48
Try looking at CreateTimer(..);


Like I understand that you can create a timer, but wouldn't that be a very bad idea to create a timer for each client? I could create a single timer similar to how I do for the HUD, but then it wouldn't be able to start/stop right? I'm not sure if this is the right way, but I also have no idea what the right way actually is.. I'm pretty stuck.

lingzhidiyu
11-09-2014, 11:53
Like I understand that you can create a timer, but wouldn't that be a very bad idea to create a timer for each client? I could create a single timer similar to how I do for the HUD, but then it wouldn't be able to start/stop right? I'm not sure if this is the right way, but I also have no idea what the right way actually is.. I'm pretty stuck.

using bool

add check in hud loop

bool is ture show hud

bool is false dont show hud

aexi0n
11-09-2014, 12:07
using bool

add check in hud loop

bool is ture show hud

bool is false dont show hud

okay maybe I should clarify what I'm actually looking for on this thread haha. I'm trying to figure out how I would create a timer, like they have on the surf, climb, and bhop servers. I already have everything else coded and working. I just need help with the literal timer. as in the thing that counts from up starting from 0:00:00 until the player finishes the map.

blaacky
11-09-2014, 15:13
I've made my own bhop timer and I can help you with this. It's actual very simple. You have to create a global array of floating type variables with size [MAXPLAYERS + 1] like "new g_fStartTime[MAXPLAYERS + 1]" And then when StartTimer is called for a client you assign the value to the variable "GetEngineTime()" like g_fStartTime[client] = GetEngineTime(); blah blah here's an example

#include <sourcemod>

new Float:g_fStartTime[MAXPLAYERS + 1];
new bool:g_bTiming[MAXPLAYERS + 1];

StartTimer(client)
{
g_fStartTime[client] = GetEngineTime();
g_bTiming[client] = true;
}

FinishTimer(client)
{
//fFinishTime is how long it took to finish, use FormatPlayerTime to convert it to a string that looks nice to clients
new Float:fFinishTime = GetEngineTime() - g_fStartTime[client];
StopTimer(client);
}

StopTimer(client)
{
g_bTiming[client] = false;
}

FormatPlayerTime(Float:Time, String:result[], maxlength, bool:showDash, precision)
{
if(Time <= 0.0 && showDash == true)
{
Format(result, maxlength, "-");
return;
}

new hours = RoundToFloor(Time/3600);
Time -= hours*3600;
new minutes = RoundToFloor(Time/60);
Time -= minutes*60;
new Float:seconds = Time;

decl String:sPrecision[16];

if(precision == 0)
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%04.1f":"%.1f", seconds);
else if(precision == 1)
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%06.3f":"%.3f", seconds);
else if(precision == 2)
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%09.6f":"%.6f", seconds);

if(hours > 0)
Format(result, maxlength, "%d:%02d:%s", hours, minutes, sPrecision);
else if(minutes > 0)
Format(result, maxlength, "%d:%s", minutes, sPrecision);
else
Format(result, maxlength, "%s", sPrecision);
}

sgtaziz
11-10-2014, 01:12
I personally set timer[client][starttime] = GetGameTime(); when a player leaves the start zone. When touching the end zone, you can use GetGameTime() - timer[client][starttime] to calculate the total time since leaving the start zone in seconds. To format the time, you can use blaacky's function. (Nice avatar btw blaacky, was happening to watch that what I read your post :P)

aexi0n
11-11-2014, 10:47
Thank you so much blaacky, and sgtaziz. I've been trying to figure this out for a week now, but you guys have helped me do it! The main core for the server is done, and the HUD now displays the players time, and prints to chat when they finish the map! I can't say how much your help was appreciated! It really does mean alot, so thank you both.