View Single Post
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-26-2018 , 12:33   Re: [TF2] Help with timer
Reply With Quote #6

Quote:
Originally Posted by mug1wara View Post
You could just use AddCommandListener, also it didn't work with GivePlayerAmmo for some reason :/
Here's a sample plugin:

PHP Code:
#include <sdktools>

#pragma semicolon 1

public void OnMapStart()
{
    
AddCommandListener(Cmd_Callback"+attack"); /* Mouse1 */
    
AddCommandListener(Cmd_Callback"+attack2"); /* Mouse2 I think, not sure */
}

public 
Action Cmd_Callback(int iClient, const char[] sCommandint iArgs)
{
    
CreateTimer(1.5Timer_Ammo_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_Ammo(Handle hTimer)
{    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (
IsPlayerAlive(i))
            {
                
int iAmmo GetEntProp(iProp_Data"m_iAmmo"); /* Get ammo count */
                
                
SetEntProp(iProp_Sned"m_iClip1"0); /* Remove ammo */
                
                
SetEntProp(iProp_Send"m_iClip1"iAmmo 1); /* Give the player it's original ammo, but + 1 */
            
}
        }
    }
    
    return 
Plugin_Continue;

+attack and similar aren't commands, they are "buttons" and cannot be intercepted via command listeners.

Please do not post false or misleading information.

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

public void OnPluginStart()
{
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i))
        {
            if(...) 
// check if the client needs ammo and maybe check if that client is not in +attack with GetClientButtons()
            
{
                
GiveAmmo(i); // your function for ammo
            
}
        }
    }

use this logic.
That would only happen when the plugin starts, which is usually before there are even any players in the server. This code does nothing.
__________________

Last edited by ddhoward; 06-26-2018 at 12:34.
ddhoward is offline