Raised This Month: $ Target: $400
 0% 

MySQL not updating


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
AnimalMonster
Senior Member
Join Date: May 2020
Old 11-04-2020 , 05:37   MySQL not updating
Reply With Quote #1

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 
boolg_bUserLoadedMAX_PLAYERS +];
new 
g_szQuery512 ]; 

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(PLUGINVERSIONAUTHOR)
    
    
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_FreeHandleg_hDBTuple );
    
    if( 
g_hConnect 
        
SQL_FreeHandleg_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_disconnectedid )
{
    if( !
g_bUserLoadedid ] )
        return;
        
    new 
szIP[10]
    
    
get_user_ip(idszIPcharsmax(szIP))

    
formatexg_szQuerycharsmaxg_szQuery ), "UPDATE `%s` SET `Candy` = '%d', `LevelS` = '%d', `LevelG` = '%d', `LevelH` = '%d' WHERE `%s`,`IP` = '%s'"SQL_TABNAMECandies[id], Level[id][0], Level[id][1], Level[id][2], SQL_TABNAMEszIP );
    
SQL_ThreadQueryg_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(idpev_maxspeedSFloatsLevel[id][0] ])
    
set_pev(idpev_gravityGFloatsLevel[id][1] ])
}

public 
fwd_Touch(touchertouched)
{
    if (!
is_user_alive(toucher) || !pev_valid(touched))
        return 
FMRES_IGNORED
    
    
new classname[32]    
    
pev(touchedpev_classnameclassname31)

    if (!
equal(classnameitem_class_name))
        return 
FMRES_IGNORED

    Candies
[toucher] += 1
    
    set_dhudmessage
(24010160random_float(0.11.0), random_float(0.51.0), 02.03.01.01.0)
    
show_dhudmessage(toucher"[+1 Candy]")

    
set_pev(touchedpev_effectsEF_NODRAW)
    
set_pev(touchedpev_solidSOLID_NOT)
    
    return 
FMRES_IGNORED
}

public 
fw_PlayerKilled(victimattackershouldgib)
{
    new 
origin[3]
    
get_user_origin(victim origin)

    
addItem(origin)
}

public 
fw_PlayerSpawned(id)
{
    
set_user_health(idHValueLevel[id][2] ])
}

public 
addItem(origin[3])
{
    new 
ent fm_create_entity("info_target")
    
set_pev(entpev_classnameitem_class_name)
    
    
engfunc(EngFunc_SetModel,entg_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(originfOrigin)
    
set_pev(entpev_originfOrigin)
    
    
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 
1set_pev(ent,pev_rendercolor,Float:{0.0,0.0,255.0})
        case 
2set_pev(ent,pev_rendercolor,Float:{0.0,255.0,0.0})
        case 
3set_pev(ent,pev_rendercolor,Float:{255.0,0.0,0.0})
        case 
4set_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_FindEntityByStringentclass_nameitem_class_name))
    
set_pev(entpev_flagsFL_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(textcharsmax(text), "\yPress Me To \rPrestige\y(\w100 \rCandy\w)")
    }
    else if(
Level[id][0] == maxlevels[id][0])
    {
        
formatex(textcharsmax(text), "Speed \yLv. \rMAXED")
    }
    else if(
Prestige[id] == && Level[id][0] != maxlevels[id][0])
    {
        
formatex(textcharsmax(text), "Speed \yLv. %d \r(%d Candy)"Level[id][0], SCostsLevel[id][0] ])
    }
    else 
formatex(textcharsmax(text), "Speed \yLv. %d \r(%d Candy)"Level[id][0], SCostsLevel[id][0] ])
    
    
menu_additem(menutext)
    
    if(
AllLvl == AllMaxs maxlevels[id][2] && Prestige[id] != 1)
    {
        
formatex(textcharsmax(text), "\yPress Me To \rPrestige\y(\w100 \rCandy\w)")
    }
    else if(
Level[id][1] == maxlevels[id][1])
    {
        
formatex(textcharsmax(text), "Gravity \yLv. \rMAXED")
    }
    else if(
Prestige[id] == && Level[id][1] != maxlevels[id][1])
    {
        
formatex(textcharsmax(text), "Gravity \yLv. %d \r(%d Candy)"Level[id][1], GCostsLevel[id][1] ])
    }
    else 
formatex(textcharsmax(text), "Gravity \yLv. %d \r(%d Candy)"Level[id][1], GCostsLevel[id][1] ])
    
    
menu_additem(menutext)
    
    if(
Level[id][2] == maxlevels[id][2])
    {
        
formatex(textcharsmax(text), "Health \yLv. \rMAXED")
    }
    else if(
Level[id][2] < maxlevels[id][2])
    { 
        if(
Prestige[id] != 1formatex(textcharsmax(text), "\dHealth Lv. 0 (Prestige 1 To Unlock)")
        else 
formatex(textcharsmax(text), "Health \yLv. %d \r(%d Candy)" ,Level[id][2], HCostsLevel[id][2] ])
    }
    
    
menu_additem(menutext)
    
    
menu_setprop(menuMPROP_EXITNAME"Exit")
    
    
menu_display(idmenu)
}

public 
mHand(idmenuitem)
{
    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] < SCostsLevel[id][0] ]) return;
            if(
Level[id][0] == maxlevels[id][0]) return;

            
Candies[id] = Candies[id] - SCostsLevel[id][0] ]
            
Level[id][0] += 1
            
            menu_cancel
(id)
            
