AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with this plugin.. (https://forums.alliedmods.net/showthread.php?t=27889)

SweatyBanana 05-01-2006 18:31

Help with this plugin..
 
What is wrong with my code??

I ran it on my server and when I typed /stuck, it said you must be alive to use /stuck...I was very much alive :evil: ...Any help here?...Making this from an old request.

Code:
#include <amxmodx>   #include <amxmisc>   #include <fun>   #define PLUGIN "Stuck"   #define VERSION "1.0"   #define AUTHOR "SweatyBanana"   new stuck[33]; public plugin_init()   {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_cvar("stuck_time", "5")     register_cvar("anounce_Time","60")     register_clcmd("say_team /stuck", "cmd_stuck")     register_clcmd("say /stuck", "cmd_stuck")     set_task(20.0,"advertise");     register_logevent("round_start", 2, "0=World triggered", "1=Round_Start"); } public round_start() {    for(new id = 1; id <= 32; id++)       stuck[id] = 0; } public cmd_stuck()   {       new Time = get_cvar_num("stuck_time");         new id;         if(!is_user_alive(id))        client_print(id, print_chat, "[STUCK] you can only use /stuck if you are alive!")             else if(stuck[id] >= Time)        client_print(id, print_chat, "[STUCK] you can only use /stuck every %i second(s)", Time)             else     {         set_user_noclip (id, 0)         set_task(get_cvar_float("Time"),"unclip");         client_print(id, print_chat, "[STUCK] You have %i second(s) until becoming solid again.", Time);     }     return PLUGIN_HANDLED; } public unclip() {     new id;     set_user_noclip (id) } public advertise() {     client_print(0,print_chat,"[STUCK] say /stuck to become a 'ghost'")     set_task(get_cvar_float("anounce_Time"),"advertise")     return PLUGIN_HANDLED }

v3x 05-01-2006 19:07

lol, simple mistake:
Code:
set_user_noclip (id, 0)
You never set it in the first place.

Also, this is a better way to do the whole "time between uses" thing:
Code:
new g_iTime[33]; public my_func(id) {   new iTime = floatround(get_gametime());   if(iTime - g_iTime[id] < 30)   {     client_print(id , print_chat , "[AMXX] You can only do that command every 30 seconds!");     return PLUGIN_HANDLED;   }   g_iTime[id] = floatround(get_gametime());   return PLUGIN_HANDLED; }
I think that's how it's done ;)

SweatyBanana 05-01-2006 20:04

So does this look good?

Code:
#include <amxmodx>   #include <amxmisc>   #include <fun>   #define PLUGIN "Stuck"   #define VERSION "1.0"   #define AUTHOR "SweatyBanana"   new stuck[33]; new g_secondTime[33]; public plugin_init()   {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_cvar("stuck_time", "5")     register_cvar("anounce_Time","60")     register_clcmd("say_team /stuck", "cmd_stuck")     register_clcmd("say /stuck", "cmd_stuck")     set_task(20.0,"advertise");     register_logevent("round_start", 2, "0=World triggered", "1=Round_Start"); } public round_start() {     for(new id = 1; id <= 32; id++)        stuck[id] = 0; } public cmd_stuck(id) {     new Time = get_cvar_num("stuck_time");     new firstTime = floatround(get_gametime());     if(firstTime - g_secondTime[id] < Time)     {         client_print(id , print_chat , "[AMXX] You can only do that command every %i seconds!", Time);         return PLUGIN_HANDLED;     }     g_secondTime[id] = floatround(get_gametime());     return PLUGIN_HANDLED; } /************************************************************************ public cmd_stuck()   {       new Time = get_cvar_num("stuck_time");         new id;         if(!is_user_alive(id))        client_print(id, print_chat, "[STUCK] you can only use /stuck if you are alive!")             else if(stuck[id] >= Time)        client_print(id, print_chat, "[STUCK] you can only use /stuck every %i second(s)", Time)             else     {         set_user_noclip (id, 1)         set_task(get_cvar_float("Time"),"unclip");         client_print(id, print_chat, "[STUCK] You have %i second(s) until becoming solid again.", Time);     }     return PLUGIN_HANDLED; } ************************************************************************/ public unclip() {     new id;     set_user_noclip (id) } public advertise() {     client_print(0,print_chat,"[STUCK] say /stuck to become a 'ghost'")     set_task(get_cvar_float("anounce_Time"),"advertise")     return PLUGIN_HANDLED }

v3x 05-01-2006 21:31

Yeah but you gotta put the noclip functions in :P

SweatyBanana 05-01-2006 21:44

So hows this :stupid:


Code:
#include <amxmodx>   #include <amxmisc>   #include <fun>   #define PLUGIN "Stuck"   #define VERSION "1.0"   #define AUTHOR "SweatyBanana"   new stuck[33]; new g_secondTime[33]; public plugin_init()   {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_cvar("stuck_time", "5")     register_cvar("anounce_Time","60")     register_clcmd("say_team /stuck", "cmd_stuck")     register_clcmd("say /stuck", "cmd_stuck")     set_task(20.0,"advertise");     register_logevent("round_start", 2, "0=World triggered", "1=Round_Start"); } public round_start() {     for(new id = 1; id <= 32; id++)        stuck[id] = 0; } public cmd_stuck(id) {     new id;         new Time = get_cvar_num("stuck_time");     new firstTime = floatround(get_gametime());         if(!is_user_alive(id))     {         client_print(id, print_chat, "[STUCK] you can only use /stuck if you are alive!")     }         if(firstTime - g_secondTime[id] < Time)     {         client_print(id , print_chat , "[AMXX] You can only do that command every %i seconds!", Time);         return PLUGIN_HANDLED;     }         else     {         set_user_noclip (id, 1)         set_task(get_cvar_float("Time"),"unclip");         client_print(id, print_chat, "[STUCK] You have %i second(s) until becoming solid again.", Time);     }     g_secondTime[id] = floatround(get_gametime());     return PLUGIN_HANDLED; } public unclip() {     new id;     set_user_noclip (id) } public advertise() {     client_print(0,print_chat,"[STUCK] say /stuck to become a 'ghost'")     set_task(get_cvar_float("anounce_Time"),"advertise")     return PLUGIN_HANDLED }

v3x 05-01-2006 21:49

Code:
public cmd_stuck(id) {     //new id; wtf?         new Time = get_cvar_num("stuck_time");     new firstTime = floatround(get_gametime());         if(!is_user_alive(id))     {         client_print(id, print_chat, "[STUCK] you can only use /stuck if you are alive!")         return PLUGIN_HANDLED; // added this return     }         if(firstTime - g_secondTime[id] < Time)     {         client_print(id , print_chat , "[AMXX] You can only do that command every %i seconds!", Time);         return PLUGIN_HANDLED;     }         // removed the else statement     set_user_noclip (id, 1)     set_task(get_cvar_float("Time"),"unclip");     client_print(id, print_chat, "[STUCK] You have %i second(s) until becoming solid again.", Time);     g_secondTime[id] = floatround(get_gametime());     return PLUGIN_HANDLED; }


All times are GMT -4. The time now is 05:12.

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