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

One time Timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EasySoft
BANNED
Join Date: Jan 2010
Old 01-15-2010 , 19:44   One time Timer
Reply With Quote #1

How can I create only one time timer?

So I want to write CreateTimer(sdfsdf, sdfdsfsdf)

And this function should be executed only once not on every x seconds.
EasySoft is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 01-15-2010 , 20:04   Re: One time Timer
Reply With Quote #2

CreateTimer(1.0, SomethingHere);

or for client

CreateTimer(1.0, SomethingHere, client);


Goes to >>>>

public Action:SomethingHere(Handle:timer) or public Action:SomethingHere(Handle:timer, any:client)

Last edited by retsam; 01-15-2010 at 20:07.
retsam is offline
EasySoft
BANNED
Join Date: Jan 2010
Old 01-15-2010 , 20:05   Re: One time Timer
Reply With Quote #3

Quote:
Originally Posted by retsam View Post
CreateTimer(1.0, SomethingHere);

or for client

CreateTimer(1.0, SomethingHere, client);
Yes I've tried that but this timer is repeating on every 1 second.
I need something like Sleep in C;
EasySoft is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 01-15-2010 , 20:09   Re: One time Timer
Reply With Quote #4

Impossible. That timer does not repeat. You must be doing something wrong.

You must have it under some event or something in the game thats making it run multiple times.
retsam is offline
EasySoft
BANNED
Join Date: Jan 2010
Old 01-15-2010 , 20:11   Re: One time Timer
Reply With Quote #5

Quote:
Originally Posted by retsam View Post
Impossible. That timer does not repeat. You must be doing something wrong.

You must have it under some event or something in the game thats making it run multiple times.
Hmmm thank you I'll check that.

Look

on every spawn I give timer for every client.

But the next spawn I want the old timers to bi destroyed.

They all stay in memory?
EasySoft is offline
=MaTi=
Member
Join Date: Jan 2008
Old 01-15-2010 , 20:36   Re: One time Timer
Reply With Quote #6

They do. Just kill them at the end of each round.

EDIT: If player can respawn before the end of the round, you should also kill the timer when he dies.
=MaTi= is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 01-15-2010 , 21:06   Re: One time Timer
Reply With Quote #7

Here's a simple plugin that will send a message 60 seconds after a player spawns. If the player respawns, the old timer will be stopped and a new timer will be started.

PHP Code:
#pragma semicolon 1

#include <sourcemod>

new Handle:g_hSpawnTimers[MAXPLAYERS+1] = {INVALID_HANDLE};

public 
OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
OnClientDisconnect(client)
{
    if (
g_hSpawnTimers[client] != INVALID_HANDLE)
    {
        
KillTimer(g_hSpawnTimers[client]);
        
g_hSpawnTimers[client] = INVALID_HANDLE;
    }
}

public 
Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));

    if (
client && g_hSpawnTimers[client] != INVALID_HANDLE)
    {
        
KillTimer(g_hSpawnTimers[client]);
        
g_hSpawnTimers[client] = INVALID_HANDLE;
    }

    
g_hSpawnTimers[client] = CreateTimer(60.0Timer_CallbackGetClientUserId(client));
}

public 
Action:Timer_Callback(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if (
client 0)
    {
        
PrintToChatAll("Player \"%N\" spawned 60 seconds ago!"client);
        
g_hSpawnTimers[client] = INVALID_HANDLE;
    }

    return 
Plugin_Continue;

I hope this is a good enough example to give you an idea of where to start.
bl4nk is offline
EasySoft
BANNED
Join Date: Jan 2010
Old 01-15-2010 , 21:25   Re: One time Timer
Reply With Quote #8

Ok thank you great example.

Last edited by EasySoft; 01-15-2010 at 21:38.
EasySoft 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:10.


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