AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Looked high and low, but no avail. (https://forums.alliedmods.net/showthread.php?t=24735)

DataMatrix 03-01-2006 17:35

Looked high and low, but no avail.
 
I'm having problems with my code, it was working perfectly before, but now it doesn't want to work at all.

It is suppost to add a random number to the database every so many minutes. It was working perfectly before but now I add/change a few things it doesn't work anymore.

Any help greatly appreciated.

Code:
/* Advanced SleepMod v1.0 for TSRP Programmed by DataMatrix Original idea by GHC.Chronic */ #include <amxmodx> #include <amxmisc> #include <fun> #include <dbi> new bool:asleep[33] new Sql:dbc new Result:result public plugin_init() {     register_plugin("Advanced SleepMod for TSRP","1.0","DataMatrix")     register_cvar("sv_healfull","0")     register_cvar("sv_maxhealth","100")     register_cvar("sv_minhealth","50")     register_clcmd("say /sleep","bsleep")     register_event("DeathMsg","death_msg","a")         set_task(1.0,"sql_init")     set_task(20.0,"tiredness",0,"",0,"b") } public plugin_precache() {     precache_sound("misc/snore.wav")     precache_sound("misc/yawn.wav") } public client_connect(id) {     asleep[id]=false } public client_disconnect(id) {     asleep[id]=false } public client_putinserver(id) {     set_task(8.0,"notify",id) } public notify(id) {     client_print(id,print_console,"This server is running Advanced SleepMod v1.0 for TSRP by DataMatrix!^n")     client_print(id,print_console,"Commands: /sleep^n")     return PLUGIN_HANDLED } public sql_init() {     new host[64],username[33],password[32],dbname[32],error[32]         get_cvar_string("economy_mysql_host",host,64)     get_cvar_string("economy_mysql_user",username,32)     get_cvar_string("economy_mysql_pass",password,32)     get_cvar_string("economy_mysql_db",dbname,32)     dbc = dbi_connect(host,username,password,dbname,error,32)         if (dbc == SQL_FAILED)     {         server_print("[SleepMod] Cannot connect to mySQL database.^n")     }     else     {         server_print("[SleepMod] Connected to mySQL database.^n")     }         return PLUGIN_HANDLED } public is_user_database(id) {     if(dbc < SQL_OK) return PLUGIN_HANDLED     new authid[32], query[256]         get_user_authid(id,authid,31)     format(query,255,"SELECT name FROM money WHERE steamid='%s'",authid)     result = dbi_query(dbc,query)         if(dbi_nextrow(result) > 0)     {         dbi_free_result(result)         return PLUGIN_CONTINUE     }     dbi_free_result(result)         return PLUGIN_HANDLED } public edit_value(id,table[],index[],func[],amount) {     if(dbc < SQL_OK) return PLUGIN_HANDLED         new authid[32], query[256]     get_user_authid(id,authid,31)         if(equali(func,"="))     {         format(query,255,"UPDATE %s SET %s=%i WHERE steamid='%s'",table,index,amount,authid)     }     else     {         format(query,255,"UPDATE %s SET %s=%s%s%i WHERE steamid='%s'",table,index,index,func,amount,authid)     }     dbi_query(dbc,query)         return PLUGIN_HANDLED } public death_msg(id) {     edit_value(id,"money","tiredness","=",0)         return PLUGIN_HANDLED } public bsleep(id) {     if(!is_user_alive(id))     {         client_print(id,print_chat,"You cannot sleep while dead!")         return PLUGIN_HANDLED     }     if(asleep[id])     {         asleep[id]=false         client_cmd(id,"-duck")         set_user_maxspeed(id,320.0)         set_task(0.1,"fadeout",id)         set_task(0.1,"snore",id)         client_print(id,print_chat,"You wake up feeling refreshed.")     }     else if(!asleep[id])     {         asleep[id]=true         client_cmd(id,"+duck")         set_user_maxspeed(id,1.0)         set_task(0.1,"fadeout",id)         set_task(0.1,"snore",id)         set_task(0.1,"health",id)         client_print(id,print_chat,"You begin to fall asleep.^n")         client_print(id,print_chat,"Type /sleep again to wake up.")     }         return PLUGIN_HANDLED } public snore(id) {     if(!is_user_alive(id)) return PLUGIN_HANDLED     if(asleep[id])     {         emit_sound(id,CHAN_VOICE,"misc/snore.wav",0.1,ATTN_NORM,0,PITCH_NORM)         set_task(5.0,"snore",0,"",0,"b")     }     else if(!asleep[id])     {         emit_sound(id,CHAN_VOICE,"misc/yawn.wav",0.1,ATTN_NORM,0,PITCH_NORM)     }         return PLUGIN_HANDLED } public health(id) {     new healfull[64],query[256],authid[32]     new currhealth = get_user_health(id)     new newhealth = currhealth + 1     new maxhealth = get_cvar_num("sv_maxhealth")     new minhealth = get_cvar_num("sv_minhealth")     get_cvar_string("sv_healfull",healfull,63)     get_user_authid(id,authid,31)     format(query,255,"SELECT tiredness FROM money WHERE steamid='%s'",authid)     result = dbi_query(dbc,query)     if(!asleep[id]) return PLUGIN_HANDLED     if(dbi_nextrow(result) > 0)     {         new currenttiredness = dbi_field(result,1)         dbi_free_result(result)         if(equal(healfull,"0"))         {             if(currenttiredness <= 0)             {                 if(currhealth >= maxhealth)                 {                     set_task(0.1,"bsleep",id)                 }             }             else if(currenttiredness > 0)             {                 if(currhealth < maxhealth && currhealth > minhealth)                 {                     set_user_health(id,newhealth)                 }                 edit_value(id,"money","tiredness","-",random_num(1,5))                 set_task(1.0,"health",id)             }         }         else if(equal(healfull,"1"))         {             if(currenttiredness <= 0)             {                 if(currhealth >= maxhealth)                 {                     set_task(0.1,"bsleep",id)                 }             }             else if(currenttiredness > 0)             {                 if(currhealth < maxhealth)                 {                     set_user_health(id,newhealth)                 }                 edit_value(id,"money","tiredness","-",random_num(1,5))                 set_task(1.0,"health",id)             }         }         else         {             log_amx("[SleepMod] %s is not a valid value for sv_healfull",healfull)         }     }     dbi_free_result(result)         return PLUGIN_HANDLED } public healthwarn(id) {     new healfull[64]     new currhealth = get_user_health(id)     new minhealth = get_cvar_num("sv_minhealth")         get_cvar_string("rp_healfull",healfull,63)         if(currhealth < minhealth)     {         if(equal(healfull,"0"))         {             client_print(id,print_chat,"Your health is very low, sleeping will be ineffective.")         }         else if(equal(healfull,"1"))         {             client_print(id,print_chat,"Your health is very low, sleeping is recommended.")         }     }         return PLUGIN_HANDLED } public tiredness() {     new players[32],num     get_players(players,num,"ac")     for(new i = 0;i < num;i++)     {         new ran = random_num(1,6)         if(ran == 1)         {             if(is_user_database(players[i]) == 1)             {                 edit_value(players[i],"money","tiredness","+",random_num(1,5))                 if(is_user_alive(players[i]))                 {                     new query[256], authid[32]                     get_user_authid(players[i],authid,31)                     format(query,255,"SELECT tiredness FROM money WHERE steamid='%s'",authid)                     result = dbi_query(dbc,query)                     if(dbi_nextrow(result) > 0)                     {                         new currenttiredness = dbi_field(result,1)                         dbi_free_result(result)                         if(currenttiredness >= 60 && currenttiredness <= 80)                         {                             client_print(players[i],print_chat,"[SleepMod] You yawn and feel tired.^n")                         }                         else if(currenttiredness >= 81 && currenttiredness <= 99)                         {                             client_print(players[i],print_chat,"[SleepMod] You yawn and feel very tired.^n")                         }                         else if(currenttiredness >= 100)                         {                             client_print(players[i],print_chat,"[SleepMod] You fell asleep because of tiredness!^n")                             set_task(0.1,"bsleep",players[i])                         }                     }                     dbi_free_result(result)                 }                 else                 {                     set_task(1.0,"tiredness",0)                 }             }         }     }         return PLUGIN_HANDLED } public fadeout(id) {     if(asleep[id])     {         set_user_rendering(id,kRenderFxGlowShell,0,255,0,kRenderTransAlpha,25)         message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},id);         write_short(~0);         write_short(~0);         write_short(1<<12);         write_byte(0);         write_byte(0);         write_byte(0);         write_byte(255);         message_end();     }     else if(!asleep[id])     {         set_user_rendering(id,kRenderFxNone,0,0,0,kRenderNormal,0)         message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},id);         write_short(~0);         write_short(~0);         write_short(1<<12);         write_byte(0);         write_byte(0);         write_byte(0);         write_byte(0);         message_end();     }         return PLUGIN_HANDLED }

v3x 03-01-2006 17:37

Moved from "Support/Help".

DataMatrix 03-01-2006 21:43

Oops sorry, v3x.

BTW the problem I'm having is with the function tiredness.

DataMatrix 03-01-2006 23:30

Nevermind guys, fixed :).


All times are GMT -4. The time now is 20:15.

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