AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   scripting help:anti-Flood for my plugin (https://forums.alliedmods.net/showthread.php?t=49838)

drcopy_wawe 01-13-2007 21:57

scripting help:anti-Flood for my plugin
 
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

stupok 01-13-2007 23:14

Re: scripting help:anti-Flood for my plugin
 
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

Hawk552 01-13-2007 23:30

Re: scripting help:anti-Flood for my plugin
 
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.

stupok 01-14-2007 01:13

Re: scripting help:anti-Flood for my plugin
 
Thanks for that hawk, I actually was actually curious about how to use halflife_time() correctly.

Alka 01-14-2007 04:57

Re: scripting help:anti-Flood for my plugin
 
can make it work only for admin with flag "e" ? thx. :)

Salepate 01-14-2007 07:22

Re: scripting help:anti-Flood for my plugin
 
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.

[ --<-@ ] Black Rose 01-14-2007 07:44

Re: scripting help:anti-Flood for my plugin
 
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") }

Alka 01-14-2007 08:03

Re: scripting help:anti-Flood for my plugin
 
thx..Black rose..:up: +karma

Salepate 01-14-2007 08:19

Re: scripting help:anti-Flood for my plugin
 
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.

Hawk552 01-14-2007 09:40

Re: scripting help:anti-Flood for my plugin
 
Quote:

Originally Posted by Salepate (Post 427080)
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.


All times are GMT -4. The time now is 22:28.

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