AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   plugin improvement - anti name flood (https://forums.alliedmods.net/showthread.php?t=84894)

ehha 02-02-2009 14:01

plugin improvement - anti name flood
 
1 Attachment(s)
I made this plugin because i didn't find one that suits my needs.

Functionality:

-scans for name change & it increments the counter (ct)
-when ct reaches 3 within 20s form the first change it displays a message
-when ct reaches 4 within 20s from the first change it kicks the player

Although it works, it seems that the print_chat message & the default game message "x changed name to y" appear with a small time delay on my machine.

I would like to know if there are any performance changes that can be made.
I'm still in the process of learning so i may induced some cpu intensive or inefficient code.

Thank you.

ehha 02-16-2009 19:20

Re: plugin improvement - anti name flood
 
Bump! :|
So i made no mistakes? Nothing to improve? Just tell me and I'll move along :D

Speed! 02-16-2009 19:58

Re: plugin improvement - anti name flood
 
Quote:

Originally Posted by ehha (Post 762855)
Bump! :|
So i made no mistakes? Nothing to improve? Just tell me and I'll move along :D

rewrote for you :D
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "name flood"
#define VERSION "0.1"
#define AUTHOR "camper"
#define ID_FLOOD (taskid - TASK_FLOOD)
//#pragma semicolon 1 useless :(

enum (+= 100)
{
    
TASK_FLOOD
}

new 
ct[33], nft;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
nft register_cvar("amx_name_flood_time""20");
}

public 
client_putinserver(id)
{
    
set_task(nft"decrease_flood"id+TASK_FLOOD)
    
ct[id] = 0;
}

public 
decrease_flood(taskid)
{
    if (
ct[ID_FLOOD] > 0)
        
ct[ID_FLOOD]  -= 1
    set_task
(nft"decrease_flood"ID_FLOOD+TASK_FLOOD)
}

public 
client_disconnect(id)
{
    
remove_task(id+TASK_FLOOD)
}

public 
client_infochanged(id)
{
    new 
newname[32], oldname[32];
    
get_user_info(id"name"newname,31);
    
get_user_name(idoldname31);
        
    if(
equal(newnameoldname))
        return 
PLUGIN_HANDLED;
    
    
ct[id]++
    switch (
ct[id])
    {
        case 
3:
        {
            
client_print(idprint_chat"*** Nick change flood! Stop or you will be kicked! ***");
            
client_print(idprint_chat"*** Nick change flood! Stop or you will be kicked! ***");
        }
        case 
4:
        {
            
server_cmd("kick #%d ^"%s^""get_user_userid(id), "Kicked due to name change flood.");
            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_HANDLED


look at the changes, how simple is now, and how better (using tasks for decreasing flood count, and removing them.)

fysiks 02-16-2009 20:49

Re: plugin improvement - anti name flood
 
@Speed!

PHP Code:

set_task(nft"decrease_flood"id+TASK_FLOOD

ntf is a cvar pointer not a floating point number, you can't use it there.

Spunky 02-16-2009 20:53

Re: plugin improvement - anti name flood
 
Code:
set_task(float(get_pcvar_num(nft)), "decrease_flood", id + TASK_FLOOD)

fysiks 02-16-2009 21:05

Re: plugin improvement - anti name flood
 
You can use get_pcvar_float(nft)

Drak 02-17-2009 01:33

Re: plugin improvement - anti name flood
 
Whoa, I didn't know you can use 'goto' in Pawn. Ethier way, don't use tasks.
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "name flood" #define VERSION "0.1" #define AUTHOR "camper" new ct[33] new Float:g_LastTime[33] new nft public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     nft = register_cvar("amx_name_flood_time", "20"); } public client_putinserver(id) {     ct[id]=0;     g_LastTime[id] = 0.0 } public client_infochanged(id) {     static sNewName[33],sOldName[33]     get_user_info(id,"name",sNewName,32)     get_user_name(id,sOldName,32);             if(equal(sNewName,sOldName))         return PLUGIN_HANDLED;         new Float:Time = get_gametime();     switch(++ct[id])     {         case 3:         {             if(Time - g_LastTime[id] <= get_pcvar_float(nft))             {                 client_print(id, print_chat, "*** Nick change flood! Stop or you will be kicked! ***");                 client_print(id, print_chat, "*** Nick change flood! Stop or you will be kicked! ***");             }         }         case 4:         {             if(Time - g_LastTime[id] <= get_pcvar_float(nft))             {                 server_cmd("kick #%d ^"%s^"", get_user_userid(id), "Kicked due to name change flood.");                 ct[id] = 0             }         }     }     g_LastTime[id] = Time     return PLUGIN_CONTINUE }

ehha 02-17-2009 09:15

Re: plugin improvement - anti name flood
 
@Drak: I don't know why i didn't use a switch & nice job incrementing the counter in the switch condition :D

Thank you all.

Drak 02-17-2009 12:46

Re: plugin improvement - anti name flood
 
Oops, you might want to move "g_LastTime[id] = Time" AFTER the switch.

ehha 02-17-2009 17:53

Re: plugin improvement - anti name flood
 
I might? I must :D, perhaps you might want to edit the post if somebody (inexperienced) wants to use this.


All times are GMT -4. The time now is 01:38.

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