set_task(0.1"mSkills"id +0)

            
client_print_color(idid"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] < GCostsLevel[id][1] ]) return;
            if(
Level[id][1] == maxlevels[id][1]) return;

            
Candies[id] = Candies[id] - GCostsLevel[id][1] ]
            
Level[id][1] += 1
                        
            menu_cancel
(id)
            
set_task(0.1"mSkills"id +0)

            
client_print_color(idid"You just brought gravity ^4level %d"Level[id][1])

        }
        
        case 
2: {
            if(
Candies[id] < HCostsLevel[id][2] ]) return;
            if(
Level[id][2] == maxlevels[id][2]) return;
            if(
Prestige[id] != 1) return;
    
            
Candies[id] = Candies[id] - HCostsLevel[id][2] ]
            
Level[id][2] += 1
                        
            menu_cancel
(id)
            
set_task(0.1"mSkills"id +0)

            
client_print_color(idid"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 == 4color_state 0

    set_dhudmessage
(r[color_state], g[color_state], b[color_state], 0.00.200.10.10.50.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__LoadDataid )
{    
    if( !
is_user_connectedid ) )
        return;
        
    new 
szIP[10]

    new 
iParams];
    
iParams ] = id;
    
    
get_user_ipid,szIPcharsmaxszIP ) );
    
    
formatexg_szQuerycharsmaxg_szQuery ), "SELECT * FROM `%s` WHERE ( `%s`.`IP` = '%i' )"SQL_TABNAMESQL_TABNAMEszIP);
    
SQL_ThreadQueryg_hDBTuple"SQL_QueryConnection"g_szQueryiParamssizeof iParams );
}

public 
SQL_LoadDebug( ) 
{
    new 
szError512 ];
    new 
iErrorCode;
    
    
g_hDBTuple SQL_MakeDbTupleSQL_HOSTSQL_NAMESQL_PASSSQL_NAME );
    
g_hConnect SQL_Connectg_hDBTupleiErrorCodeszErrorcharsmaxszError ) );
    
    if( 
g_hConnect == Empty_Handle )
        
set_fail_stateszError );
    
    if( !
SQL_TableExistsg_hConnectSQL_TABNAME ) )
    {
        new 
HandlehQueries
        new 
szQuery512 ];
        
        
formatexszQuerycharsmaxszQuery ), "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_PrepareQueryg_hConnectszQuery );
        
        if( !
SQL_ExecutehQueries ) )
        {
            
SQL_QueryErrorhQueriesszErrorcharsmaxszError ) );
            
set_fail_stateszError );
        }
        
SQL_FreeHandlehQueries );    
    }
    
SQL_QueryAndIgnoreg_hConnect"SET NAMES utf8" );
}

public 
SQL_QueryConnectioniStateHandlehQueryszError[ ], iErrorCodeiParams[ ], iParamsSize )
{
    new 
szIP[10]

    switch( 
iState )
    {
        case 
TQUERY_CONNECT_FAILEDlog_amx"Load - Could not connect to SQL database. [%d] %s"iErrorCodeszError );
        case 
TQUERY_QUERY_FAILEDlog_amx"Load Query failed. [%d] %s"iErrorCodeszError );
    }
    
    new 
id iParams];
    
g_bUserLoadedid ] = true;
    
    
get_user_ip(idszIPcharsmax(szIP))
    
    if( 
SQL_NumResultshQuery ) < )
    {
        if( 
equalszIP"ID_PENDING" ) )
            return 
PLUGIN_HANDLED;

        
formatexg_szQuerycharsmaxg_szQuery ), "INSERT INTO `%s` ( `IP`, `Candy`, `LevelS`, `LevelG`, `LevelH` ) VALUES ( '%i', '%d', '%d', '%d', '%d' );"SQL_TABNAMEszIPCandies[id], Level[id][0], Level[id][1], Level[id][2]);
        
SQL_ThreadQueryg_hDBTuple"SQL_ThreadQueryHandler"g_szQuery )
    }
    else {
        if(!
g_bUserLoaded[id]) return PLUGIN_CONTINUE;

        
Candies[id] = SQL_ReadResulthQuery1)
        
Level[id][0] = SQL_ReadResulthQuery2)
        
Level[id][1] = SQL_ReadResulthQuery3)
        
Level[id][2] = SQL_ReadResulthQuery4)
        
        if(
Level[id][2] > 0)
        {
            
Prestige[id] = 1
        
}
    }
    return 
PLUGIN_HANDLED;
}

public 
SQL_ThreadQueryHandleriStateHandlehQueryszError[ ], iErrorCodeiParams[ ], iParamsSize )
{
    if( 
iState == )
        return;
    
    
log_amx"SQL Error: %d (%s)"iErrorCodeszError );
}

stock boolSQL_TableExistsHandlehDataBase, const szTable[ ] )
{
    new 
HandlehQuery SQL_PrepareQueryhDataBase"SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;"szTable );
    new 
szError512 ];
    
    if( !
SQL_ExecutehQuery ) )
    {
        
SQL_QueryErrorhQueryszErrorcharsmaxszError ) );
        
set_fail_stateszError );
    }
    else if( !
SQL_NumResultshQuery ) )
    {
        
SQL_FreeHandlehQuery );
        return 
false;
    }
    
SQL_FreeHandlehQuery );
    return 
true;


Last edited by AnimalMonster; 11-04-2020 at 05:38. Reason: Personal Data
AnimalMonster is offline
 


Thread Tools
Display Modes

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 14:11.


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