| AnimalMonster |
11-04-2020 05:37 |
MySQL not updating
PHP Code:
#include <amxmodx> #include <hamsandwich> #include <fakemeta> #include <fakemeta_util> #include <fun> #include <sqlx>
#define PLUGIN "Candy System" #define VERSION "1.0" #define AUTHOR "DeclineD"
#define skills 3 #define levelwprestige 15 #define levelwoprestige 10
#define SQL_HOST "*" #define SQL_NAME "*" #define SQL_USER "*" #define SQL_PASS "*" #define SQL_TABNAME "*"
new Handle:g_hDBTuple; new Handle:g_hConnect;
new bool: g_bUserLoaded[ MAX_PLAYERS +1 ]; new g_szQuery[ 512 ];
new const item_class_name[] = "candy"
new g_model[] = "models/candy.mdl"
new Candies[33]
new Level[33][skills]
new maxlevels[33][skills]
new Prestige[33]
new SCosts[levelwprestige+1] = { 3, 5, 7, 9, 11, 13, 15, 17, 19, 22, 25, 28, 31, 34, 37 }
new GCosts[levelwprestige+1] = { 3, 5, 7, 9, 11, 13, 15, 17, 19, 22, 25, 28, 31, 34, 37 }
new HCosts[levelwoprestige+1] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }
new Float:GFloats[levelwprestige+1] = { 1.0, 0.950, 0.900, 0.850, 0.800, 0.750, 0.700, 0.650, 0.600, 0.550, 0.525, 0.500, 0.475, 0.450, 0.425, 0.400 }
new Float:SFloats[levelwprestige+1] = { 250.0, 300.0, 325.0, 350.0, 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0 }
new HValue[levelwoprestige+1] = { 100, 155, 210, 265, 320, 375, 430, 485, 500, 550, 600 }
new color_state
new r[] = { 255, 255, 87, 87 }
new g[] = { 87, 255, 255, 87 }
new b[] = { 87, 87, 87, 255 }
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_forward(FM_Touch, "fwd_Touch")
RegisterHam(Ham_Killed, "player", "fw_PlayerKilled") RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawned", 1) register_logevent("log_RStart", 2, "1=Round_Start") register_forward(FM_PlayerPreThink, "Think") register_clcmd("say /skill", "mSkills") register_clcmd("lalala", "lalala") }
public lalala(id) { Candies[id] = 99999 }
public plugin_cfg( ) SQL_LoadDebug( ); public plugin_end( ) { if( g_hDBTuple ) SQL_FreeHandle( g_hDBTuple ); if( g_hConnect ) SQL_FreeHandle( g_hConnect ); return; }
public plugin_precache() { precache_model(g_model) }
public client_putinserver(id) { set_task(1.0, "hud", id, _, _, "b") set_task(5.0, "CTask__LoadData", id ); }
public client_disconnected( id ) { if( !g_bUserLoaded[ id ] ) return; new szIP[10] get_user_ip(id, szIP, charsmax(szIP))
formatex( g_szQuery, charsmax( g_szQuery ), "UPDATE `%s` SET `Candy` = '%d', `LevelS` = '%d', `LevelG` = '%d', `LevelH` = '%d' WHERE `%s`,`IP` = '%s'", SQL_TABNAME, Candies[id], Level[id][0], Level[id][1], Level[id][2], SQL_TABNAME, szIP ); SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery ); }
public log_RStart(id) { deleteAllItems() }
public Think(id) { if(Prestige[id] != 1) { maxlevels[id][0] = levelwoprestige maxlevels[id][1] = levelwoprestige maxlevels[id][2] = 10 } else { maxlevels[id][0] = levelwprestige maxlevels[id][1] = levelwprestige maxlevels[id][2] = 10 }
set_pev(id, pev_maxspeed, SFloats[ Level[id][0] ]) set_pev(id, pev_gravity, GFloats[ Level[id][1] ]) }
public fwd_Touch(toucher, touched) { if (!is_user_alive(toucher) || !pev_valid(touched)) return FMRES_IGNORED new classname[32] pev(touched, pev_classname, classname, 31)
if (!equal(classname, item_class_name)) return FMRES_IGNORED
Candies[toucher] += 1 set_dhudmessage(240, 10, 160, random_float(0.1, 1.0), random_float(0.5, 1.0), 0, 2.0, 3.0, 1.0, 1.0) show_dhudmessage(toucher, "[+1 Candy]")
set_pev(touched, pev_effects, EF_NODRAW) set_pev(touched, pev_solid, SOLID_NOT) return FMRES_IGNORED }
public fw_PlayerKilled(victim, attacker, shouldgib) { new origin[3] get_user_origin(victim , origin)
addItem(origin) }
public fw_PlayerSpawned(id) { set_user_health(id, HValue[ Level[id][2] ]) }
public addItem(origin[3]) { new ent = fm_create_entity("info_target") set_pev(ent, pev_classname, item_class_name) engfunc(EngFunc_SetModel,ent, g_model) set_pev(ent,pev_mins,Float:{-10.0,-10.0,0.0}) set_pev(ent,pev_maxs,Float:{10.0,10.0,25.0}) set_pev(ent,pev_size,Float:{-10.0,-10.0,0.0,10.0,10.0,25.0}) engfunc(EngFunc_SetSize,ent,Float:{-10.0,-10.0,0.0},Float:{10.0,10.0,25.0})
set_pev(ent,pev_solid,SOLID_BBOX) set_pev(ent,pev_movetype,MOVETYPE_TOSS) new Float:fOrigin[3] IVecFVec(origin, fOrigin) set_pev(ent, pev_origin, fOrigin) set_pev(ent,pev_renderfx,kRenderFxGlowShell)
new Float:velocity[3]; pev(ent,pev_velocity,velocity); velocity[2] = random_float(265.0,285.0); set_pev(ent,pev_velocity,velocity) switch(random_num(1,4)) { case 1: set_pev(ent,pev_rendercolor,Float:{0.0,0.0,255.0}) case 2: set_pev(ent,pev_rendercolor,Float:{0.0,255.0,0.0}) case 3: set_pev(ent,pev_rendercolor,Float:{255.0,0.0,0.0}) case 4: set_pev(ent,pev_rendercolor,Float:{255.0,255.0,255.0}) } }
public deleteAllItems() { new ent = FM_NULLENT static class_name[] = "classname" while(ent == engfunc(EngFunc_FindEntityByString, ent, class_name, item_class_name)) set_pev(ent, pev_flags, FL_KILLME) }
public mSkills(id) { new AllLvl = Level[id][0] + Level[id][1] + Level[id][2] new AllMaxs = maxlevels[id][0] + maxlevels[id][1] + maxlevels[id][2] new menu = menu_create("\ySkills \rMenu \r[\yLIMITED\r]", "mHand") new text[128] if(AllLvl == AllMaxs - maxlevels[id][2] && Prestige[id] != 1) { formatex(text, charsmax(text), "\yPress Me To \rPrestige\y(\w100 \rCandy\w)") } else if(Level[id][0] == maxlevels[id][0]) { formatex(text, charsmax(text), "Speed \yLv. \rMAXED") } else if(Prestige[id] == 1 && Level[id][0] != maxlevels[id][0]) { formatex(text, charsmax(text), "Speed \yLv. %d \r(%d Candy)", Level[id][0], SCosts[ Level[id][0] ]) } else formatex(text, charsmax(text), "Speed \yLv. %d \r(%d Candy)", Level[id][0], SCosts[ Level[id][0] ]) menu_additem(menu, text) if(AllLvl == AllMaxs - maxlevels[id][2] && Prestige[id] != 1) { formatex(text, charsmax(text), "\yPress Me To \rPrestige\y(\w100 \rCandy\w)") } else if(Level[id][1] == maxlevels[id][1]) { formatex(text, charsmax(text), "Gravity \yLv. \rMAXED") } else if(Prestige[id] == 1 && Level[id][1] != maxlevels[id][1]) { formatex(text, charsmax(text), "Gravity \yLv. %d \r(%d Candy)", Level[id][1], GCosts[ Level[id][1] ]) } else formatex(text, charsmax(text), "Gravity \yLv. %d \r(%d Candy)", Level[id][1], GCosts[ Level[id][1] ]) menu_additem(menu, text) if(Level[id][2] == maxlevels[id][2]) { formatex(text, charsmax(text), "Health \yLv. \rMAXED") } else if(Level[id][2] < maxlevels[id][2]) { if(Prestige[id] != 1) formatex(text, charsmax(text), "\dHealth Lv. 0 (Prestige 1 To Unlock)") else formatex(text, charsmax(text), "Health \yLv. %d \r(%d Candy)" ,Level[id][2], HCosts[ Level[id][2] ]) } menu_additem(menu, text) menu_setprop(menu, MPROP_EXITNAME, "Exit") menu_display(id, menu) }
public mHand(id, menu, item) { switch(item) { case 0: { if(Level[id][0] + Level[id][1] == maxlevels[id][0] + maxlevels[id][1] && Prestige[id] != 1) { if(Candies[id] >= 100) { Prestige[id] += 1 Level[id][0] = 0 Level[id][1] = 0 } }
if(Candies[id] < SCosts[ Level[id][0] ]) return; if(Level[id][0] == maxlevels[id][0]) return;
Candies[id] = Candies[id] - SCosts[ Level[id][0] ] Level[id][0] += 1 menu_cancel(id) set_task(0.1, "mSkills", id +0)
client_print_color(id, id, "You just brought speed ^4level %d", Level[id][0]) } case 1: { if(Level[id][0] + Level[id][1] == maxlevels[id][0] + maxlevels[id][1] && Prestige[id] != 1) { if(Candies[id] >= 100) { Prestige[id] += 1 Level[id][0] = 0 Level[id][1] = 0 } }
if(Candies[id] < GCosts[ Level[id][1] ]) return; if(Level[id][1] == maxlevels[id][1]) return;
Candies[id] = Candies[id] - GCosts[ Level[id][1] ] Level[id][1] += 1 menu_cancel(id) set_task(0.1, "mSkills", id +0)
client_print_color(id, id, "You just brought gravity ^4level %d", Level[id][1])
} case 2: { if(Candies[id] < HCosts[ Level[id][2] ]) return; if(Level[id][2] == maxlevels[id][2]) return; if(Prestige[id] != 1) return; Candies[id] = Candies[id] - HCosts[ Level[id][2] ] Level[id][2] += 1 menu_cancel(id) set_task(0.1, "mSkills", id +0)
client_print_color(id, id, "You just brought health ^4level %d", Level[id][2]) } } }
public hud(id) { new AllLvl = Level[id][0] + Level[id][1] + Level[id][2] new AllMaxs = maxlevels[id][0] + maxlevels[id][1] + maxlevels[id][2] if(color_state == 4) color_state = 0
set_dhudmessage(r[color_state], g[color_state], b[color_state], 0.0, 0.2, 0, 0.1, 0.1, 0.5, 0.5) color_state += 1 if(!g_bUserLoaded[id]) { show_dhudmessage(id, "[(-Candy-)] - LOADING...^n[(-Event-Level-)] - LOADING...^n[(-Prestige-)] - LOADING...") } else { if(Prestige[id] != 1) { if(Level[id][0] + Level[id][1] == maxlevels[id][0] + maxlevels[id][1]) { show_dhudmessage(id, "[(-Candy-)] - %d^n[(-Event-Level-)] - %d (MAXED)^n[(-Prestige-)] - UPGRADEABLE", Candies[id], 100 * (Level[id][0] + Level[id][1]) / (maxlevels[id][0] + maxlevels[id][1])) } else show_dhudmessage(id, "[(-Candy-)] - %d^n[(-Event-Level-)] - %d ^n[(-Prestige-)] - NONE", Candies[id], 100 * (Level[id][0] + Level[id][1]) / (maxlevels[id][0] + maxlevels[id][1])) } else if(AllLvl == AllMaxs) { show_dhudmessage(id, "[(-Candy-)] - %d^n[(-Event-Level-)] - %d (MAXED)^n[(-Prestige-)] - %d", Candies[id], 100 * (Level[id][0] + Level[id][1] + Level[id][2]) / (maxlevels[id][0] + maxlevels[id][1] + maxlevels[id][2]), Prestige[id]) } else show_dhudmessage(id, "[(-Candy-)] - %d^n[(-Event-Level-)] - %d ^n[(-Prestige-)] - %d", Candies[id], 100 * (Level[id][0] + Level[id][1] + Level[id][2]) / (maxlevels[id][0] + maxlevels[id][1] + maxlevels[id][2]),Prestige[id]) } }
public CTask__LoadData( id ) { if( !is_user_connected( id ) ) return; new szIP[10]
new iParams[ 1 ]; iParams [ 0 ] = id; get_user_ip( id,szIP, charsmax( szIP ) ); formatex( g_szQuery, charsmax( g_szQuery ), "SELECT * FROM `%s` WHERE ( `%s`.`IP` = '%i' )", SQL_TABNAME, SQL_TABNAME, szIP); SQL_ThreadQuery( g_hDBTuple, "SQL_QueryConnection", g_szQuery, iParams, sizeof iParams ); }
public SQL_LoadDebug( ) { new szError[ 512 ]; new iErrorCode; g_hDBTuple = SQL_MakeDbTuple( SQL_HOST, SQL_NAME, SQL_PASS, SQL_NAME ); g_hConnect = SQL_Connect( g_hDBTuple, iErrorCode, szError, charsmax( szError ) ); if( g_hConnect == Empty_Handle ) set_fail_state( szError ); if( !SQL_TableExists( g_hConnect, SQL_TABNAME ) ) { new Handle: hQueries; new szQuery[ 512 ]; formatex( szQuery, charsmax( szQuery ), "CREATE TABLE IF NOT EXISTS `%s` ( IP varchar( 32 ) CHARACTER SET cp1250 COLLATE cp1250_general_ci NOT NULL, Candy INT NOT NULL, LevelS INT NOT NULL, LevelG INT NOT NULL, LevelH INT NOT NULL, PRIMARY KEY ( IP ) )", SQL_TABNAME ); hQueries = SQL_PrepareQuery( g_hConnect, szQuery ); if( !SQL_Execute( hQueries ) ) { SQL_QueryError( hQueries, szError, charsmax( szError ) ); set_fail_state( szError ); } SQL_FreeHandle( hQueries ); } SQL_QueryAndIgnore( g_hConnect, "SET NAMES utf8" ); }
public SQL_QueryConnection( iState, Handle: hQuery, szError[ ], iErrorCode, iParams[ ], iParamsSize ) { new szIP[10]
switch( iState ) { case TQUERY_CONNECT_FAILED: log_amx( "Load - Could not connect to SQL database. [%d] %s", iErrorCode, szError ); case TQUERY_QUERY_FAILED: log_amx( "Load Query failed. [%d] %s", iErrorCode, szError ); } new id = iParams[ 0 ]; g_bUserLoaded[ id ] = true; get_user_ip(id, szIP, charsmax(szIP)) if( SQL_NumResults( hQuery ) < 1 ) { if( equal( szIP, "ID_PENDING" ) ) return PLUGIN_HANDLED;
formatex( g_szQuery, charsmax( g_szQuery ), "INSERT INTO `%s` ( `IP`, `Candy`, `LevelS`, `LevelG`, `LevelH` ) VALUES ( '%i', '%d', '%d', '%d', '%d' );", SQL_TABNAME, szIP, Candies[id], Level[id][0], Level[id][1], Level[id][2]); SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery ) } else { if(!g_bUserLoaded[id]) return PLUGIN_CONTINUE;
Candies[id] = SQL_ReadResult( hQuery, 1) Level[id][0] = SQL_ReadResult( hQuery, 2) Level[id][1] = SQL_ReadResult( hQuery, 3) Level[id][2] = SQL_ReadResult( hQuery, 4) if(Level[id][2] > 0) { Prestige[id] = 1 } } return PLUGIN_HANDLED; }
public SQL_ThreadQueryHandler( iState, Handle: hQuery, szError[ ], iErrorCode, iParams[ ], iParamsSize ) { if( iState == 0 ) return; log_amx( "SQL Error: %d (%s)", iErrorCode, szError ); }
stock bool: SQL_TableExists( Handle: hDataBase, const szTable[ ] ) { new Handle: hQuery = SQL_PrepareQuery( hDataBase, "SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;", szTable ); new szError[ 512 ]; if( !SQL_Execute( hQuery ) ) { SQL_QueryError( hQuery, szError, charsmax( szError ) ); set_fail_state( szError ); } else if( !SQL_NumResults( hQuery ) ) { SQL_FreeHandle( hQuery ); return false; } SQL_FreeHandle( hQuery ); return true; }
|