Raised This Month: $ Target: $400
 0% 

Command limit for every player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yatchi
Member
Join Date: Feb 2011
Location: Brazil
Old 09-15-2013 , 14:08   Command limit for every player
Reply With Quote #1

Hi!

I want to make a limit for using a command, like 5 per round (5 for every player)

But how?
yatchi is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 09-15-2013 , 14:17   Re: Command limit for every player
Reply With Quote #2

I've wrote example stuff:
PHP Code:
new PootisUse[MAXPLAYERS+1] = // Register for all players PootisUse mini-database

public OnPluginStart()
{
    
RegConsoleCmd("sm_pootis"Pootis"Pootis Pow!"// create command in chat !pootis or /pootis 
    
    
HookEvent("teamplay_round_start"RoundStartEventHookMode_Post// hook round start TF2
}

public 
Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
PootisRefresh() // each round reset all pootis limit to 5
}

public 
Action:Pootis(clientargs)
{
    if(
PootisUse[client] > 0// if player has more pootis uses than zero
    
{
        
PootisUse[client] -= // decrease use by one
        
PrintToChatAll("POOTIS"// Replace this with stuff you want to do when you execute command
    
}
    else
    {
        
PrintToChat(client"[SM] You can't use anymore 'Pootis' Command"// Print message that you cnat use anymore stuff
    
}
}

stock PootisRefresh() // Set all player pootis use limit to 5
{
    for(new 
1<= MaxClientsi++) // target all players
    
{
        if(
IsClientInGame(i) && !IsFakeClient(i)) // if player is in game and is not a bot
        
{
            
PootisUse[i] = 5
        
}
    }

__________________
...

Last edited by Oshizu; 09-15-2013 at 14:18.
Oshizu is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-15-2013 , 14:58   Re: Command limit for every player
Reply With Quote #3

@Oshizu

Anyone who joins a slot mid-round after the previous person used up all 5 commands will find he can't use the command. Reset it to 5 every connect or disconnect.

Similarly, if the player wasn't in-game yet when the round began then entered the game, he would still be on the number from the previous person's round. Just reset to five for everyone, regardless of whether they're a bot or not in-game..

Need a return case for Pootis.

PootisUse[client]-- is arguably more readable than PootisUse[client] -= 1

May as well use EventHookMode_PostNoCopy instead.


@yatchi

Depending on your usage, ensure the client provided valid arguments (or lack thereof) to the command before subtracting one.
__________________
11530 is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 09-15-2013 , 15:50   Re: Command limit for every player
Reply With Quote #4

Or you can use adt trie with authid to check for unique client.
xf117 is offline
Send a message via ICQ to xf117
yatchi
Member
Join Date: Feb 2011
Location: Brazil
Old 09-15-2013 , 15:51   Re: Command limit for every player
Reply With Quote #5

@Oshizu

Thank you! Worked fine here!

@11530

Thank you too, for your tips and advices! Actually, I put the "reset" function on player spawn, so there's no way to miss the reset (because only alive players can use the command)
yatchi 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 22:27.


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