Raised This Month: $ Target: $400
 0% 

scripting help:anti-Flood for my plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drcopy_wawe
Junior Member
Join Date: Dec 2006
Old 01-13-2007 , 21:57   scripting help:anti-Flood for my plugin
Reply With Quote #1

lets say...
//////////////////////////
bla2~
public plugin_init()
{
register_clcmd("say /restart","recmd")
}

public recmd()
{
server_cmd("sv_restart 1")
}
////////////////////////////

When the client say /restart,the server will sv_restart 1.
If he say /restart again right after that,the server will not sv_restart 1,
as he need to wait for 10 sec before saying /restart again.
I want to prevent flooding.

How to make the plugin works like this?
any1 who is generous enough pls help.
tq in adv
drcopy_wawe is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 01-13-2007 , 23:14   Re: scripting help:anti-Flood for my plugin
Reply With Quote #2

Here is how that would look:

Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "stupok69" new bool:said_restart[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say /restart", "say_restart") } public client_connect(id)     said_restart[id] = false public say_restart(id) {     if(said_restart[id])         return PLUGIN_HANDLED             server_cmd("sv_restart 1")     said_restart[id] = true     set_task(10.0, "prevent_flood", id)     return PLUGIN_CONTINUE } public prevent_flood(id)     said_restart[id] = false
stupok is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 01-13-2007 , 23:30   Re: scripting help:anti-Flood for my plugin
Reply With Quote #3

Absolutely abhorrid.

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #define PLUGIN "Restart" #define VERSION "1.0" #define AUTHOR "Hawk552" new Float:g_LastRestart[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say /restart", "say_restart") } public say_restart(id) {     new Float:Time = halflife_time()     if(Time - g_LastRestart[id] < 10.0)         return PLUGIN_HANDLED         g_LastRestart[id] = Time         server_cmd("sv_restart 1")         return PLUGIN_CONTINUE }

Much more resource efficient.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
stupok
Veteran Member
Join Date: Feb 2006
Old 01-14-2007 , 01:13   Re: scripting help:anti-Flood for my plugin
Reply With Quote #4

Thanks for that hawk, I actually was actually curious about how to use halflife_time() correctly.
stupok is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 01-14-2007 , 04:57   Re: scripting help:anti-Flood for my plugin
Reply With Quote #5

can make it work only for admin with flag "e" ? thx.
Alka is offline
Salepate
Junior Member
Join Date: Jan 2007
Old 01-14-2007 , 07:22   Re: scripting help:anti-Flood for my plugin
Reply With Quote #6

Code:
register_clcmd("say /restart","say_restart",ADMIN_SLAY);

Here is it. You should take a look in other plugins source to see how it works, or just watch includes or the wiki.
Salepate is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 01-14-2007 , 07:44   Re: scripting help:anti-Flood for my plugin
Reply With Quote #7

Code:
#include <amxmodx> #include <amxmisc> #include <engine> new Float:g_LastRestart[33] public plugin_init() {     register_plugin("Restart", "1.0", "Hawk552")     register_clcmd("say /restart", "say_restart", ADMIN_SLAY) } public say_restart(id, level, cid) {     if ( ! cmd_access(id, level, cid, 0) )         return     new Float:Time = halflife_time()     if(Time - g_LastRestart[id] < 10.0)         return         g_LastRestart[id] = Time         server_cmd("sv_restart 1") }
[ --<-@ ] Black Rose is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 01-14-2007 , 08:03   Re: scripting help:anti-Flood for my plugin
Reply With Quote #8

thx..Black rose.. +karma
Alka is offline
Salepate
Junior Member
Join Date: Jan 2007
Old 01-14-2007 , 08:19   Re: scripting help:anti-Flood for my plugin
Reply With Quote #9

if you put ADMIN_SLAY you don't need to use cmd_access();
is it wrong ?

besides you wrote
Code:
if ( ! cmd_access(id, level, cid, 0) )

isn't 0 supposed to be ADMIN_ALL ? and if it's the case then none of the players (Admin included) can use the command.

Tell me if I am wrong.
Salepate is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 01-14-2007 , 09:40   Re: scripting help:anti-Flood for my plugin
Reply With Quote #10

Quote:
Originally Posted by Salepate View Post
if you put ADMIN_SLAY you don't need to use cmd_access();
is it wrong ?

besides you wrote
Code:
if ( ! cmd_access(id, level, cid, 0) )


isn't 0 supposed to be ADMIN_ALL ? and if it's the case then none of the players (Admin included) can use the command.

Tell me if I am wrong.
No, that's the amount of args, but it will never work. I don't know why he used cmd_access, just use this:

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #define ACCESS ADMIN_SLAY new Float:g_LastRestart[33] public plugin_init() {     register_plugin("Restart","1.0","Hawk552")     register_clcmd("say /restart","say_restart",ACCESS) } public say_restart(id) {     if(!(get_user_flags(id) & ACCESS))         return         new Float:Time = halflife_time()     if(Time - g_LastRestart[id] < 10.0)         return         g_LastRestart[id] = Time         server_cmd("sv_restart 1") }

Also, please don't screw with the indentation and put your own when you're adding 1 line. Not only does K&R look worse, it's just stupid to make changes like that.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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:28.


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