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

Create Timers on events


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZeeBOB
Junior Member
Join Date: Jul 2009
Old 10-24-2009 , 11:09   Create Timers on events
Reply With Quote #1

Hi,

My plugin creates a panel with a bunch of random information inside of it.
I am currently calling this panel by a command (for testing).

PHP Code:
DrawHud()
{
    
decl String:sTempString[1024];
    
decl String:name[MAX_NAME_LENGTH];
    
    new 
Handle:specHUD CreatePanel();
    new 
i;
    for (
i=1;i<L4D_MAXCLIENTS_PLUS1;i++)
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == && GetEntProp(iProp_Send"m_zombieClass") == 5)
        {
            ...
        }
    }
    for (
i=1;i<L4D_MAXCLIENTS_PLUS1;i++) 
    {
        if(
IsClientInGame(i)) 
        {
            
SendPanelToClient(specHUDiMenu_HUDPanelHUD_PANEL_LIFETIME);            
        }
    }
    if(
menuPanel != INVALID_HANDLE)
    {
        
CloseHandle(menuPanel);
    }
    
menuPanel specHUD;

I basically need the panel to start showing when a tank spawns and disappears when the tank dies.

I have tried adding:

PHP Code:
public OnPluginStart()
  {
      
HookEvent("tank_spawn"Event_TankSpawn);
  }

public 
Action:Event_TankSpawn(Handle:event, const String:name[], bool:dontBroadcast)
 {
     
CreateDataTimer(1.0showHUD_TIMER_REPEAT);
 } 
The error I am getting is:
error 100: function prototypes do not match

Am I going about this the wrong way? Any help much appreciated!
ZeeBOB is offline
Chris-_-
SourceMod Donor
Join Date: Oct 2008
Old 10-24-2009 , 11:13   Re: Create Timers on events
Reply With Quote #2

What line?
Chris-_- is offline
MockingBird
Member
Join Date: Mar 2005
Old 10-24-2009 , 11:34   Re: Create Timers on events
Reply With Quote #3

I think its because your 'showHUD' function does not match the function type that should be passed into CreateTimer.

'showHUD' should look something like this:
PHP Code:
public Action:showHUD(Handle:timerany:client
edit: If you look at the funcwiki:
PHP Code:
Any of the following prototypes will work for a timed function.
funcenum Timer
{
    
/**
      * Called when the timer interval has elapsed.
      * 
      * @param timer            Handle to the timer object.
      * @param hndl            Handle passed to CreateTimer() when timer was created.
      * @return                Plugin_Stop to stop a repeating timer, any other value for
      *                        default behavior.
      */
    
Action:public(Handle:timerHandle:hndl),
    
/**
      * Called when the timer interval has elapsed.
      * 
      * @param timer            Handle to the timer object.
      * @param data            Data passed to CreateTimer() when timer was created.
      * @return                Plugin_Stop to stop a repeating timer, any other value for
      *                        default behavior.
      */
    
Action:public(Handle:timerany:data),
    
/**
      * Called when the timer interval has elapsed.
      * 
      * @param timer            Handle to the timer object.
      * @return                Plugin_Stop to stop a repeating timer, any other value for
      *                        default behavior.
      */
    
Action:public(Handle:timer),
}; 

Last edited by MockingBird; 10-24-2009 at 11:36.
MockingBird is offline
ZeeBOB
Junior Member
Join Date: Jul 2009
Old 10-24-2009 , 11:45   Re: Create Timers on events
Reply With Quote #4

Wow, thanks for the response.

I suppose there's no point keeping this secret because its for the Community anyway

I tried what you suggested but got error:

(30) : error 034: argument does not have a default value (argument 3)

This is the full code so please pick at it and let me know where I went wrong.

Also, if you could show me how I would make it kill the menu when the tank dies that would be fantastic!

PHP Code:
#include <sourcemod>
#include <sdktools>

#define L4D_MAXCLIENTS_PLUS1 (MaxClients+1)

new Handle:menuPanel INVALID_HANDLE;

public 
Plugin:myinfo 
{
    
name "CyberGamer Spectator HUD",
    
author "ZeeBOB",
    
description "Adds a HUD to spectators to easily see the infected's status",
    
version "1.2",
    
url ""
}

public 
OnPluginStart()
{
    
HookEvent("tank_spawn"Event_TankSpawn);
}

public 
Action:showHUD(Handle:timer)
{
    
DrawHUD();
}

public 
Action:Event_TankSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
     
CreateDataTimer(1.0showHUD_TIMER_REPEAT);
}

