Raised This Month: $ Target: $400
 0% 

Timer Problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zapulater
New Member
Join Date: Nov 2012
Old 11-07-2012 , 09:53   Timer Problems
Reply With Quote #1

Hello, I started Sourcepawn a few days ago and now I'm having trouble compiling this code. On the CreateTimer line, it says "function prototypes do not match."
Code:
#include <sourcemod> 
#include <sdktools>

public Plugin:myinfo =
{
   name = "Roll the Dice",
   description = "Type !rtd to roll the dice. Okay?",    
   author = "White Noise/Zapulater/Fishyboy",    
   version = "1.0",    
   url = "www.zpdcom.forumotion.com/"        
}


public OnPluginStart()
{
    PrintToServer("Type !rtd to roll the dice")
    RegConsoleCmd("sm_rtd", CommandRtd)
}

public Action:CommandRtd(client, args)
{
    new rtd = GetRandomInt(1,7)
    switch (rtd)
    {
        case 1:
        {
            SetEntityHealth(client, GetClientHealth(client)-15)
            PrintToChat( client, "You have lost 15 health!" )
        }
        case 2:
        {
            SetEntityRenderColor(client, GetRandomInt(1,255), GetRandomInt(1,255), GetRandomInt(1,255), GetRandomInt(100,255))
            PrintToChat( client, "Your color has been changed!" )
        }
        case 3:
        {
            PrintToChat( client, "You have received a useless message!" )
        }
        case 4:
        {
            new rand = GetRandomInt(-5,5)
            SlapPlayer( client, rand, false )
            PrintToChat( client, "You have been launched into the air and your health has been changed by %d", rand )
        }
        case 5:
        {
            SetEntityHealth(client, GetClientHealth(client)+15)
            PrintToChat( client, "You have gained 15 health!" )
        }
        case 6:
        {
            GivePlayerItem( client, "pistol_magnum", 1 )
            PrintToChat( client, "You have gained a magnum!" )
        }
        case 7:
        {
            CreateTimer( 3.0, Timer_Regen, _, TIMER_REPEAT ) // This is the line with the problem.
        }
    }
        
}

public Action:Timer_Regen( client ) 
{
    new health = GetClientHealth(client)
    new sum = health
    if (health>=100 && IsPlayerAlive(client)==true)
    {
        sum = health
    }
    else
    {
        sum = health+1
    }
    SetEntityHealth( client, sum )
    return Plugin_Continue;
}
I'm probably making a noob mistake here, but a brief reply on what I'm doing wrong would help.
Thanks!

Last edited by Zapulater; 11-07-2012 at 09:56.
Zapulater is offline
SEGnosis
Senior Member
Join Date: Oct 2012
Old 11-07-2012 , 12:23   Re: Timer Problems
Reply With Quote #2

Code:
native Handle:CreateTimer(Float:interval, Timer:func, any:data=INVALID_HANDLE, flags=0)
You need to pass INVALID_HANDLE as the third parameter. Also you are treating the handle of the timer that is passed into the callback as client id when it is not.
SEGnosis is offline
Glite
Senior Member
Join Date: Sep 2011
Location: Ukraine
Old 11-07-2012 , 12:27   Re: Timer Problems
Reply With Quote #3

PHP Code:
public Action:Timer_Regen(Handle:timer
Glite is offline
Zapulater
New Member
Join Date: Nov 2012
Old 11-07-2012 , 13:02   Re: Timer Problems
Reply With Quote #4

Thank you! The help is very much appreciated!
Zapulater is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 11-07-2012 , 13:03   Re: Timer Problems
Reply With Quote #5

Quote:
Originally Posted by Glite View Post
PHP Code:
public Action:Timer_Regen(Handle:timerany:client
Changed yours above (guessing what the author wants)... In addition:

when creating the timer, don't forget to pass the client since you're using it in your callback:
PHP Code:
CreateTimer3.0Timer_RegenclientTIMER_REPEAT 
__________________
View my Plugins | Donate

Last edited by TnTSCS; 11-07-2012 at 13:03.
TnTSCS 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 14:44.


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