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

timer question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 07-29-2013 , 15:06   timer question
Reply With Quote #1

Hey guys,

I've got a Problem,

on player spawn I got this code

g_ticker[client] = CreateTimer(20.0, ticker, client);

then

public Action:ticker(Handle:timer, any:client)
{
// do smth
}


how can I kill this timer on round end ?
cause if the round ends before the 20s expire my whole plugin messes up.
any help ?


Allready tried this on roundend:

for (new i = 1; i <= GetMaxClients(); i++){
CloseHandle(g_ticker[i]);
}

does not work
Totenfluch is offline
Eden.Campo
Member
Join Date: Mar 2013
Old 07-29-2013 , 15:12   Re: timer question
Reply With Quote #2

Code:
for ( new i = 1; i <= MaxClients; i++ )
{
       if(!IsClientConnected(i) || IsFakeClient(i) || !IsClientInGame(i))
       continue;

      KillTimer(g_ticker[i]);
}
Eden.Campo is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 07-29-2013 , 15:27   Re: timer question
Reply With Quote #3

thanks !

one question: Does the round_end event fire if you use "mp_restartgame 1" ?
Totenfluch is offline
Eden.Campo
Member
Join Date: Mar 2013
Old 07-30-2013 , 02:13   Re: timer question
Reply With Quote #4

Quote:
Originally Posted by Totenfluch View Post
thanks !

one question: Does the round_end event fire if you use "mp_restartgame 1" ?
I ain't sure.
Anyways, if it doesn't, use AddCommandListener(callback, "mp_restartgame").
Eden.Campo is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-31-2013 , 01:58   Re: timer question
Reply With Quote #5

Code:
if(!IsClientConnected(i) || IsFakeClient(i) || !IsClientInGame(i))
Checking IsClientConnected is not necessary, as IsClientInGame already does that check.

Might want to do this instead:

Code:
if(IsFakeClient(i) || !IsClientInGame(i))

Last edited by ddhoward; 07-31-2013 at 01:59.
ddhoward is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-31-2013 , 06:20   Re: timer question
Reply With Quote #6

Quote:
Originally Posted by ddhoward View Post
Code:
if(!IsClientConnected(i) || IsFakeClient(i) || !IsClientInGame(i))
Checking IsClientConnected is not necessary, as IsClientInGame already does that check.

Might want to do this instead:

Code:
if(IsFakeClient(i) || !IsClientInGame(i))
Other way around. Do the in-game check first.
__________________
11530 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-31-2013 , 12:15   Re: timer question
Reply With Quote #7

DURRRRR thanks lol

Now that I think about it, would it matter that they are both on the same line?

For example,

Code:
if (!IsClientInGame(i) || IsFakeClient(i)) {
Let's say that 'i' is well over "MaxClients." Would running this check cause IsFakeClient to throw an error? I would think to separate them like this:

Code:
if (!IsClientInGame(i)) {
	return;
}
if (IsFakeClient(i)) {
	return;
}

Last edited by ddhoward; 07-31-2013 at 12:21.
ddhoward is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 07-31-2013 , 12:24   Re: timer question
Reply With Quote #8

There shouldn't really be a case where i is > MaxClients, you're supposed to account for that. And you don't have to have the calls on the same line, as it'll still be processed in its defined order.
__________________
thetwistedpanda is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-31-2013 , 12:39   Re: timer question
Reply With Quote #9

I don't know why I indicated that i > MaxClients... Long night lol.

In any case, I wasn't sure if SM would stop running parts of the conditional if it was already guaranteed to be true. Tested it out myself, and I know know that it somehow does stop?

Code:
public OnPluginStart() {
	for (new i = 1; i <= MaxClients; i++)
		if (IsFakeClient(i))
			PrintToChatAll("test %i", i)
}
In this example, IsFakeClient is run on even non-connected players, and throws an error.

Code:
public OnPluginStart() {
	for (new i = 1; i <= MaxClients; i++)
		if (!IsClientInGame(i) || IsFakeClient(i))
			PrintToChatAll("test %i", i)
}
Here, however, if IsClientInGame returns false (making that half of the conditional = true), then IsFakeClient isn't even touched. Fascinating.

Last edited by ddhoward; 07-31-2013 at 12:43.
ddhoward is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-31-2013 , 12:45   Re: timer question
Reply With Quote #10

Quote:
Originally Posted by ddhoward View Post
Code:
public OnPluginStart() {
    for (new i = 1; i <= MaxClients; i++)
        if (!IsClientInGame(i) || IsFakeClient(i))
            PrintToChatAll("test %i", i)
}
Here, however, if IsClientInGame returns false (making that half of the conditional = true), then IsFakeClient isn't even touched. Fascinating.
|| and && use Short-circuit Evaluation. Basically, that means if the part before || is true, or the part before && is false, the other side won't be evaluated at all.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-31-2013 at 12:46.
Powerlord 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:23.


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