DrawHUD()
{
    
decl String:sTempString[1024];
    
decl String:name[MAX_NAME_LENGTH];
    
    new 
Handle:specHUD CreatePanel();
    new 
i;
    for (
i=1;i<L4D_MAXCLIENTS_PLUS1;i++)
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == && GetEntProp(iProp_Send"m_zombieClass") == 5)
        {
            
GetClientName(inamesizeof(name));
            if (
strlen(name) > 25)
            {
                
name[22] = '.';
                
name[23] = '.';
                
name[24] = '.';
                
name[25] = 0;
            }
            
Format(sTempString1024"%s"name);
            
DrawPanelText(specHUDsTempString);
            if (
IsPlayerAlive(i))
            {
                
Format(sTempStringsizeof(sTempString), "->   %dHP"GetClientHealth(i));
            }
            else
            {
                
sTempString "->   Dead";
            }
            
DrawPanelText(specHUDsTempString);
            if(!
IsFakeClient(i))
            {
                
Format(sTempStringsizeof(sTempString), "Tank Control: %d%"100-GetEntProp(iProp_Send"m_frustration"));
            }
            else 
            {
                
sTempString "->  AI Control!";
            }
            
DrawPanelText(specHUDsTempString);
        }
    }
    for (
i=1;i<L4D_MAXCLIENTS_PLUS1;i++) 
    {
        if(
IsClientInGame(i)) 
        {
            
SendPanelToClient(specHUDiMenu_HUDPanel1);            
        }
    }
    if(
menuPanel != INVALID_HANDLE)
    {
        
CloseHandle(menuPanel);
    }
    
menuPanel specHUD;
}

public 
Menu_HUDPanel(Handle:menuMenuAction:actionparam1param2



Last edited by ZeeBOB; 10-24-2009 at 11:49.
ZeeBOB is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 10-25-2009 , 10:01   Re: Create Timers on events
Reply With Quote #5

Try this
PHP Code:
CreateTimer(1.0showHUD_TIMER_REPEAT); 
instead of
PHP Code:
CreateDataTimer(1.0showHUD_TIMER_REPEAT); 
As for killing the timer on tank death you need to hook the tanks death, and then you would need to kill the timer. To kill the timer you need to give it a handle. Like so,
PHP Code:
#include <sourcemod>
#include <sdktools>
#define L4D_MAXCLIENTS_PLUS1 (MaxClients+1)
new Handle:menuPanel INVALID_HANDLE;
new 
Handle:menuTimer INVALID_HANDLE;
public 
Plugin:myinfo 
{
    
name "CyberGamer Spectator HUD",
    
author "ZeeBOB",
    
description "Adds a HUD to spectators to easily see the infected's status",
    
version "1.2",
    
url ""
}
public 
OnPluginStart()
{
    
HookEvent("tank_spawn"Event_TankSpawn);
    
HookEvent("tank_killed"TankKilled);
}
public 
Action:showHUD(Handle:timer)
{
    
DrawHUD();
}
public 
Action:Event_TankSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
      
menuTimer CreateTimer(1.0showHUD_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public 
Action:TankKilled(Handle:event, const String:name[], bool:dontBroadcast)
{
      if(
menuTimer != INVALID_HANDLE)
      {
            
KillTimer(menuTimer);
            
menuTimer INVALID_HANDLE;
      }
}
DrawHUD()
{
    
decl String:sTempString[1024];
    
decl String:name[MAX_NAME_LENGTH];
 
    new 
Handle:specHUD CreatePanel();
    new 
i;
    for (
i=1;i<L4D_MAXCLIENTS_PLUS1;i++)
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == && GetEntProp(iProp_Send"m_zombieClass") == 5)
        {
            
GetClientName(inamesizeof(name));
            if (
strlen(name) > 25)
            {
                
name[22] = '.';
                
name[23] = '.';
                
name[24] = '.';
                
name[25] = 0;
            }
            
Format(sTempString1024"%s"name);
            
DrawPanelText(specHUDsTempString);
            if (
IsPlayerAlive(i))
            {
                
Format(sTempStringsizeof(sTempString), "->   %dHP"GetClientHealth(i));
            }
            else
            {
                
sTempString "->   Dead";
            }
            
DrawPanelText(specHUDsTempString);
            if(!
IsFakeClient(i))
            {
                
Format(sTempStringsizeof(sTempString), "Tank Control: %d%"100-GetEntProp(iProp_Send"m_frustration"));
            }
            else 
            {
                
sTempString "->  AI Control!";
            }
            
DrawPanelText(specHUDsTempString);
        }
    }
    for (
i=1;i<L4D_MAXCLIENTS_PLUS1;i++) 
    {
        if(
IsClientInGame(i)) 
        {
            
SendPanelToClient(specHUDiMenu_HUDPanel1);            
        }
    }
    if(
menuPanel != INVALID_HANDLE)
    {
        
CloseHandle(menuPanel);
    }
    
menuPanel specHUD;
}
public 
Menu_HUDPanel(Handle:menuMenuAction:actionparam1param2


Its early so if it dosnt compile sorry but thats pretty much how you would kill the timer.

Last edited by Dr!fter; 10-25-2009 at 10:15.
Dr!fter 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 07:55.


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