Raised This Month: $ Target: $400
 0% 

[CS:GO] Need help with timers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-20-2016 , 07:17   [CS:GO] Need help with timers
Reply With Quote #1

Hello, I'm making plugin that uses timers and I'm sitting here like 4 hours straight, and simply cannot kill timer...
Super simple description:
On player spawn > start timer
On player death > stop timer

Code:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <cstrike>

Handle DelayTimer[MAXPLAYERS+1];
Handle ScoreTimer[MAXPLAYERS+1];

public 
OnPluginStart()
{
    
HookEvent("player_death"OnPlayerDeath);
    
HookEvent("player_spawn"OnPlayerSpawnEvent);
}

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

    
PrintToChat(pClient"[DEBUG] START_DELAY");
    
DelayTimer[pClient] = CreateTimer(30.0delayGetEventInt(event"userid"), TIMER_REPEAT);
    
ScoreTimer[pClient] = CreateTimer(15.9getpointGetEventInt(event"userid"), TIMER_REPEAT);
}

public 
OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
pClient GetClientOfUserId(GetEventInt(event"userid"));
    
PrintToChat(pClient"[DEBUG] KILLTIMERS");
    
KillTimer(DelayTimer[pClient]);
    
KillTimer(ScoreTimer[pClient]);
    
DelayTimer[pClient] = null;
    
ScoreTimer[pClient] = null;
}

public 
Action:delay(Handle:timerany:userid)
{
    new 
pClient GetClientOfUserId(userid);
    
PrintToChat(pClient"[DEBUG] START_SCORING");
}

public 
Action:getpoint(Handle:timerany:userid)
{
    
//do stuff

All debug messages are shown, but when player dies, timers are still running (they are not killed)...

Can you guys please help me out because i run out of ideas :/?

ps: i know about existence of this: "https://wiki.alliedmods.net/Timers_(SourceMod_Scripting)"
__________________


Last edited by Jcrr; 07-20-2016 at 07:36.
Jcrr is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 07-20-2016 , 10:16   Re: [CS:GO] Need help with timers
Reply With Quote #2

In the call back set the timer Handle to null. Use delete instead of KillTimer:

PHP Code:
public Action:delay(Handle:timerany:userid)
{
    new 
pClient GetClientOfUserId(userid);
    
PrintToChat(pClient"[DEBUG] START_SCORING");

    
DelayTimer[GetClientOfUserId(userid)] = null;

PHP Code:
delete DelayTimer[pClient

Last edited by Michael Shoe Maker; 07-20-2016 at 10:19.
Michael Shoe Maker is offline
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-20-2016 , 14:20   Re: [CS:GO] Need help with timers
Reply With Quote #3

Quote:
Originally Posted by Michael Shoe Maker View Post
In the call back set the timer Handle to null. Use delete instead of KillTimer:

PHP Code:
public Action:delay(Handle:timerany:userid)
{
    new 
pClient GetClientOfUserId(userid);
    
PrintToChat(pClient"[DEBUG] START_SCORING");

    
DelayTimer[GetClientOfUserId(userid)] = null;

PHP Code:
delete DelayTimer[pClient
Can you be more precise? Because i can't find single thing related to "delete blahblah" in sourcemod
__________________

Jcrr is offline
nOProblem
New Member
Join Date: Mar 2016
Old 07-21-2016 , 06:56   Re: [CS:GO] Need help with timers
Reply With Quote #4

PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#pragma semicolon 1
#pragma newdecls required


Handle delayTimer[MAXPLAYERS+1];
Handle scoreTimer[MAXPLAYERS+1];


public 
void OnPluginStart()
{
    
HookEvent("player_spawn"PlayerSpawn);
    
HookEvent("player_death"PlayerDeath);
}

public 
Action PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));

    
PrintToChat(client"[DEBUG] START_DELAY");
    
    
delayTimer[client] = CreateTimer(30.0DelayclientTIMER_REPEAT);
    
scoreTimer[client] = CreateTimer(15.9GetPointclientTIMER_REPEAT);
}

public 
Action Delay(Handle timerany client)
{
    
PrintToChat(client"[DEBUG] START_SCORING");
    
    
// do stuff here..
    
    
    
delayTimer[client] = null;
    
    return 
Plugin_Stop;
}

public 
Action GetPoint(Handle timerany client)
{
    
// do stuff here..
    
    
    
scoreTimer[client] = null;
    
    return 
Plugin_Stop;
}

public 
Action PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
    
PrintToChat(client"[DEBUG] KILLTIMERS");
    
    if(
delayTimer[client] != null)
    {
        
CloseHandle(delayTimer[client]);
        
delayTimer[client] = null;
    }
    
    if(
scoreTimer[client] != null)
    {
        
CloseHandle(scoreTimer[client]);
        
scoreTimer[client] = null;
    }
}

public 
void OnClientDisconnect(int client)
{
    if(
delayTimer[client] != null)
    {
        
CloseHandle(delayTimer[client]);
        
delayTimer[client] = null;
    }
    
    if(
scoreTimer[client] != null)
    {
        
CloseHandle(scoreTimer[client]);
        
scoreTimer[client] = null;
    }

This is just an example of how you could do it.. I added OnClientDisconnect, just for the safety..
The keyword "delete" is also an option, but better try it with this version, because "delete" is not documented for Timers..
nOProblem is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 07-21-2016 , 07:20   Re: [CS:GO] Need help with timers
Reply With Quote #5

delete is the new syntax I think it = closehandle
__________________
8guawong is offline
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-21-2016 , 08:02   Re: [CS:GO] Need help with timers
Reply With Quote #6

nOProblem
I tried to do it like this way, but it wont work for 2 reasons:
1. In exactly your version, all timers work only once (1 time loop)
2. If i redo it to repeat the timers, this will happend:

When player will respawn before timer can check if it's null, they simply wont end, and there will be 2 timers running (they will stack). And in addition i tried to do it like this earlier.

Only option working for me, will be instakill any timer at any time.
__________________

Jcrr is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 07-21-2016 , 08:24   Re: [CS:GO] Need help with timers
Reply With Quote #7

i think some1 had this problem before
its b/c player_spawn fire twice or something before they actually spawns
so check if client is alive or something before creating a timer
__________________
8guawong is offline
Jcrr
Senior Member
Join Date: Jul 2015
Old 07-21-2016 , 08:39   Re: [CS:GO] Need help with timers
Reply With Quote #8

8guawong
I'm aware about first spawn twice timer start, it's very easy to solve, but still, it wont help with kill timers.
If player will die, and then timer will check if it should run, it's ok.
If player will die, timer won't check if it should run, because player will respawn, it's not ok.

Thats why i need method to instakill timer, so i won't rely on timers loop checks, timers variable checks and so on.
__________________

Jcrr is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 07-21-2016 , 09:43   Re: [CS:GO] Need help with timers
Reply With Quote #9

do a start_timer[client] = true on player_spawn and start_timer[client] = false;

then in your timercallback do

if (!start_timer[client])
return Plugin_Stop;

XDDDD
__________________
8guawong is offline
nOProblem
New Member
Join Date: Mar 2016
Old 07-21-2016 , 11:13   Re: [CS:GO] Need help with timers
Reply With Quote #10

Quote:
nOProblem
I tried to do it like this way, but it wont work for 2 reasons:
1. In exactly your version, all timers work only once (1 time loop)
2. If i redo it to repeat the timers, this will happend:

When player will respawn before timer can check if it's null, they simply wont end, and there will be 2 timers running (they will stack). And in addition i tried to do it like this earlier.

Only option working for me, will be instakill any timer at any time.
I actually donīt know, what your plugin should do, thatīs why I canīt add some bools in the events.. and like 8guawong said, you have to add some bools to your plugin for sure..
Give us more information about your plugin.. What should it do? So we can help you a way better with the timers
nOProblem 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 17:37.


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