Page 7 of 8

Re: Levels-XP System

Posted: 14 Sep 2019, 15:43
by czirimbolo
Mohamed Alaa wrote: 4 years ago What do you mean you can't give XP?
I use this plugin for giving XP viewtopic.php?f=17&t=3373

Raheem changed some code in my level system. Now I cant use it, its just doesnt work

Re: Levels-XP System

Posted: 26 Sep 2019, 16:35
by czirimbolo

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 10
#define TASK_SHOWHUD 2020
#define TASK_DOUBLE 1133
#define REPEAT_TIME 60.0
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
#define LEVELUP "levelup_ZE/ze_levelup.wav"
 
enum
{
    Host = 0,
    User,
    Pass,
    DB
}
 
new const g_iMaxLevelsXP[MAX_LEVEL] =
{
    10, // 1
    20, // 2
    30, // 3
    40, // 4
    500, // 5
    600, // 6
    700, // 7
    800, // 8
    900, // 9
    5000 // 10
}
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
new const g_szTable[] =
" \
    ALTER TABLE `test` \
    ADD IF NOT EXISTS `Level` int(20) NOT NULL DEFAULT '0', \
    ADD IF NOT EXISTS `XP` int(20) NOT NULL DEFAULT '0'; \
"
 
// Messages
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.70
const Float:HUD_STATS_X = -1.0
const Float:HUD_STATS_Y = 0.90
 
const HUD_STATS_ZOMBIE_R = 200
const HUD_STATS_ZOMBIE_G = 220
const HUD_STATS_ZOMBIE_B = 0
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 210
 
const HUD_STATS_SPEC_R = 100
const HUD_STATS_SPEC_G = 100
const HUD_STATS_SPEC_B = 100
 
// Variables
new g_iLevel[33],
    g_iXP[33],
    g_iMaxXP[33],
    Float:g_fDamage[33],
    g_MsgSync,
    g_iLevelsVaultHandle,
    g_iRanksVaultHandle,
    Handle:g_hTuple,
    Fw_LevelUP,
    ForwardReturn,
    bool:g_bIsDoubleHours
 
// Cvars
new g_pCvarZombieInfect,
    g_pCvarEscapeSuccess,
    g_pCvarEnableDamage,
    g_pCvarRequiredDamage,
    g_pCvarDamageAward,
    g_pCvarStartXP,
    g_pCvarPercentageStyle,
    g_pCvarStartFromZero,
    g_pCvarAddCommas,
    g_pCvarLevelEffects,
    g_pCvarSaveType,
    g_pCvarDBInfo[4],
    g_pCvarDoubleXP
 
public plugin_natives()
{
    register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
}
 
public plugin_precache()
{
    precache_sound(LEVELUP)
}
 
public plugin_init()
{
    register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
 
    Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
   
    // Cvars
    g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    g_pCvarStartXP = register_cvar("ze_start_xp", "0")
    g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "0")
    g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "0")
    g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "0")
    g_pCvarDoubleXP = register_cvar("ze_double_xp", "9-12")
 
    g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
    g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
    g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
    g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
    g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
 
    if (get_pcvar_num(g_pCvarSaveType))
    {
        set_task(0.1, "Delay_MySQL_Init")
    }
}
 
public plugin_end()
{
    if (get_pcvar_num(g_pCvarSaveType))
    {
        if (g_hTuple != Empty_Handle)
        {
            SQL_FreeHandle(g_hTuple)
        }
    }
}
 
public Delay_MySQL_Init()
{
    MySQL_Init()
}
 
public MySQL_Init()
{
    if (!get_pcvar_num(g_pCvarSaveType))
        return
   
    new szHost[64], szUser[32], szPass[32], szDB[128]
   
    get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
   
    g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
   
    // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    new iErrorCode, szError[512], Handle:hSQLConnection
   
    hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
   
    if (hSQLConnection != Empty_Handle)
    {
        log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
        SQL_FreeHandle(hSQLConnection)
    }
    else
    {
        // Disable plugin
        set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
    }
   
    SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
}
 
public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public client_putinserver(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
   
    // Just 1 second delay
    set_task(1.0, "DelayLoad", id)
 
    // Other tasks
    set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
   
    // Message task
    DoubleHours()
   
    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", id+TASK_DOUBLE, _, _, "b")
    }
}
 
public HappyHours(taskid)
{
    new id = taskid - TASK_DOUBLE
   
    DoubleHours()
   
    if (!g_bIsDoubleHours)
        remove_task(taskid)
   
    new szDoubleHours[32]
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    set_dhudmessage(0, 255, 0, -1.0, 0.20, 0, 0.0, 10.0)
    show_dhudmessage(id, "DOUBLE XP: %s", szDoubleHours)
}
 
public DelayLoad(id)
{
    // Load his data
    LoadData(id)
}
 
public client_disconnected(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
       
    remove_task(id+TASK_SHOWHUD)
    remove_task(id)
}
 
public Show_Hud(taskid)
{  
    new iPlayer = ID_SHOWHUD
   
    if (!is_user_alive(iPlayer))
    {
        iPlayer = pev(iPlayer, pev_iuser2)
       
        if (!is_user_alive(iPlayer))
            return
    }
   
    if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    {
        if(iPlayer != ID_SHOWHUD)
        {
            set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
        else
        {
            set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
    }
    else
    {
        if(iPlayer != ID_SHOWHUD)
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szSpecXP[15], szSpecMaxXP[15]
               
                AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
                AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
               
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
            }  
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szZombieXP[15], szZombieMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
               
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
        else
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szHumanXP[15], szHumanMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
               
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
    }
}
 
public ze_roundend(WinTeam)
{
    if (WinTeam == ZE_TEAM_HUMAN)
    {
        new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarEscapeSuccess) * 2) : get_pcvar_num(g_pCvarEscapeSuccess)
        for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
        {
            if (!is_user_alive(id) || ze_is_user_zombie(id))
                continue
           
            Reward(id, (g_iXP[id] + iXP))
        }
    }
   
    remove_task(TASK_SHOWHUD)
}
 
public Check_User_Level(id)
{
    if (!is_user_connected(id))
        return
 
    if (g_iLevel[id] <= MAX_LEVEL)
    {
        while (g_iXP[id] >= g_iMaxXP[id])
        {
            if (get_pcvar_num(g_pCvarStartFromZero) == 1)
            {
                g_iXP[id] = 0
            }
           
            new szName[32]
            g_iLevel[id]++
            g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
            get_user_name(id, szName, charsmax(szName))
            ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
            ExecuteForward(Fw_LevelUP, ForwardReturn, id)
           
            SaveData(id)
           
            PlaySound(id, LEVELUP)
           
            if (get_pcvar_num(g_pCvarLevelEffects) != 0)
            {
                // Screen Fade
                message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
                write_short(4096*2)
                write_short(4096*5)
                write_short(0x0001)
                write_byte(random(256))
                write_byte(random(256))
                write_byte(random(256))
                write_byte(150)
                message_end()
               
                // Screen Shake
                message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
                write_short(255<<14)
                write_short(10<<14)
                write_short(255<<14)
                message_end()
            }
        }
    }
}
 
public ze_user_infected(iVictim, iInfector)
{
    if (iInfector == 0)
        return
 
    new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarZombieInfect) * 2) : get_pcvar_num(g_pCvarZombieInfect)
    Reward(iInfector, (g_iXP[iInfector] + iXP))
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Player Damage Himself
    if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
        return HC_CONTINUE
   
    // Same Team?
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // Store Damage For every Player
    g_fDamage[iAttacker] += fDamage
   
    // Damage Calculator Equal or Higher than needed damage
    if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    {
        // Player did damage that a multiplication of the cvar? Increase coins by this factor
        new iMultiplier = floatround(g_fDamage[iAttacker] / get_pcvar_float(g_pCvarRequiredDamage))
        new iXP = ((g_bIsDoubleHours ? (get_pcvar_num(g_pCvarDamageAward) * 2) : get_pcvar_num(g_pCvarDamageAward)) * iMultiplier)
        Reward(iAttacker, (g_iXP[iAttacker] + iXP))
       
        // Rest The Damage Calculator
        g_fDamage[iAttacker] = 0.0
    }
    return HC_CONTINUE
}
 
public Reward(id, XP)
{
    if (g_iLevel[id] <= MAX_LEVEL)
    {
        if (g_iLevel[id] == MAX_LEVEL)
        {
            if ((g_iXP[id] + XP) >= g_iMaxLevelsXP[MAX_LEVEL - 1])
            {
                g_iXP[id] = g_iMaxLevelsXP[MAX_LEVEL - 1]
                SaveData(id)
                return
            }
        }
 
        g_iXP[id] = XP
        SaveData(id)
        Check_User_Level(id)
    }
}
 
public SaveData(id)
{
    new szAuthID[35], szName[32]
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
 
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256]
        formatex(szData , charsmax(szData), "%i %i", g_iLevel[id], g_iXP[id])
       
        // Open the Vaults
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
        g_iRanksVaultHandle = nvault_open(g_szRanksVault)
 
        // Saves His Data
        nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
        nvault_set(g_iRanksVaultHandle, szAuthID, szName)
       
        // Close Vaults
        nvault_close(g_iLevelsVaultHandle)
        nvault_close(g_iRanksVaultHandle)
    }
    else
    {
        new szQuery[128]
        formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Level` = '%d', `XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], szAuthID)
        SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
    }
}
 
public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public LoadData(id)
{
    new szAuthID[35]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
   
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256], iTimestamp, iExists
       
        // Open the Vault
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
       
        iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
       
        // Close Vault
        nvault_close(g_iLevelsVaultHandle)
       
        if (!iExists)
        {
            g_iLevel[id] = 0
            g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
            SaveData(id)
        }
        else
        {
            new iLevel[32], iXP[32]
            parse(szData, iLevel, 31, iXP, 31)
           
            g_iLevel[id] = str_to_num(iLevel)
            g_iXP[id] = str_to_num(iXP)
        }
 
        g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
    }
    else
    {
        new szQuery[128], szData[5]
        formatex(szQuery, charsmax(szQuery), "SELECT * FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
   
        num_to_str(id, szData, charsmax(szData))
        SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    }
}
 
public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
{
    if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
        return
   
    new id = str_to_num(szData)
   
    // No results for this query means this is new player
    if (!SQL_NumResults(hQuery))
    {
        g_iLevel[id] = 0
        g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
    }
    else
    {
        g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
        g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
    }
 
    g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
}
 
public native_ze_get_user_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iXP[id]
}
 
public native_ze_set_user_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    Reward(id, amount)
    return true
}
 
public native_ze_get_user_level(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iLevel[id]
}
 
public native_ze_set_user_level(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    if (amount > MAX_LEVEL)
    {
        log_error(AMX_ERR_NATIVE, "Level must be less than or equal to MAX_LEVEL (%d)", MAX_LEVEL)
        return false
    }
 
    g_iLevel[id] = amount
   
    if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    {
        g_iXP[id] = 0
    }
    SaveData(id)
   
    return true
}
 
public native_ze_get_user_max_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    return g_iMaxXP[id]
}
 
stock DoubleHours()
{
    new szTime[3], szDoubleHours[32], szDoubleHours_Start[32], szDoubleHours_End[32]
    get_time("%H", szTime, charsmax(szTime))
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    for (new ch = 0; ch <= charsmax(szDoubleHours); ch++)
    {
        if (szDoubleHours[ch] == '-')
            szDoubleHours[ch] = ' '
    }
   
    parse(szDoubleHours, szDoubleHours_Start, charsmax(szDoubleHours_Start), szDoubleHours_End, charsmax(szDoubleHours_End))
   
    new iTime, iDoubleHourStart, iDoubleHourEnd
   
    iTime = str_to_num(szTime)
    iDoubleHourStart = str_to_num(szDoubleHours_Start)
    iDoubleHourEnd = str_to_num(szDoubleHours_End)
   
    if(iDoubleHourEnd > iTime >= iDoubleHourStart)
    {
        g_bIsDoubleHours = true
    }
    else
    {
        g_bIsDoubleHours = false
    }
}
Can you finally fix these errors? I want to use it on my server from 1 Year!


L 09/25/2019 - 19:22:28: [AMXX] Displaying debug trace (plugin "ze_level_system.amxx", version "1.9")
L 09/25/2019 - 19:22:28: [AMXX] Run time error 4: index out of bounds
L 09/25/2019 - 19:22:28: [AMXX] [0] ze_level_system.sma::LoadData (line 532)
L 09/25/2019 - 19:22:28: [AMXX] [1] ze_level_system.sma::DelayLoad (line 235)
L 09/25/2019 - 19:27:01: Start of error session

L 09/25/2019 - 19:04:09: [AMXX] Displaying debug trace (plugin "ze_level_system.amxx", version "1.9")
L 09/25/2019 - 19:04:09: [AMXX] Run time error 4: index out of bounds
L 09/25/2019 - 19:04:09: [AMXX] [0] ze_level_system.sma::Check_User_Level (line 369)
L 09/25/2019 - 19:04:09: [AMXX] [1] ze_level_system.sma::Reward (line 454)
L 09/25/2019 - 19:04:09: [AMXX] [2] ze_level_system.sma::Fw_TakeDamage_Post (line 430)
L 09/25/2019 - 19:08:16: [AMXX] Displaying debug trace (plugin "ze_level_system.amxx", version "1.9")
L 09/25/2019 - 19:08:16: [AMXX] Run time error 4: index out of bounds
L 09/25/2019 - 19:08:16: [AMXX] [0] ze_level_system.sma::Check_User_Level (line 369)
L 09/25/2019 - 19:08:16: [AMXX] [1] ze_level_system.sma::Reward (line 454)
L 09/25/2019 - 19:08:16: [AMXX] [2] ze_level_system.sma::Fw_TakeDamage_Post (line 430)

Re: Levels-XP System

Posted: 04 Oct 2019, 21:06
by czirimbolo
Ok here is fixed version of level system by Jack and Raheem. Double exp is working too.

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 41
#define TASK_SHOWHUD 2020
#define TASK_DOUBLE 1133
#define REPEAT_TIME 60.0
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
#define LEVELUP "levelup_ZE/ze_levelup.wav"
 
enum
{
    Host = 0,
    User,
    Pass,
    DB
}
 
new const g_iMaxLevelsXP[MAX_LEVEL] =
{
    3000, // 1
    3500, // 2
    5000, // 3
    7500, // 4
    11000, // 5
    15000, // 6
    20000, // 7
    25000, // 8
    30000, // 9
    40000, // 10
    50000, // 11
    60000, // 12
    75000, // 13
    90000, // 14
    105000, // 15
    120000, // 16
    140000, // 17
    170000, // 18
    200000, // 19
    275000, // 20
    350000, // 21
    500000, // 22
    1000000, // 23
    1750000, // 24
    3000000, // 25
    6000000, // 26
    10000000, // 27
    15000000, // 28
    20000000, // 29
    30000000, // 30
    40000000, // 31		
    62000000, // 32
    75000000, // 33
    90000000, // 34
    105000000, // 35
    125000000, // 36
    135000000, // 37
    155000000, // 38
    175000000, // 39
    200000000, // 40		
    300000000 // 41
}
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
new const g_szTable[] =
" \
    ALTER TABLE `test` \
    ADD IF NOT EXISTS `Level` int(20) NOT NULL DEFAULT '0', \
    ADD IF NOT EXISTS `XP` int(20) NOT NULL DEFAULT '0'; \
"
 
// Messages
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.70
const Float:HUD_STATS_X = 0.01
const Float:HUD_STATS_Y = 0.22
 
const HUD_STATS_ZOMBIE_R = 200
const HUD_STATS_ZOMBIE_G = 220
const HUD_STATS_ZOMBIE_B = 0
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 210
 
const HUD_STATS_SPEC_R = 100
const HUD_STATS_SPEC_G = 100
const HUD_STATS_SPEC_B = 100
 
// Variables
new g_iLevel[33],
    g_iXP[33],
    g_iMaxXP[33],
    Float:g_fDamage[33],
    g_MsgSync,
    g_iLevelsVaultHandle,
    g_iRanksVaultHandle,
    Handle:g_hTuple,
    Fw_LevelUP,
    ForwardReturn,
    bool:g_bIsDoubleHours
 
// Cvars
new g_pCvarZombieInfect,
    g_pCvarEscapeSuccess,
    g_pCvarEnableDamage,
    g_pCvarRequiredDamage,
    g_pCvarDamageAward,
    g_pCvarStartXP,
    g_pCvarPercentageStyle,
    g_pCvarStartFromZero,
    g_pCvarAddCommas,
    g_pCvarLevelEffects,
    g_pCvarSaveType,
    g_pCvarDBInfo[4],
    g_pCvarDoubleXP
 
public plugin_natives()
{
    register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
}
 
public plugin_precache()
{
    precache_sound(LEVELUP)
}
 
public plugin_init()
{
    register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
 
    Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
   
    // Cvars
    g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    g_pCvarStartXP = register_cvar("ze_start_xp", "0")
    g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "0")
    g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
    g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "0")
    g_pCvarDoubleXP = register_cvar("ze_double_xp", "15-22")
 
    g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
    g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
    g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
    g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
    g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
 
    if (get_pcvar_num(g_pCvarSaveType))
    {
        set_task(0.1, "Delay_MySQL_Init")
    }

    DoubleHours()

    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", TASK_DOUBLE, _, _, "b")
    }
}
 
public plugin_end()
{
    if (get_pcvar_num(g_pCvarSaveType))
    {
        if (g_hTuple != Empty_Handle)
        {
            SQL_FreeHandle(g_hTuple)
        }
    }
}
 
public Delay_MySQL_Init()
{
    MySQL_Init()
}
 
public MySQL_Init()
{
    if (!get_pcvar_num(g_pCvarSaveType))
        return
   
    new szHost[64], szUser[32], szPass[32], szDB[128]
   
    get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
   
    g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
   
    // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    new iErrorCode, szError[512], Handle:hSQLConnection
   
    hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
   
    if (hSQLConnection != Empty_Handle)
    {
        log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
        SQL_FreeHandle(hSQLConnection)
    }
    else
    {
        // Disable plugin
        set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
    }
   
    SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
}
 
public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public client_putinserver(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
   
    // Just 1 second delay
    set_task(1.0, "DelayLoad", id)
 
    // Other tasks
    set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
   
    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", id+TASK_DOUBLE, _, _, "b")
    }
}
 
public HappyHours(taskid)
{
    DoubleHours()

    if (!g_bIsDoubleHours)
        remove_task(taskid)
   
    new szDoubleHours[32]
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    set_dhudmessage(0, 255, 0, -1.0, 0.20, 0, 0.0, 10.0)
    show_dhudmessage(0, "DOUBLE XP: %s", szDoubleHours)
}
 
public DelayLoad(id)
{
    // Load his data
    LoadData(id)
}
 
public client_disconnected(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
       
    remove_task(id+TASK_SHOWHUD)
    remove_task(id)
}
 
public Show_Hud(taskid)
{  
    new iPlayer = ID_SHOWHUD
   
    if (!is_user_alive(iPlayer))
    {
        iPlayer = pev(iPlayer, pev_iuser2)
       
        if (!is_user_alive(iPlayer))
            return
    }
   
    if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    {
        if(iPlayer != ID_SHOWHUD)
        {
            set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
        else
        {
            set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
    }
    else
    {
        if(iPlayer != ID_SHOWHUD)
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szSpecXP[15], szSpecMaxXP[15]
               
                AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
                AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
               
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
            }  
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szZombieXP[15], szZombieMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
               
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
        else
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szHumanXP[15], szHumanMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
               
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
    }
}
 
public ze_roundend(WinTeam)
{
    if (WinTeam == ZE_TEAM_HUMAN)
    {
        new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarEscapeSuccess) * 2) : get_pcvar_num(g_pCvarEscapeSuccess)

        for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
        {
            if (!is_user_alive(id) || ze_is_user_zombie(id))
                continue
           
            Reward(id, (g_iXP[id] + iXP))
        }
    }
   
    remove_task(TASK_SHOWHUD)
}
 
public Check_User_Level(id)
{
    if (!is_user_connected(id))
        return
 
    if (g_iLevel[id] < MAX_LEVEL)
    {
    	new szName[32]

        while (g_iXP[id] > g_iMaxXP[id])
        {
            if (get_pcvar_num(g_pCvarStartFromZero) == 1)
            {
                g_iXP[id] = 0
            }

        	g_iLevel[id]++
        	g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
            get_user_name(id, szName, charsmax(szName))
            ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
            ExecuteForward(Fw_LevelUP, ForwardReturn, id)
            SaveData(id)
            PlaySound(id, LEVELUP)
           
            if (get_pcvar_num(g_pCvarLevelEffects) != 0)
            {
                // Screen Fade
                message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
                write_short(4096*2)
                write_short(4096*5)
                write_short(0x0001)
                write_byte(random(256))
                write_byte(random(256))
                write_byte(random(256))
                write_byte(150)
                message_end()
               
                // Screen Shake
                message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
                write_short(255<<14)
                write_short(10<<14)
                write_short(255<<14)
                message_end()
            }
        }
    }
}
 
public ze_user_infected(iVictim, iInfector)
{
    if (iInfector == 0)
        return
 
    new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarZombieInfect) * 2) : get_pcvar_num(g_pCvarZombieInfect)
    Reward(iInfector, (g_iXP[iInfector] + iXP))
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Player Damage Himself
    if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
        return HC_CONTINUE
   
    // Same Team?
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // Store Damage For every Player
    g_fDamage[iAttacker] += fDamage
   
    // Damage Calculator Equal or Higher than needed damage
    if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    {
        // Player did damage that a multiplication of the cvar? Increase coins by this factor
        new iMultiplier = floatround(g_fDamage[iAttacker] / get_pcvar_float(g_pCvarRequiredDamage))
        new iXP = ((g_bIsDoubleHours ? (get_pcvar_num(g_pCvarDamageAward) * 2) : get_pcvar_num(g_pCvarDamageAward)) * iMultiplier)
        Reward(iAttacker, (g_iXP[iAttacker] + iXP))
       
        // Rest The Damage Calculator
        g_fDamage[iAttacker] = 0.0
    }
    return HC_CONTINUE
}
 
public Reward(id, XP)
{
    if ((g_iLevel[id] + 1) < MAX_LEVEL)
    {
        g_iXP[id] = XP
        Check_User_Level(id)
    }
    else
    {
    	if ((g_iXP[id] + XP) >= g_iMaxLevelsXP[MAX_LEVEL - 1])
        {
            g_iXP[id] = g_iMaxXP[id] = g_iMaxLevelsXP[MAX_LEVEL - 1]
        }
    }
    SaveData(id)
}
 
public SaveData(id)
{
    new szAuthID[35], szName[32]
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
 
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256]
        formatex(szData , charsmax(szData), "%i %i", g_iLevel[id], g_iXP[id])
       
        // Open the Vaults
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
        g_iRanksVaultHandle = nvault_open(g_szRanksVault)
 
        // Saves His Data
        nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
        nvault_set(g_iRanksVaultHandle, szAuthID, szName)
       
        // Close Vaults
        nvault_close(g_iLevelsVaultHandle)
        nvault_close(g_iRanksVaultHandle)
    }
    else
    {
        new szQuery[128]
        formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Level` = '%d', `XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], szAuthID)
        SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
    }
}
 
public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public LoadData(id)
{
    new szAuthID[35]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
   
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256], iTimestamp, iExists
       
        // Open the Vault
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
       
        iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
       
        // Close Vault
        nvault_close(g_iLevelsVaultHandle)
       
        if (!iExists)
        {
            g_iLevel[id] = 0
            g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
            SaveData(id)
        }
        else
        {
            new iLevel[32], iXP[32]
            parse(szData, iLevel, 31, iXP, 31)
           
            g_iLevel[id] = str_to_num(iLevel)
            g_iXP[id] = str_to_num(iXP)
        }
 
        g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
    }
    else
    {
        new szQuery[128], szData[5]
        formatex(szQuery, charsmax(szQuery), "SELECT * FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
   
        num_to_str(id, szData, charsmax(szData))
        SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    }
}
 
public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
{
    if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
        return
   
    new id = str_to_num(szData)
   
    // No results for this query means this is new player
    if (!SQL_NumResults(hQuery))
    {
        g_iLevel[id] = 0
        g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
    }
    else
    {
        g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
        g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
    }
 
    g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
}
 
public native_ze_get_user_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iXP[id]
}
 
public native_ze_set_user_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
    
    DoubleHours()
    new addedXP = (amount - g_iXP[id])
    new iXP = g_bIsDoubleHours ? (addedXP * 2) : addedXP
    Reward(id, g_iXP[id] + iXP)
    return true
}
 
public native_ze_get_user_level(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iLevel[id]
}
 
public native_ze_set_user_level(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    if (amount > MAX_LEVEL)
    {
        log_error(AMX_ERR_NATIVE, "Level must be less than or equal to MAX_LEVEL (%d)", MAX_LEVEL)
        return false
    }
 
    g_iLevel[id] = amount
   
    if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    {
        g_iXP[id] = 0
    }
    SaveData(id)
   
    return true
}
 
public native_ze_get_user_max_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    return g_iMaxXP[id]
}
 
stock DoubleHours()
{
    new szTime[3], szDoubleHours[32], szDoubleHours_Start[32], szDoubleHours_End[32]
    get_time("%H", szTime, charsmax(szTime))
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    for (new ch = 0; ch <= charsmax(szDoubleHours); ch++)
    {
        if (szDoubleHours[ch] == '-')
            szDoubleHours[ch] = ' '
    }
   
    parse(szDoubleHours, szDoubleHours_Start, charsmax(szDoubleHours_Start), szDoubleHours_End, charsmax(szDoubleHours_End))
   
    new iTime, iDoubleHourStart, iDoubleHourEnd
   
    iTime = str_to_num(szTime)
    iDoubleHourStart = str_to_num(szDoubleHours_Start)
    iDoubleHourEnd = str_to_num(szDoubleHours_End)
   
    if (iDoubleHourEnd > iTime >= iDoubleHourStart)
    {
        g_bIsDoubleHours = true
    }
    else
    {
        g_bIsDoubleHours = false
    }
}

Re: Levels-XP System

Posted: 17 Mar 2020, 01:26
by karan
if mysql isnt working u can use this code

Code: Select all

#include <zombie_escape>

// Defines
#define MAX_LEVEL 50
#define MAX_XP 500000
#define TASK_SHOWHUD 2020
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
#define LEVELUP "levelup_ZE/ze_levelup.wav"

enum
{
	Host = 0,
	User,
	Pass,
	DB
}

// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
new const g_szLogFile[] = "Levels.log" // MySQL Errors log file

new const g_szTable[] =
" \
	CREATE TABLE IF NOT EXISTS `lvlez` \
	( \
		`steamid` varchar(34) NOT NULL, \
		`XP` int(20) NOT NULL, \
                `Level` int(20) NOT NULL, \
		PRIMARY KEY (`steamid`) \
	); \
"

// Messages
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.70
const Float:HUD_STATS_X = -1.0
const Float:HUD_STATS_Y = 0.90

const HUD_STATS_ZOMBIE_R = 200
const HUD_STATS_ZOMBIE_G = 220
const HUD_STATS_ZOMBIE_B = 0

const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 210

const HUD_STATS_SPEC_R = 100
const HUD_STATS_SPEC_G = 100
const HUD_STATS_SPEC_B = 100

// Variables
new g_iLevel[33], 
	g_iXP[33], 
	g_iMaxXP[33],
	Float:g_fDamage[33],
	g_MsgSync, 
	g_iLevelsVaultHandle, 
	g_iRanksVaultHandle,
	Handle:g_hTuple,
	Fw_LevelUP,
	ForwardReturn

// Cvars
new g_pCvarZombieInfect, 
	g_pCvarEscapeSuccess, 
	g_pCvarEnableDamage, 
	g_pCvarRequiredDamage, 
	g_pCvarDamageAward, 
	g_pCvarStartXP, 
	g_pCvarMaxLevelsIncrement, 
	g_pCvarMaxXPFirstLevel,
	g_pCvarPercentageStyle, 
	g_pCvarStartFromZero, 
	g_pCvarAddCommas, 
	g_pCvarLevelEffects,
	g_pCvarSaveType,
	g_pCvarDBInfo[4]

public plugin_natives()
{
	register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
	register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
	register_native("ze_get_user_level", "native_ze_get_user_level", 1)
	register_native("ze_set_user_level", "native_ze_set_user_level", 1)
	register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
	register_native("ze_set_user_max_xp", "native_ze_set_user_max_xp", 1)
}

public plugin_precache()
{
	precache_sound(LEVELUP)
}

public plugin_init()
{
	register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
	
	// Hook Chains
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)

	Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
	
	// Cvars
	g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
	g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
	g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
	g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
	g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
	g_pCvarStartXP = register_cvar("ze_start_xp", "50")
	g_pCvarMaxLevelsIncrement = register_cvar("ze_maxlevels_increment", "2.0")
	g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "100")
	g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "1")
	g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
	g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
	g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
	g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
	g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
	g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
	g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
	g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
	
	// Messages
	g_MsgSync = CreateHudSyncObj()

	if (get_pcvar_num(g_pCvarSaveType))
	{
		set_task(0.1, "Delay_MySQL_Init")
	}
}

public plugin_end()
{
	if (get_pcvar_num(g_pCvarSaveType))
	{
		if (g_hTuple != Empty_Handle)
		{
			SQL_FreeHandle(g_hTuple)
		}
	}
}

public Delay_MySQL_Init()
{
	MySQL_Init()
}

public MySQL_Init()
{
	if (!get_pcvar_num(g_pCvarSaveType))
		return
	
	new szHost[64], szUser[32], szPass[32], szDB[128]
	
	get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
	get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
	get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
	get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
	
	g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
	
	// Let's ensure that the g_hTuple will be valid, we will access the database to make sure
	new iErrorCode, szError[512], Handle:hSQLConnection
	
	hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
	
	if (hSQLConnection != Empty_Handle)
	{
		log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
		SQL_FreeHandle(hSQLConnection)
	}
	else
	{
		// Disable plugin
		set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
	}
	
	SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
}

public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime) 
{
	SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}

public client_putinserver(id)
{
	if (is_user_bot(id) || is_user_hltv(id))
		return
	
	// Just 1 second delay
	set_task(1.0, "DelayLoad", id)
      
        // Other tasks
	set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
	set_task(0.1, "Check_MaxXP", id, _, _, "b")
}

public DelayLoad(id)
{
	// Load his data
	LoadData(id)
}

public client_disconnected(id) 
{
	if(is_user_hltv(id) || is_user_bot(id))
		return
		
	remove_task(id+TASK_SHOWHUD)
	remove_task(id)
}

public Check_MaxXP(id)
{
	new iCurrentMaxXP = g_iMaxXP[id]
	
	new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
	
	for (new i = 1; i <= g_iLevel[id]; i++)
	{
		iMaxXP = floatround(float(iMaxXP) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
	}
	
	if (iCurrentMaxXP != iMaxXP)
	{
		g_iMaxXP[id] = iMaxXP
	}
}

public Show_Hud(taskid)
{	
	new iPlayer = ID_SHOWHUD
	
	if (!is_user_alive(iPlayer))
	{
		iPlayer = pev(iPlayer, pev_iuser2)
		
		if (!is_user_alive(iPlayer))
			return
	}
	
	if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
	{
		if(iPlayer != ID_SHOWHUD)
		{
			set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
			ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
		}
		else if (ze_is_user_zombie(iPlayer))
		{
			set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
			ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
		}
		else
		{
			set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
			ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
		}
	}
	else
	{
		if(iPlayer != ID_SHOWHUD)
		{
			if (get_pcvar_num(g_pCvarAddCommas) == 1)
			{
				new szSpecXP[15], szSpecMaxXP[15]
				
				AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
				AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
				
				set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
				ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
			}
			else
			{
				set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
				ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
			}	
		}
		else if (ze_is_user_zombie(iPlayer))
		{
			if (get_pcvar_num(g_pCvarAddCommas) == 1)
			{
				new szZombieXP[15], szZombieMaxXP[15]
				
				AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
				AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
				
				set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
				ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
			}
			else
			{
				set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
				ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
			}
		}
		else
		{
			if (get_pcvar_num(g_pCvarAddCommas) == 1)
			{
				new szHumanXP[15], szHumanMaxXP[15]
				
				AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
				AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
				
				set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
				ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
			}
			else
			{
				set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
				ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
			}
		}
	}
}

public ze_roundend(WinTeam)
{
	if (WinTeam == ZE_TEAM_HUMAN)
	{
		for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
		{
			if (!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
				continue
			
			g_iXP[id] += get_pcvar_num(g_pCvarEscapeSuccess)
			SaveData(id)
			Check_User_Level(id)
		}
	}
	
	remove_task(TASK_SHOWHUD)
}

public Check_User_Level(id)
{
	if(!is_user_connected(id))
		return

	if(g_iXP[id] >= g_iMaxXP[id])
	{
		if (get_pcvar_num(g_pCvarStartFromZero) == 1)
		{
			g_iXP[id] = 0
		}
		
		new szName[32]
		g_iLevel[id] ++
		g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
		get_user_name(id, szName, charsmax(szName))
		ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
		ExecuteForward(Fw_LevelUP, ForwardReturn, id)
		
		SaveData(id)
		
		PlaySound(id, LEVELUP)
		
		if (get_pcvar_num(g_pCvarLevelEffects) != 0)
		{
			// Screen Fade
			message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
			write_short(4096*2)
			write_short(4096*5)
			write_short(0x0001) 
			write_byte(random(256))
			write_byte(random(256))
			write_byte(random(256))
			write_byte(150)
			message_end()
			
			// Screen Shake
			message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
			write_short(255<<14)
			write_short(10<<14)
			write_short(255<<14)
			message_end()
		}
	}
}

public ze_user_infected(iVictim, iInfector)
{
	if (iInfector == 0)
		return
	
	g_iXP[iInfector] += get_pcvar_num(g_pCvarZombieInfect)
	SaveData(iInfector)
	Check_User_Level(iInfector)
}

public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
	// Player Damage Himself
	if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
		return HC_CONTINUE
	
	// Same Team?
	if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
		return HC_CONTINUE
	
	// Store Damage For every Player
	g_fDamage[iAttacker] += fDamage
	
	// Damage Calculator Equal or Higher than needed damage
	if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
	{
		// Give Player The Coins
		g_iXP[iAttacker] += get_pcvar_num(g_pCvarDamageAward)
		SaveData(iAttacker)
		Check_User_Level(iAttacker)
		
		// Rest The Damage Calculator
		g_fDamage[iAttacker] = 0.0
	}
	return HC_CONTINUE
}

public SaveData(id)
{
	new szAuthID[35], szName[32]
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	get_user_name(id, szName, charsmax(szName))
	
	// Set Him to max if he Higher than Max Value
	if (g_iLevel[id] > MAX_LEVEL)
	{
		g_iLevel[id] = MAX_LEVEL
	}
	
	if (g_iXP[id] > MAX_XP)
	{
		g_iXP[id] = MAX_XP
	}

	if (!get_pcvar_num(g_pCvarSaveType))
	{
		new szData[256]
		formatex(szData , charsmax(szData), "%i %i %i", g_iLevel[id], g_iXP[id], g_iMaxXP[id])
		
		// Open the Vaults
		g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
		g_iRanksVaultHandle = nvault_open(g_szRanksVault)

		// Saves His Data
		nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
		nvault_set(g_iRanksVaultHandle, szAuthID, szName)
		
		// Close Vaults
		nvault_close(g_iLevelsVaultHandle)
		nvault_close(g_iRanksVaultHandle)
	}
	else
	{
		new szQuery[128]
		formatex(szQuery, charsmax(szQuery), "UPDATE `lvlez` SET `Level` = '%d', `XP` = '%d' WHERE ( `steamid` = '%s' );", g_iLevel[id], g_iXP[id], szAuthID)
		SQL_ThreadQuery(g_hTuple, "QueryUpdateData", szQuery)
	}
}

public QueryUpdateData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime) 
{
	SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}

public LoadData(id)
{
	new szData[256], szAuthID[35]
	
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	
	if (!get_pcvar_num(g_pCvarSaveType))
	{
		// Useless Variable
		new iTimestamp, iExists
		
		// Open the Vault
		g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
		
		iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
		
		// Close Vault
		nvault_close(g_iLevelsVaultHandle)
		
		if (!iExists)
		{
			g_iLevel[id] = 0
			g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
			g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
			SaveData(id)
		}
		else
		{
			new iLevel[32], iXP[32], iMaxLevel[32]
			parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
			
			g_iLevel[id] = str_to_num(iLevel)
			g_iXP[id] = str_to_num(iXP)
			g_iMaxXP[id] = str_to_num(iMaxLevel)
		}
	}
	else
	{
		new szQuery[128], szData[5]
                formatex(szQuery, charsmax(szQuery), "SELECT `XP`, `Level` FROM `lvlez` WHERE ( `steamid` = '%s' );", szAuthID)
		//formatex(szQuery, charsmax(szQuery), "SELECT * FROM `test` WHERE ( `steamid` = '%s' );", szAuthID)
     
		num_to_str(id, szData, charsmax(szData))
		SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
	}
}

public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[]) 
{
	if(SQL_IsFail(iFailState, iError, szError, g_szLogFile))
		return
	
	new id = str_to_num(szData)
	
	// No results for this query means that player not saved before
	if(!SQL_NumResults(hQuery))
	{
		// This is new player
		//g_iEscapeCoins[id] = get_pcvar_num(g_pCvarStartCoins)
                g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
		
		// Get user steamid
		new szAuthID[35]
		get_user_authid(id, szAuthID, charsmax(szAuthID))
		
		// Insert his data to our database
		new szQuery[128]
		
		formatex(szQuery, charsmax(szQuery), "INSERT INTO `lvlez` (`steamid`, `XP`, `Level`) VALUES ('%s', '%d', '%d');", szAuthID,  g_iXP[id], g_iLevel[id])
		SQL_ThreadQuery(g_hTuple, "QueryInsertData", szQuery)
		
		return
	}
	
	// Get the "EC" column number (It's 2, always i don't like to hardcode :p)
	new iXP_Column = SQL_FieldNameToNum(hQuery, "XP")
        new iLvl_Column = SQL_FieldNameToNum(hQuery, "Level")
	
	// Read the coins of this player
        g_iXP[id] = SQL_ReadResult(hQuery, iXP_Column)
        g_iLevel[id] = SQL_ReadResult(hQuery, iLvl_Column)
}

public QueryInsertData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
	SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}

public native_ze_get_user_xp(id)
{
	if(!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false;
	}
	
	return g_iXP[id]
}

public native_ze_set_user_xp(id, amount)
{
	if(!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false;
	}
	
	g_iXP[id] = amount
	
	Check_User_Level(id)
	return true;
}

public native_ze_get_user_level(id)
{
	if(!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false;
	}
	
	return g_iLevel[id]
}

public native_ze_set_user_level(id, amount)
{
	if(!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false;
	}
	
	g_iLevel[id] = amount
	
	if (get_pcvar_num(g_pCvarStartFromZero) == 1)
	{
		g_iXP[id] = 0
	}
	
	return true;
}

public native_ze_get_user_max_xp(id)
{
	if(!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false;
	}
	
	return g_iMaxXP[id]
}

public native_ze_set_user_max_xp(id, amount)
{
	if(!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false;
	}
	
	g_iMaxXP[id] = amount
	return true;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang16393\\ f0\\ fs16 \n\\ par }
*/

Re: Levels-XP System

Posted: 13 May 2020, 08:02
by AmericanuCSBD
Code for hud show after Coins Escape ? this default code show top up and is ugly

Re: Levels-XP System

Posted: 14 May 2020, 15:44
by Raheem
AmericanuCSBD wrote: 4 years ago Code for hud show after Coins Escape ? this default code show top up and is ugly
Hello,

You can change the HUD messages position from:
    1. // Messages
    2. const Float:HUD_SPECT_X = -1.0
    3. const Float:HUD_SPECT_Y = 0.70
    4. const Float:HUD_STATS_X = -1.0
    5. const Float:HUD_STATS_Y = 0.90
The first two for spectator X,Y, and the last two for players while they are alive.
You just edit the code and recompile.

level probleem

Posted: 15 Oct 2020, 20:44
by Luxurious
i don`t know why when i use ze_new_level_zero_xp 0 is shown like that !
any help ?!

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 40
#define TASK_SHOWHUD 2020
#define TASK_DOUBLE 1133
#define REPEAT_TIME 60.0
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
#define LEVELUP "levelup_ZE/ze_levelup.wav"
 
enum
{
    Host = 0,
    User,
    Pass,
    DB
}
 
new const g_iMaxLevelsXP[MAX_LEVEL] =
{
    10, // 1
    20, // 2
    40, // 3
    60, // 4 
    80, // 5
    100, // 6
    120, // 7
    140, // 8
    160, // 9
    180, // 10
    200, // 11
    230, // 12
    260, // 13
    290, // 14
    320, // 15
    360, // 16
    400, // 17
    440, // 18
    490, // 19
    550, // 20
    620, // 21
    700, // 22
    800, // 23
    900, // 24
    1000, // 25
    1200, // 26
    1400, // 27
    1600, // 28
    1800, // 29
    2000, // 30
    2200, // 31		
    2400, // 32
    2600, // 33
    2800, // 34
    3000, // 35
    3200, // 36
    3400, // 37
    3600, // 38
    3700, // 39
    4000 // 40		
}
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
new const g_szTable[] =
" \
    ALTER TABLE `test` \
    ADD IF NOT EXISTS `Level` int(20) NOT NULL DEFAULT '0', \
    ADD IF NOT EXISTS `XP` int(20) NOT NULL DEFAULT '0'; \
"
 
// Messages
const Float:HUD_SPECT_X = 0.01
const Float:HUD_SPECT_Y = 0.2
const Float:HUD_STATS_X = 0.01
const Float:HUD_STATS_Y = 0.2
 
const HUD_STATS_ZOMBIE_R = 0
const HUD_STATS_ZOMBIE_G = 255
const HUD_STATS_ZOMBIE_B = 0
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 255
const HUD_STATS_HUMAN_B = 0
 
const HUD_STATS_SPEC_R = 0
const HUD_STATS_SPEC_G = 255
const HUD_STATS_SPEC_B = 0
 
// Variables
new g_iLevel[33],
    g_iXP[33],
    g_iMaxXP[33],
    Float:g_fDamage[33],
    g_iKills[33],
    g_MsgSync,
    g_iLevelsVaultHandle,
    g_iRanksVaultHandle,
    Handle:g_hTuple,
    Fw_LevelUP,
    ForwardReturn,
    bool:g_bIsDoubleHours
 
// Cvars
new g_pCvarZombieInfect,
    g_pCvarEscapeSuccess,
    g_pCvarEnableDamage,
    g_pCvarRequiredDamage,
    g_pCvarDamageAward,
    g_pCvarStartXP,
    g_pCvarPercentageStyle,
    g_pCvarStartFromZero,
    g_pCvarAddCommas,
    g_pCvarLevelEffects,
    g_pCvarSaveType,
    g_pCvarDBInfo[4],
    g_pCvarDoubleXP
 
public plugin_natives()
{
    register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
}
 
public plugin_precache()
{
    precache_sound(LEVELUP)
}
 
public plugin_init()
{
    register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
 
    Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
   
    // Cvars
    g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "0")
    g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "1")
    g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "0")
    g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "500000000.0")
    g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    g_pCvarStartXP = register_cvar("ze_start_xp", "0")
    g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "0")
    g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "0")
    g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "0")
    g_pCvarDoubleXP = register_cvar("ze_double_xp", "15-22")
 
    g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
    g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
    g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
    g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
    g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
 
    if (get_pcvar_num(g_pCvarSaveType))
    {
        set_task(0.1, "Delay_MySQL_Init")
    }

    DoubleHours()

    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", TASK_DOUBLE, _, _, "b")
    }
}
 
public plugin_end()
{
    if (get_pcvar_num(g_pCvarSaveType))
    {
        if (g_hTuple != Empty_Handle)
        {
            SQL_FreeHandle(g_hTuple)
        }
    }
}
 
public Delay_MySQL_Init()
{
    MySQL_Init()
}
 
public MySQL_Init()
{
    if (!get_pcvar_num(g_pCvarSaveType))
        return
   
    new szHost[64], szUser[32], szPass[32], szDB[128]
   
    get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
   
    g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
   
    // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    new iErrorCode, szError[512], Handle:hSQLConnection
   
    hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
   
    if (hSQLConnection != Empty_Handle)
    {
        log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
        SQL_FreeHandle(hSQLConnection)
    }
    else
    {
        // Disable plugin
        set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
    }
   
    SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
}
 
public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public client_putinserver(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
   
    // Just 1 second delay
    set_task(1.0, "DelayLoad", id)
 
    // Other tasks
    set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
   
    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", id+TASK_DOUBLE, _, _, "b")
    }
}
 
public HappyHours(taskid)
{
    DoubleHours()

    if (!g_bIsDoubleHours)
        remove_task(taskid)
   
    new szDoubleHours[32]
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    set_dhudmessage(0, 255, 0, -1.0, 0.20, 0, 0.0, 10.0)
    show_dhudmessage(0, "DOUBLE XP: %s", szDoubleHours)
}
 
public DelayLoad(id)
{
    // Load his data
    LoadData(id)
}
 
public client_disconnected(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
       
    remove_task(id+TASK_SHOWHUD)
    remove_task(id)
}
 
public Show_Hud(taskid)
{  
    new iPlayer = ID_SHOWHUD
   
    if (!is_user_alive(iPlayer))
    {
        iPlayer = pev(iPlayer, pev_iuser2)
       
        if (!is_user_alive(iPlayer))
            return
    }
   
    if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    {
        if(iPlayer != ID_SHOWHUD)
        {
            set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %0.2f %^nInfections: %d/5", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0, g_iKills[ID_SHOWHUD])
        }
        else
        {
            set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | Escape: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
    }
    else
    {
        if(iPlayer != ID_SHOWHUD)
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szSpecXP[15], szSpecMaxXP[15]
               
                AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
                AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
               
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
            }  
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szZombieXP[15], szZombieMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
               
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %s/%s^nInfections: %d/5", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP, g_iKills[ID_SHOWHUD])
            }
            else
            {
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %d/%d^nInfections: %d/5", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD], g_iKills[ID_SHOWHUD])
            }
        } 
        else
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szHumanXP[15], szHumanMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
               
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d ^nEscape: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
    }
}
 
public ze_roundend(WinTeam)
{
    if (WinTeam == ZE_TEAM_HUMAN)
    {
        new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarEscapeSuccess) * 2) : get_pcvar_num(g_pCvarEscapeSuccess)

        for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
        {
            if (!is_user_alive(id) || ze_is_user_zombie(id))
                continue
           
            Reward(id, (g_iXP[id] + iXP))
        }
    }
   
    remove_task(TASK_SHOWHUD)
}
 
public Check_User_Level(id)
{
    if (!is_user_connected(id))
        return
 
    if (g_iLevel[id] < MAX_LEVEL)
    {
    	new szName[32]

        while (g_iXP[id] > g_iMaxXP[id])
        {
            if (get_pcvar_num(g_pCvarStartFromZero) == 1)
            {
                g_iXP[id] = 0
            }
 
	g_iLevel[id]++
        	g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
	   get_user_name(id, szName, charsmax(szName))
            ze_colored_print(0, "!tGrts For Our Brother !g%s For Become !tLevel %i!y!", szName, g_iLevel[id])
            ExecuteForward(Fw_LevelUP, ForwardReturn, id)
            SaveData(id)
            PlaySound(id, LEVELUP)
           
            if (get_pcvar_num(g_pCvarLevelEffects) != 0)
            {
                // Screen Fade
                message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
                write_short(4096*2)
                write_short(4096*5)
                write_short(0x0001)
                write_byte(random(256))
                write_byte(random(256))
                write_byte(random(256))
                write_byte(150)
                message_end()
               
                // Screen Shake
                message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
                write_short(255<<14)
                write_short(10<<14)
                write_short(255<<14)
                message_end()
            }
        }
    }
}
 
public ze_user_infected(iVictim, iInfector)
{
    if (iInfector == 0)
        return
 
    g_iKills[iInfector]++
    new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarZombieInfect) * 2) : get_pcvar_num(g_pCvarZombieInfect)
    Reward(iInfector, (g_iXP[iInfector] + iXP))
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Player Damage Himself
    if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
        return HC_CONTINUE
   
    // Same Team?
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // Store Damage For every Player
    g_fDamage[iAttacker] += fDamage
   
    // Damage Calculator Equal or Higher than needed damage
    if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    {
        // Player did damage that a multiplication of the cvar? Increase coins by this factor
        new iMultiplier = floatround(g_fDamage[iAttacker] / get_pcvar_float(g_pCvarRequiredDamage))
        new iXP = ((g_bIsDoubleHours ? (get_pcvar_num(g_pCvarDamageAward) * 2) : get_pcvar_num(g_pCvarDamageAward)) * iMultiplier)
        Reward(iAttacker, (g_iXP[iAttacker] + iXP))
       
        // Rest The Damage Calculator
        g_fDamage[iAttacker] = 0.0
    }
    return HC_CONTINUE
}
 
public Reward(id, XP)
{
    if ((g_iLevel[id] + 1) < MAX_LEVEL)
    {
        g_iXP[id] = XP
        Check_User_Level(id)
    }
    else
    {
    	if ((g_iXP[id] + XP) >= g_iMaxLevelsXP[MAX_LEVEL - 1])
        {
            g_iXP[id] = g_iMaxXP[id] = g_iMaxLevelsXP[MAX_LEVEL - 1]
        }
    }
    SaveData(id)
}
 
public ze_game_started()
{
	set_task(2.0, "RestKills")
}

public RestKills()
{
	for (new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
	{
		g_iKills[i] = 0
	}
}

public SaveData(id)
{
    new szAuthID[35], szName[32]
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
 
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256]
        formatex(szData , charsmax(szData), "%i %i", g_iLevel[id], g_iXP[id])
       
        // Open the Vaults
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
        g_iRanksVaultHandle = nvault_open(g_szRanksVault)
 
        // Saves His Data
        nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
        nvault_set(g_iRanksVaultHandle, szAuthID, szName)
       
        // Close Vaults
        nvault_close(g_iLevelsVaultHandle)
        nvault_close(g_iRanksVaultHandle)
    }
    else
    {
        new szQuery[128]
        formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Level` = '%d', `XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], szAuthID)
        SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
    }
}
 
public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public LoadData(id)
{
    new szAuthID[35]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
   
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256], iTimestamp, iExists
       
        // Open the Vault
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
       
        iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
       
        // Close Vault
        nvault_close(g_iLevelsVaultHandle)
       
        if (!iExists)
        {
            g_iLevel[id] = 0
            g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
            SaveData(id)
        }
        else
        {
            new iLevel[32], iXP[32]
            parse(szData, iLevel, 31, iXP, 31)
           
            g_iLevel[id] = str_to_num(iLevel)
            g_iXP[id] = str_to_num(iXP)
        }
 
        g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
    }
    else
    {
        new szQuery[128], szData[5]
        formatex(szQuery, charsmax(szQuery), "SELECT * FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
   
        num_to_str(id, szData, charsmax(szData))
        SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    }
}
 
public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
{
    if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
        return
   
    new id = str_to_num(szData)
   
    // No results for this query means this is new player
    if (!SQL_NumResults(hQuery))
    {
        g_iLevel[id] = 0
        g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
    }
    else
    {
        g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
        g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
    }
 
    g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
}
 
public native_ze_get_user_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iXP[id]
}
 
public native_ze_set_user_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
    
    DoubleHours()
    new addedXP = (amount - g_iXP[id])
    new iXP = g_bIsDoubleHours ? (addedXP * 2) : addedXP
    Reward(id, g_iXP[id] + iXP)
    return true
}
 
public native_ze_get_user_level(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iLevel[id]
}
 
public native_ze_set_user_level(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    if (amount > MAX_LEVEL)
    {
        log_error(AMX_ERR_NATIVE, "Level must be less than or equal to MAX_LEVEL (%d)", MAX_LEVEL)
        return false
    }
 
    g_iLevel[id] = amount
   
    if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    {
        g_iXP[id] = 0
    }
    SaveData(id)
   
    return true
}
 
public native_ze_get_user_max_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    return g_iMaxXP[id]
}
 
stock DoubleHours()
{
    new szTime[3], szDoubleHours[32], szDoubleHours_Start[32], szDoubleHours_End[32]
    get_time("%H", szTime, charsmax(szTime))
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    for (new ch = 0; ch <= charsmax(szDoubleHours); ch++)
    {
        if (szDoubleHours[ch] == '-')
            szDoubleHours[ch] = ' '
    }
   
    parse(szDoubleHours, szDoubleHours_Start, charsmax(szDoubleHours_Start), szDoubleHours_End, charsmax(szDoubleHours_End))
   
    new iTime, iDoubleHourStart, iDoubleHourEnd
   
    iTime = str_to_num(szTime)
    iDoubleHourStart = str_to_num(szDoubleHours_Start)
    iDoubleHourEnd = str_to_num(szDoubleHours_End)
   
    if (iDoubleHourEnd > iTime >= iDoubleHourStart)
    {
        g_bIsDoubleHours = true
    }
    else
    {
        g_bIsDoubleHours = false
    }
}

Re: level probleem

Posted: 16 Oct 2020, 05:34
by Raheem
Change: To:

Re: level probleem

Posted: 16 Oct 2020, 16:57
by Luxurious
Raheem wrote: 3 years ago Change: To:
Edit : Sloved ! Thx

Re: Levels-XP System

Posted: 10 Apr 2021, 14:55
by Raheem
Fixed MySQL versions:
    1. #include <zombie_escape>
    2.  
    3. // Defines
    4. #define MAX_LEVEL 50
    5. #define MAX_XP 500000
    6. #define TASK_SHOWHUD 2020
    7. #define ID_SHOWHUD (taskid - TASK_SHOWHUD)
    8. #define LEVELUP "levelup_ZE/ze_levelup.wav"
    9.  
    10. enum
    11. {
    12.     Host = 0,
    13.     User,
    14.     Pass,
    15.     DB
    16. }
    17.  
    18. // Constants
    19. new const g_szLevelsVault[] = "Levels"
    20. new const g_szRanksVault[] = "Ranks"
    21. new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
    22. new const g_szTable[] =
    23. " \
    24.     CREATE TABLE IF NOT EXISTS `ze_levels` \
    25.     ( \
    26.         `SteamID` varchar(34) NOT NULL, \
    27.         `Level` int(16) NOT NULL, \
    28.         `XP` int(16) NOT NULL, \
    29.         `Max_XP` int(16) NOT NULL, \
    30.         PRIMARY KEY (`SteamID`) \
    31.     ); \
    32. "
    33.  
    34. // Messages
    35. const Float:HUD_SPECT_X = -1.0
    36. const Float:HUD_SPECT_Y = 0.70
    37. const Float:HUD_STATS_X = -1.0
    38. const Float:HUD_STATS_Y = 0.90
    39.  
    40. const HUD_STATS_ZOMBIE_R = 200
    41. const HUD_STATS_ZOMBIE_G = 220
    42. const HUD_STATS_ZOMBIE_B = 0
    43.  
    44. const HUD_STATS_HUMAN_R = 0
    45. const HUD_STATS_HUMAN_G = 200
    46. const HUD_STATS_HUMAN_B = 210
    47.  
    48. const HUD_STATS_SPEC_R = 100
    49. const HUD_STATS_SPEC_G = 100
    50. const HUD_STATS_SPEC_B = 100
    51.  
    52. // Variables
    53. new g_iLevel[33],
    54.     g_iXP[33],
    55.     g_iMaxXP[33],
    56.     Float:g_fDamage[33],
    57.     g_MsgSync,
    58.     g_iLevelsVaultHandle,
    59.     g_iRanksVaultHandle,
    60.     Handle:g_hTuple,
    61.     Fw_LevelUP,
    62.     ForwardReturn
    63.  
    64. // Cvars
    65. new g_pCvarZombieInfect,
    66.     g_pCvarEscapeSuccess,
    67.     g_pCvarEnableDamage,
    68.     g_pCvarRequiredDamage,
    69.     g_pCvarDamageAward,
    70.     g_pCvarStartXP,
    71.     g_pCvarMaxLevelsIncrement,
    72.     g_pCvarMaxXPFirstLevel,
    73.     g_pCvarPercentageStyle,
    74.     g_pCvarStartFromZero,
    75.     g_pCvarAddCommas,
    76.     g_pCvarLevelEffects,
    77.     g_pCvarSaveType,
    78.     g_pCvarDBInfo[4]
    79.  
    80. public plugin_natives()
    81. {
    82.     register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    83.     register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    84.     register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    85.     register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    86.     register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
    87.     register_native("ze_set_user_max_xp", "native_ze_set_user_max_xp", 1)
    88. }
    89.  
    90. public plugin_precache()
    91. {
    92.     precache_sound(LEVELUP)
    93. }
    94.  
    95. public plugin_init()
    96. {
    97.     register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
    98.    
    99.     // Hook Chains
    100.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    101.  
    102.     Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
    103.    
    104.     // Cvars
    105.     g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    106.     g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    107.     g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    108.     g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    109.     g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    110.     g_pCvarStartXP = register_cvar("ze_start_xp", "50")
    111.     g_pCvarMaxLevelsIncrement = register_cvar("ze_maxlevels_increment", "2.0")
    112.     g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "100")
    113.     g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "1")
    114.     g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    115.     g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
    116.     g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
    117.     g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
    118.     g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
    119.     g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
    120.     g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
    121.     g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
    122.    
    123.     // Messages
    124.     g_MsgSync = CreateHudSyncObj()
    125.  
    126.     if (get_pcvar_num(g_pCvarSaveType))
    127.     {
    128.         set_task(0.1, "Delay_MySQL_Init")
    129.     }
    130. }
    131.  
    132. public plugin_end()
    133. {
    134.     if (get_pcvar_num(g_pCvarSaveType))
    135.     {
    136.         if (g_hTuple != Empty_Handle)
    137.         {
    138.             SQL_FreeHandle(g_hTuple)
    139.         }
    140.     }
    141. }
    142.  
    143. public Delay_MySQL_Init()
    144. {
    145.     MySQL_Init()
    146. }
    147.  
    148. public MySQL_Init()
    149. {
    150.     if (!get_pcvar_num(g_pCvarSaveType))
    151.         return
    152.    
    153.     new szHost[64], szUser[32], szPass[32], szDB[128]
    154.    
    155.     get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    156.     get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    157.     get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    158.     get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
    159.    
    160.     g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
    161.    
    162.     // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    163.     new iErrorCode, szError[512], Handle:hSQLConnection
    164.    
    165.     hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
    166.    
    167.     if (hSQLConnection != Empty_Handle)
    168.     {
    169.         log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
    170.         SQL_FreeHandle(hSQLConnection)
    171.     }
    172.     else
    173.     {
    174.         // Disable plugin
    175.         set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
    176.     }
    177.    
    178.     SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
    179. }
    180.  
    181. public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    182. {
    183.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    184. }
    185.  
    186. public client_putinserver(id)
    187. {
    188.     if(is_user_hltv(id) || is_user_bot(id))
    189.         return
    190.    
    191.     // Just 1 second delay
    192.     set_task(1.0, "DelayLoad", id)
    193.  
    194.     // Other tasks
    195.     set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
    196.     set_task(0.1, "Check_MaxXP", id, _, _, "b")
    197. }
    198.  
    199. public DelayLoad(id)
    200. {
    201.     // Load his data
    202.     LoadData(id)
    203. }
    204.  
    205. public client_disconnected(id)
    206. {
    207.     if(is_user_hltv(id) || is_user_bot(id))
    208.         return
    209.        
    210.     remove_task(id+TASK_SHOWHUD)
    211.     remove_task(id)
    212. }
    213.  
    214. public Check_MaxXP(id)
    215. {
    216.     new iCurrentMaxXP = g_iMaxXP[id]
    217.    
    218.     new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    219.    
    220.     for (new i = 1; i <= g_iLevel[id]; i++)
    221.     {
    222.         iMaxXP = floatround(float(iMaxXP) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
    223.     }
    224.    
    225.     if (iCurrentMaxXP != iMaxXP)
    226.     {
    227.         g_iMaxXP[id] = iMaxXP
    228.     }
    229. }
    230.  
    231. public Show_Hud(taskid)
    232. {  
    233.     new iPlayer = ID_SHOWHUD
    234.    
    235.     if (!is_user_alive(iPlayer))
    236.     {
    237.         iPlayer = pev(iPlayer, pev_iuser2)
    238.        
    239.         if (!is_user_alive(iPlayer))
    240.             return
    241.     }
    242.    
    243.     if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    244.     {
    245.         if(iPlayer != ID_SHOWHUD)
    246.         {
    247.             set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    248.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
    249.         }
    250.         else if (ze_is_user_zombie(iPlayer))
    251.         {
    252.             set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    253.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
    254.         }
    255.         else
    256.         {
    257.             set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    258.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
    259.         }
    260.     }
    261.     else
    262.     {
    263.         if(iPlayer != ID_SHOWHUD)
    264.         {
    265.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
    266.             {
    267.                 new szSpecXP[15], szSpecMaxXP[15]
    268.                
    269.                 AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
    270.                 AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
    271.                
    272.                 set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    273.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
    274.             }
    275.             else
    276.             {
    277.                 set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    278.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
    279.             }  
    280.         }
    281.         else if (ze_is_user_zombie(iPlayer))
    282.         {
    283.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
    284.             {
    285.                 new szZombieXP[15], szZombieMaxXP[15]
    286.                
    287.                 AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
    288.                 AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
    289.                
    290.                 set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    291.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
    292.             }
    293.             else
    294.             {
    295.                 set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    296.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
    297.             }
    298.         }
    299.         else
    300.         {
    301.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
    302.             {
    303.                 new szHumanXP[15], szHumanMaxXP[15]
    304.                
    305.                 AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
    306.                 AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
    307.                
    308.                 set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    309.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
    310.             }
    311.             else
    312.             {
    313.                 set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    314.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
    315.             }
    316.         }
    317.     }
    318. }
    319.  
    320. public ze_roundend(WinTeam)
    321. {
    322.     if (WinTeam == ZE_TEAM_HUMAN)
    323.     {
    324.         for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
    325.         {
    326.             if (!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
    327.                 continue
    328.            
    329.             g_iXP[id] += get_pcvar_num(g_pCvarEscapeSuccess)
    330.             SaveData(id)
    331.             Check_User_Level(id)
    332.         }
    333.     }
    334.    
    335.     remove_task(TASK_SHOWHUD)
    336. }
    337.  
    338. public Check_User_Level(id)
    339. {
    340.     if(!is_user_connected(id))
    341.         return
    342.  
    343.     if(g_iXP[id] >= g_iMaxXP[id])
    344.     {
    345.         if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    346.         {
    347.             g_iXP[id] = 0
    348.         }
    349.        
    350.         new szName[32]
    351.         g_iLevel[id] ++
    352.         g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
    353.         get_user_name(id, szName, charsmax(szName))
    354.         ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
    355.         ExecuteForward(Fw_LevelUP, ForwardReturn, id)
    356.        
    357.         SaveData(id)
    358.        
    359.         PlaySound(id, LEVELUP)
    360.        
    361.         if (get_pcvar_num(g_pCvarLevelEffects) != 0)
    362.         {
    363.             // Screen Fade
    364.             message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
    365.             write_short(4096*2)
    366.             write_short(4096*5)
    367.             write_short(0x0001)
    368.             write_byte(random(256))
    369.             write_byte(random(256))
    370.             write_byte(random(256))
    371.             write_byte(150)
    372.             message_end()
    373.            
    374.             // Screen Shake
    375.             message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
    376.             write_short(255<<14)
    377.             write_short(10<<14)
    378.             write_short(255<<14)
    379.             message_end()
    380.         }
    381.     }
    382. }
    383.  
    384. public ze_user_infected(iVictim, iInfector)
    385. {
    386.     if (iInfector == 0)
    387.         return
    388.    
    389.     g_iXP[iInfector] += get_pcvar_num(g_pCvarZombieInfect)
    390.     SaveData(iInfector)
    391.     Check_User_Level(iInfector)
    392. }
    393.  
    394. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    395. {
    396.     // Player Damage Himself
    397.     if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
    398.         return HC_CONTINUE
    399.    
    400.     // Same Team?
    401.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
    402.         return HC_CONTINUE
    403.    
    404.     // Store Damage For every Player
    405.     g_fDamage[iAttacker] += fDamage
    406.    
    407.     // Damage Calculator Equal or Higher than needed damage
    408.     if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    409.     {
    410.         // Give Player The Coins
    411.         g_iXP[iAttacker] += get_pcvar_num(g_pCvarDamageAward)
    412.         SaveData(iAttacker)
    413.         Check_User_Level(iAttacker)
    414.        
    415.         // Rest The Damage Calculator
    416.         g_fDamage[iAttacker] = 0.0
    417.     }
    418.     return HC_CONTINUE
    419. }
    420.  
    421. public SaveData(id)
    422. {
    423.     new szAuthID[35], szName[32]
    424.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    425.     get_user_name(id, szName, charsmax(szName))
    426.    
    427.     // Set Him to max if he Higher than Max Value
    428.     if (g_iLevel[id] > MAX_LEVEL)
    429.     {
    430.         g_iLevel[id] = MAX_LEVEL
    431.     }
    432.    
    433.     if (g_iXP[id] > MAX_XP)
    434.     {
    435.         g_iXP[id] = MAX_XP
    436.     }
    437.  
    438.     if (!get_pcvar_num(g_pCvarSaveType))
    439.     {
    440.         new szData[256]
    441.         formatex(szData , charsmax(szData), "%i %i %i", g_iLevel[id], g_iXP[id], g_iMaxXP[id])
    442.        
    443.         // Open the Vaults
    444.         g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
    445.         g_iRanksVaultHandle = nvault_open(g_szRanksVault)
    446.  
    447.         // Saves His Data
    448.         nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
    449.         nvault_set(g_iRanksVaultHandle, szAuthID, szName)
    450.        
    451.         // Close Vaults
    452.         nvault_close(g_iLevelsVaultHandle)
    453.         nvault_close(g_iRanksVaultHandle)
    454.     }
    455.     else
    456.     {
    457.         new szQuery[128]
    458.         formatex(szQuery, charsmax(szQuery), "UPDATE `ze_levels` SET `Level` = '%d', `XP` = '%d', `Max_XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], g_iMaxXP[id], szAuthID)
    459.         SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
    460.     }
    461. }
    462.  
    463. public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    464. {
    465.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    466. }
    467.  
    468. public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    469. {
    470.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    471. }
    472.  
    473. public LoadData(id)
    474. {
    475.     new szData[256], szAuthID[35]
    476.    
    477.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    478.    
    479.     if (!get_pcvar_num(g_pCvarSaveType))
    480.     {
    481.         // Useless Variable
    482.         new iTimestamp, iExists
    483.        
    484.         // Open the Vault
    485.         g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
    486.        
    487.         iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
    488.        
    489.         // Close Vault
    490.         nvault_close(g_iLevelsVaultHandle)
    491.        
    492.         if (!iExists)
    493.         {
    494.             g_iLevel[id] = 0
    495.             g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
    496.             g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    497.             SaveData(id)
    498.         }
    499.         else
    500.         {
    501.             new iLevel[32], iXP[32], iMaxLevel[32]
    502.             parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
    503.            
    504.             g_iLevel[id] = str_to_num(iLevel)
    505.             g_iXP[id] = str_to_num(iXP)
    506.             g_iMaxXP[id] = str_to_num(iMaxLevel)
    507.         }
    508.     }
    509.     else
    510.     {
    511.         new szQuery[128], szData[5]
    512.         formatex(szQuery, charsmax(szQuery), "SELECT * FROM `ze_levels` WHERE ( `SteamID` = '%s' );", szAuthID)
    513.      
    514.         num_to_str(id, szData, charsmax(szData))
    515.         SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    516.     }
    517. }
    518.  
    519. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
    520. {
    521.     if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
    522.         return
    523.    
    524.     new id = str_to_num(szData)
    525.    
    526.     // No results for this query means this is new player
    527.     if (!SQL_NumResults(hQuery))
    528.     {
    529.         new szSteamId[36], szQuery[128]
    530.         get_user_authid(id, szSteamId, charsmax(szSteamId))
    531.  
    532.         g_iLevel[id] = 0
    533.         g_iXP[id] = 0
    534.         g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    535.         return
    536.     }
    537.  
    538.     g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
    539.     g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
    540.     g_iMaxXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Max_XP"))
    541. }
    542.  
    543. public native_ze_get_user_xp(id)
    544. {
    545.     if(!is_user_connected(id))
    546.     {
    547.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    548.         return false;
    549.     }
    550.    
    551.     return g_iXP[id]
    552. }
    553.  
    554. public native_ze_set_user_xp(id, amount)
    555. {
    556.     if(!is_user_connected(id))
    557.     {
    558.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    559.         return false;
    560.     }
    561.    
    562.     g_iXP[id] = amount
    563.    
    564.     Check_User_Level(id)
    565.     return true;
    566. }
    567.  
    568. public native_ze_get_user_level(id)
    569. {
    570.     if(!is_user_connected(id))
    571.     {
    572.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    573.         return false;
    574.     }
    575.    
    576.     return g_iLevel[id]
    577. }
    578.  
    579. public native_ze_set_user_level(id, amount)
    580. {
    581.     if(!is_user_connected(id))
    582.     {
    583.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    584.         return false;
    585.     }
    586.    
    587.     g_iLevel[id] = amount
    588.    
    589.     if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    590.     {
    591.         g_iXP[id] = 0
    592.     }
    593.    
    594.     return true;
    595. }
    596.  
    597. public native_ze_get_user_max_xp(id)
    598. {
    599.     if(!is_user_connected(id))
    600.     {
    601.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    602.         return false;
    603.     }
    604.    
    605.     return g_iMaxXP[id]
    606. }
    607.  
    608. public native_ze_set_user_max_xp(id, amount)
    609. {
    610.     if(!is_user_connected(id))
    611.     {
    612.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    613.         return false;
    614.     }
    615.    
    616.     g_iMaxXP[id] = amount
    617.     return true;
    618. }
OR:
    1. #include <zombie_escape>
    2.  
    3. // Defines
    4. #define MAX_LEVEL 50
    5. #define MAX_XP 500000
    6. #define TASK_SHOWHUD 2020
    7. #define ID_SHOWHUD (taskid - TASK_SHOWHUD)
    8. #define LEVELUP "levelup_ZE/ze_levelup.wav"
    9.  
    10. enum
    11. {
    12.     Host = 0,
    13.     User,
    14.     Pass,
    15.     DB
    16. }
    17.  
    18. // Constants
    19. new const g_szLevelsVault[] = "Levels"
    20. new const g_szRanksVault[] = "Ranks"
    21. new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
    22. new const g_szTable[] =
    23. " \
    24.     ALTER TABLE `zombie_escape` \
    25.     ADD COLUMN `Level` int(20) NOT NULL DEFAULT '0', \
    26.     ADD COLUMN `XP` int(20) NOT NULL DEFAULT '0', \
    27.     ADD COLUMN `Max_XP` int(20) NOT NULL DEFAULT '0'; \
    28. "
    29.  
    30. // Messages
    31. const Float:HUD_SPECT_X = -1.0
    32. const Float:HUD_SPECT_Y = 0.70
    33. const Float:HUD_STATS_X = -1.0
    34. const Float:HUD_STATS_Y = 0.90
    35.  
    36. const HUD_STATS_ZOMBIE_R = 200
    37. const HUD_STATS_ZOMBIE_G = 220
    38. const HUD_STATS_ZOMBIE_B = 0
    39.  
    40. const HUD_STATS_HUMAN_R = 0
    41. const HUD_STATS_HUMAN_G = 200
    42. const HUD_STATS_HUMAN_B = 210
    43.  
    44. const HUD_STATS_SPEC_R = 100
    45. const HUD_STATS_SPEC_G = 100
    46. const HUD_STATS_SPEC_B = 100
    47.  
    48. // Variables
    49. new g_iLevel[33],
    50.     g_iXP[33],
    51.     g_iMaxXP[33],
    52.     Float:g_fDamage[33],
    53.     g_MsgSync,
    54.     g_iLevelsVaultHandle,
    55.     g_iRanksVaultHandle,
    56.     Handle:g_hTuple,
    57.     Fw_LevelUP,
    58.     ForwardReturn
    59.  
    60. // Cvars
    61. new g_pCvarZombieInfect,
    62.     g_pCvarEscapeSuccess,
    63.     g_pCvarEnableDamage,
    64.     g_pCvarRequiredDamage,
    65.     g_pCvarDamageAward,
    66.     g_pCvarStartXP,
    67.     g_pCvarMaxLevelsIncrement,
    68.     g_pCvarMaxXPFirstLevel,
    69.     g_pCvarPercentageStyle,
    70.     g_pCvarStartFromZero,
    71.     g_pCvarAddCommas,
    72.     g_pCvarLevelEffects,
    73.     g_pCvarSaveType,
    74.     g_pCvarDBInfo[4]
    75.  
    76. public plugin_natives()
    77. {
    78.     register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    79.     register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    80.     register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    81.     register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    82.     register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
    83.     register_native("ze_set_user_max_xp", "native_ze_set_user_max_xp", 1)
    84. }
    85.  
    86. public plugin_precache()
    87. {
    88.     precache_sound(LEVELUP)
    89. }
    90.  
    91. public plugin_init()
    92. {
    93.     register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
    94.    
    95.     // Hook Chains
    96.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    97.  
    98.     Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
    99.    
    100.     // Cvars
    101.     g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    102.     g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    103.     g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    104.     g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    105.     g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    106.     g_pCvarStartXP = register_cvar("ze_start_xp", "50")
    107.     g_pCvarMaxLevelsIncrement = register_cvar("ze_maxlevels_increment", "2.0")
    108.     g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "100")
    109.     g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "1")
    110.     g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    111.     g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
    112.     g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
    113.     g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
    114.     g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
    115.     g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
    116.     g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
    117.     g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
    118.    
    119.     // Messages
    120.     g_MsgSync = CreateHudSyncObj()
    121.  
    122.     if (get_pcvar_num(g_pCvarSaveType))
    123.     {
    124.         set_task(0.1, "Delay_MySQL_Init")
    125.     }
    126. }
    127.  
    128. public plugin_end()
    129. {
    130.     if (get_pcvar_num(g_pCvarSaveType))
    131.     {
    132.         if (g_hTuple != Empty_Handle)
    133.         {
    134.             SQL_FreeHandle(g_hTuple)
    135.         }
    136.     }
    137. }
    138.  
    139. public Delay_MySQL_Init()
    140. {
    141.     MySQL_Init()
    142. }
    143.  
    144. public MySQL_Init()
    145. {
    146.     if (!get_pcvar_num(g_pCvarSaveType))
    147.         return
    148.    
    149.     new szHost[64], szUser[32], szPass[32], szDB[128]
    150.    
    151.     get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    152.     get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    153.     get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    154.     get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
    155.    
    156.     g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
    157.    
    158.     // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    159.     new iErrorCode, szError[512], Handle:hSQLConnection
    160.    
    161.     hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
    162.    
    163.     if (hSQLConnection != Empty_Handle)
    164.     {
    165.         log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
    166.         SQL_FreeHandle(hSQLConnection)
    167.     }
    168.     else
    169.     {
    170.         // Disable plugin
    171.         set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
    172.     }
    173.    
    174.     SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
    175. }
    176.  
    177. public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    178. {
    179.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    180. }
    181.  
    182. public client_putinserver(id)
    183. {
    184.     if(is_user_hltv(id) || is_user_bot(id))
    185.         return
    186.    
    187.     // Just 1 second delay
    188.     set_task(1.0, "DelayLoad", id)
    189.  
    190.     // Other tasks
    191.     set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
    192.     set_task(0.1, "Check_MaxXP", id, _, _, "b")
    193. }
    194.  
    195. public DelayLoad(id)
    196. {
    197.     // Load his data
    198.     LoadData(id)
    199. }
    200.  
    201. public client_disconnected(id)
    202. {
    203.     if(is_user_hltv(id) || is_user_bot(id))
    204.         return
    205.        
    206.     remove_task(id+TASK_SHOWHUD)
    207.     remove_task(id)
    208. }
    209.  
    210. public Check_MaxXP(id)
    211. {
    212.     new iCurrentMaxXP = g_iMaxXP[id]
    213.    
    214.     new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    215.    
    216.     for (new i = 1; i <= g_iLevel[id]; i++)
    217.     {
    218.         iMaxXP = floatround(float(iMaxXP) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
    219.     }
    220.    
    221.     if (iCurrentMaxXP != iMaxXP)
    222.     {
    223.         g_iMaxXP[id] = iMaxXP
    224.     }
    225. }
    226.  
    227. public Show_Hud(taskid)
    228. {  
    229.     new iPlayer = ID_SHOWHUD
    230.    
    231.     if (!is_user_alive(iPlayer))
    232.     {
    233.         iPlayer = pev(iPlayer, pev_iuser2)
    234.        
    235.         if (!is_user_alive(iPlayer))
    236.             return
    237.     }
    238.    
    239.     if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    240.     {
    241.         if(iPlayer != ID_SHOWHUD)
    242.         {
    243.             set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    244.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
    245.         }
    246.         else if (ze_is_user_zombie(iPlayer))
    247.         {
    248.             set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    249.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
    250.         }
    251.         else
    252.         {
    253.             set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    254.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
    255.         }
    256.     }
    257.     else
    258.     {
    259.         if(iPlayer != ID_SHOWHUD)
    260.         {
    261.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
    262.             {
    263.                 new szSpecXP[15], szSpecMaxXP[15]
    264.                
    265.                 AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
    266.                 AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
    267.                
    268.                 set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    269.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
    270.             }
    271.             else
    272.             {
    273.                 set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    274.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
    275.             }  
    276.         }
    277.         else if (ze_is_user_zombie(iPlayer))
    278.         {
    279.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
    280.             {
    281.                 new szZombieXP[15], szZombieMaxXP[15]
    282.                
    283.                 AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
    284.                 AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
    285.                
    286.                 set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    287.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
    288.             }
    289.             else
    290.             {
    291.                 set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    292.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
    293.             }
    294.         }
    295.         else
    296.         {
    297.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
    298.             {
    299.                 new szHumanXP[15], szHumanMaxXP[15]
    300.                
    301.                 AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
    302.                 AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
    303.                
    304.                 set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    305.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
    306.             }
    307.             else
    308.             {
    309.                 set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
    310.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
    311.             }
    312.         }
    313.     }
    314. }
    315.  
    316. public ze_roundend(WinTeam)
    317. {
    318.     if (WinTeam == ZE_TEAM_HUMAN)
    319.     {
    320.         for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
    321.         {
    322.             if (!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
    323.                 continue
    324.            
    325.             g_iXP[id] += get_pcvar_num(g_pCvarEscapeSuccess)
    326.             SaveData(id)
    327.             Check_User_Level(id)
    328.         }
    329.     }
    330.    
    331.     remove_task(TASK_SHOWHUD)
    332. }
    333.  
    334. public Check_User_Level(id)
    335. {
    336.     if(!is_user_connected(id))
    337.         return
    338.  
    339.     if(g_iXP[id] >= g_iMaxXP[id])
    340.     {
    341.         if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    342.         {
    343.             g_iXP[id] = 0
    344.         }
    345.        
    346.         new szName[32]
    347.         g_iLevel[id] ++
    348.         g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
    349.         get_user_name(id, szName, charsmax(szName))
    350.         ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
    351.         ExecuteForward(Fw_LevelUP, ForwardReturn, id)
    352.        
    353.         SaveData(id)
    354.        
    355.         PlaySound(id, LEVELUP)
    356.        
    357.         if (get_pcvar_num(g_pCvarLevelEffects) != 0)
    358.         {
    359.             // Screen Fade
    360.             message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
    361.             write_short(4096*2)
    362.             write_short(4096*5)
    363.             write_short(0x0001)
    364.             write_byte(random(256))
    365.             write_byte(random(256))
    366.             write_byte(random(256))
    367.             write_byte(150)
    368.             message_end()
    369.            
    370.             // Screen Shake
    371.             message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
    372.             write_short(255<<14)
    373.             write_short(10<<14)
    374.             write_short(255<<14)
    375.             message_end()
    376.         }
    377.     }
    378. }
    379.  
    380. public ze_user_infected(iVictim, iInfector)
    381. {
    382.     if (iInfector == 0)
    383.         return
    384.    
    385.     g_iXP[iInfector] += get_pcvar_num(g_pCvarZombieInfect)
    386.     SaveData(iInfector)
    387.     Check_User_Level(iInfector)
    388. }
    389.  
    390. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    391. {
    392.     // Player Damage Himself
    393.     if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
    394.         return HC_CONTINUE
    395.    
    396.     // Same Team?
    397.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
    398.         return HC_CONTINUE
    399.    
    400.     // Store Damage For every Player
    401.     g_fDamage[iAttacker] += fDamage
    402.    
    403.     // Damage Calculator Equal or Higher than needed damage
    404.     if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    405.     {
    406.         // Give Player The Coins
    407.         g_iXP[iAttacker] += get_pcvar_num(g_pCvarDamageAward)
    408.         SaveData(iAttacker)
    409.         Check_User_Level(iAttacker)
    410.        
    411.         // Rest The Damage Calculator
    412.         g_fDamage[iAttacker] = 0.0
    413.     }
    414.     return HC_CONTINUE
    415. }
    416.  
    417. public SaveData(id)
    418. {
    419.     new szAuthID[35], szName[32]
    420.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    421.     get_user_name(id, szName, charsmax(szName))
    422.    
    423.     // Set Him to max if he Higher than Max Value
    424.     if (g_iLevel[id] > MAX_LEVEL)
    425.     {
    426.         g_iLevel[id] = MAX_LEVEL
    427.     }
    428.    
    429.     if (g_iXP[id] > MAX_XP)
    430.     {
    431.         g_iXP[id] = MAX_XP
    432.     }
    433.  
    434.     if (!get_pcvar_num(g_pCvarSaveType))
    435.     {
    436.         new szData[256]
    437.         formatex(szData , charsmax(szData), "%i %i %i", g_iLevel[id], g_iXP[id], g_iMaxXP[id])
    438.        
    439.         // Open the Vaults
    440.         g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
    441.         g_iRanksVaultHandle = nvault_open(g_szRanksVault)
    442.  
    443.         // Saves His Data
    444.         nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
    445.         nvault_set(g_iRanksVaultHandle, szAuthID, szName)
    446.        
    447.         // Close Vaults
    448.         nvault_close(g_iLevelsVaultHandle)
    449.         nvault_close(g_iRanksVaultHandle)
    450.     }
    451.     else
    452.     {
    453.         new szQuery[128]
    454.         formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Level` = '%d', `XP` = '%d', `Max_XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], g_iMaxXP[id], szAuthID)
    455.         SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
    456.     }
    457. }
    458.  
    459. public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    460. {
    461.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    462. }
    463.  
    464. public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    465. {
    466.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    467. }
    468.  
    469. public LoadData(id)
    470. {
    471.     new szData[256], szAuthID[35]
    472.    
    473.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    474.    
    475.     if (!get_pcvar_num(g_pCvarSaveType))
    476.     {
    477.         // Useless Variable
    478.         new iTimestamp, iExists
    479.        
    480.         // Open the Vault
    481.         g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
    482.        
    483.         iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
    484.        
    485.         // Close Vault
    486.         nvault_close(g_iLevelsVaultHandle)
    487.        
    488.         if (!iExists)
    489.         {
    490.             g_iLevel[id] = 0
    491.             g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
    492.             g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    493.             SaveData(id)
    494.         }
    495.         else
    496.         {
    497.             new iLevel[32], iXP[32], iMaxLevel[32]
    498.             parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
    499.            
    500.             g_iLevel[id] = str_to_num(iLevel)
    501.             g_iXP[id] = str_to_num(iXP)
    502.             g_iMaxXP[id] = str_to_num(iMaxLevel)
    503.         }
    504.     }
    505.     else
    506.     {
    507.         new szQuery[128], szData[5]
    508.         formatex(szQuery, charsmax(szQuery), "SELECT * FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
    509.      
    510.         num_to_str(id, szData, charsmax(szData))
    511.         SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    512.     }
    513. }
    514.  
    515. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
    516. {
    517.     if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
    518.         return
    519.    
    520.     new id = str_to_num(szData)
    521.    
    522.     // No results for this query means this is new player
    523.     if (!SQL_NumResults(hQuery))
    524.     {
    525.         new szSteamId[36], szQuery[128]
    526.         get_user_authid(id, szSteamId, charsmax(szSteamId))
    527.  
    528.         g_iLevel[id] = 0
    529.         g_iXP[id] = 0
    530.         g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    531.         return
    532.     }
    533.  
    534.     g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
    535.     g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
    536.     g_iMaxXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Max_XP"))
    537. }
    538.  
    539. public native_ze_get_user_xp(id)
    540. {
    541.     if(!is_user_connected(id))
    542.     {
    543.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    544.         return false;
    545.     }
    546.    
    547.     return g_iXP[id]
    548. }
    549.  
    550. public native_ze_set_user_xp(id, amount)
    551. {
    552.     if(!is_user_connected(id))
    553.     {
    554.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    555.         return false;
    556.     }
    557.    
    558.     g_iXP[id] = amount
    559.    
    560.     Check_User_Level(id)
    561.     return true;
    562. }
    563.  
    564. public native_ze_get_user_level(id)
    565. {
    566.     if(!is_user_connected(id))
    567.     {
    568.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    569.         return false;
    570.     }
    571.    
    572.     return g_iLevel[id]
    573. }
    574.  
    575. public native_ze_set_user_level(id, amount)
    576. {
    577.     if(!is_user_connected(id))
    578.     {
    579.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    580.         return false;
    581.     }
    582.    
    583.     g_iLevel[id] = amount
    584.    
    585.     if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    586.     {
    587.         g_iXP[id] = 0
    588.     }
    589.    
    590.     return true;
    591. }
    592.  
    593. public native_ze_get_user_max_xp(id)
    594. {
    595.     if(!is_user_connected(id))
    596.     {
    597.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    598.         return false;
    599.     }
    600.    
    601.     return g_iMaxXP[id]
    602. }
    603.  
    604. public native_ze_set_user_max_xp(id, amount)
    605. {
    606.     if(!is_user_connected(id))
    607.     {
    608.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    609.         return false;
    610.     }
    611.    
    612.     g_iMaxXP[id] = amount
    613.     return true;
    614. }

Re: Levels-XP System

Posted: 18 Apr 2021, 19:26
by BandiT
i try this plugin and again i have this error,,,,

======= Backtrace: =========
/usr/lib/libc.so.6(+0x7968d)[0xf761d68d]
/usr/lib/libc.so.6(fclose+0x164)[0xf760a764]
/usr/lib/libnss_files.so.2(_nss_files_gethostbyname4_r+0x2a2)[0xf0995262]
/usr/lib/libc.so.6(+0xe1c92)[0xf7685c92]
/usr/lib/libc.so.6(getaddrinfo+0x12d)[0xf768720d]
cstrike/addons/amxmodx/modules/mysql_amxx_i386.so(mysql_real_connect+0xc80)[0xf1d28f90]
cstrike/addons/amxmodx/modules/mysql_amxx_i386.so(+0x246fc)[0xf1d236fc]
[0x9ab9380]
======= Memory map: ========
08048000-08049000 r--p 00000000 103:02 12059195 /opt/hlds_real3/hlds_linux
08049000-08051000 r-xp 00001000 103:02 12059195 /opt/hlds_real3/hlds_linux
08051000-08056000 r--p 00009000 103:02 12059195 /opt/hlds_real3/hlds_linux
08056000-08057000 r--p 0000d000 103:02 12059195 /opt/hlds_real3/hlds_linux
08057000-08058000 rw-p 0000e000 103:02 12059195 /opt/hlds_real3/hlds_linux
08058000-0805a000 rw-p 00000000 00:00 0
085c6000-09c5d000 rw-p 00000000 00:00 0 [heap]
ed300000-ed331000 rw-p 00000000 00:00 0
ed331000-ed400000 ---p 00000000 00:00 0
ed4fc000-ed4fd000 ---p 00000000 00:00 0
ed4fd000-edcfd000 rwxp 00000000 00:00 0
edcfd000-edcfe000 ---p 00000000 00:00 0
edcfe000-eddfe000 rwxp 00000000 00:00 0
eddfe000-eddff000 ---p 00000000 00:00 0
eddff000-edeff000 rwxp 00000000 00:00 0
edeff000-edf00000 ---p 00000000 00:00 0
edf00000-ee000000 rwxp 00000000 00:00 0
ee000000-ee021000 rw-p 00000000 00:00 0
ee021000-ee100000 ---p 00000000 00:00 0
ee1ff000-ee200000 ---p 00000000 00:00 0
ee200000-ee300000 rwxp 00000000 00:00 0
ee300000-ee321000 rw-p 00000000 00:00 0
ee321000-ee400000 ---p 00000000 00:00 0
ee4fb000-ee4fc000 ---p 00000000 00:00 0
ee4fc000-ee5fc000 rwxp 00000000 00:00 0
ee600000-ee6be000 rw-p 00000000 00:00 0
ee6be000-ee700000 ---p 00000000 00:00 0
ee700000-ee721000 rw-p 00000000 00:00 0
ee721000-ee800000 ---p 00000000 00:00 0
ee800000-ee821000 rw-p 00000000 00:00 0
ee821000-ee900000 ---p 00000000 00:00 0
eea00000-eeae2000 rw-p 00000000 00:00 0
eeae2000-eeb00000 ---p 00000000 00:00 0
eebff000-eec00000 ---p 00000000 00:00 0
eec00000-eed00000 rwxp 00000000 00:00 0
eed00000-eed79000 rw-p 00000000 00:00 0
eed79000-eee00000 ---p 00000000 00:00 0
eeefe000-eeeff000 ---p 00000000 00:00 0
eeeff000-eefff000 rwxp 00000000 00:00 0
eefff000-ef000000 ---p 00000000 00:00 0
ef000000-ef100000 rwxp 00000000 00:00 0
ef100000-ef122000 rw-p 00000000 00:00 0
ef122000-ef200000 ---p 00000000 00:00 0
ef296000-ef3f1000 r-xp 00000000 103:02 12059190 /opt/hlds_real3/libSDL2-2.0.so.0.10.0
ef3f1000-ef3f2000 ---p 0015b000 103:02 12059190 /opt/hlds_real3/libSDL2-2.0.so.0.10.0
ef3f2000-ef3f5000 r--p 0015b000 103:02 12059190 /opt/hlds_real3/libSDL2-2.0.so.0.10.0
ef3f5000-ef3f9000 rw-p 0015e000 103:02 12059190 /opt/hlds_real3/libSDL2-2.0.so.0.10.0
ef3f9000-ef3fe000 rw-p 00000000 00:00 0
ef3fe000-ef3ff000 ---p 00000000 00:00 0
ef3ff000-ef4ff000 rwxp 00000000 00:00 0
ef4ff000-ef500000 ---p 00000000 00:00 0
ef500000-ef600000 rwxp 00000000 00:00 0
ef600000-ef621000 rw-p 00000000 00:00 0
ef621000-ef700000 ---p 00000000 00:00 0
ef7fe000-ef7ff000 ---p 00000000 00:00 0
ef7ff000-ef8ff000 rwxp 00000000 00:00 0
ef8ff000-ef900000 ---p 00000000 00:00 0
ef900000-efa00000 rwxp 00000000 00:00 0
efa00000-efa21000 rw-p 00000000 00:00 0
efa21000-efb00000 ---p 00000000 00:00 0
efbff000-efc00000 ---p 00000000 00:00 0
efc00000-efd00000 rwxp 00000000 00:00 0
efd00000-efdda000 rw-p 00000000 00:00 0
efdda000-efe00000 ---p 00000000 00:00 0
efe03000-efe04000 ---p 00000000 00:00 0
efe04000-eff04000 rwxp 00000000 00:00 0
f0000000-f00b7000 rw-p 00000000 00:00 0
f00b7000-f0100000 ---p 00000000 00:00 0
f0101000-f0104000 rw-p 00000000 00:00 0
f0104000-f0105000 ---p 00000000 00:00 0
f0105000-f0971000 rwxp 00000000 00:00 0
f0971000-f0986000 r-xp 00000000 103:02 267744 /usr/lib/libresolv-2.17.so
f0986000-f0987000 r--p 00014000 103:02 267744 /usr/lib/libresolv-2.17.so
f0987000-f0988000 rw-p 00015000 103:02 267744 /usr/lib/libresolv-2.17.so
f0988000-f098a000 rw-p 00000000 00:00 0
f098a000-f098f000 r-xp 00000000 103:02 267732 /usr/lib/libnss_dns-2.17.so
f098f000-f0990000 r--p 00004000 103:02 267732 /usr/lib/libnss_dns-2.17.so
f0990000-f0991000 rw-p 00005000 103:02 267732 /usr/lib/libnss_dns-2.17.so
f0991000-f099c000 r-xp 00000000 103:02 267734 /usr/lib/libnss_files-2.17.so
f099c000-f099d000 r--p 0000a000 103:02 267734 /usr/lib/libnss_files-2.17.so
f099d000-f099e000 rw-p 0000b000 103:02 267734 /usr/lib/libnss_files-2.17.so
f099e000-f09a4000 rw-p 00000000 00:00 0
f09a4000-f09ce000 rwxp 00000000 00:00 0
f09ce000-f09cf000 ---p 00000000 00:00 0
f09cf000-f17ea000 rwxp 00000000 00:00 0
f17ea000-f184d000 rwxp 00000000 00:00 0
f184d000-f1b98000 r--s 00000000 103:02 17173010 /home/vuser101/cstrike/addons/amxmodx/data/GeoLite2-Country.mmdb
f1b98000-f1b9f000 rwxp 00000000 00:00 0
f1b9f000-f1ba9000 r-xp 00000000 103:02 17172717 /home/vuser101/cstrike/addons/amxmodx/modules/geoip_amxx_i386.so
f1ba9000-f1baa000 rw-p 0000a000 103:02 17172717 /home/vuser101/cstrike/addons/amxmodx/modules/geoip_amxx_i386.so
f1baa000-f1bb4000 rwxp 00000000 00:00 0
f1bb4000-f1bc8000 r-xp 00000000 103:02 17172715 /home/vuser101/cstrike/addons/amxmodx/modules/engine_amxx_i386.so
f1bc8000-f1bc9000 rw-p 00013000 103:02 17172715 /home/vuser101/cstrike/addons/amxmodx/modules/engine_amxx_i386.so
f1bc9000-f1bca000 rw-p 00000000 00:00 0
f1bca000-f1be8000 rwxp 00000000 00:00 0
f1be8000-f1bf0000 r-xp 00000000 103:02 17172710 /home/vuser101/cstrike/addons/amxmodx/modules/fun_amxx_i386.so
f1bf0000-f1bf1000 rw-p 00007000 103:02 17172710 /home/vuser101/cstrike/addons/amxmodx/modules/fun_amxx_i386.so
f1bf1000-f1bf2000 rw-p 00000000 00:00 0
f1bf2000-f1bfb000 rwxp 00000000 00:00 0
f1bfb000-f1c14000 r-xp 00000000 103:02 17172706 /home/vuser101/cstrike/addons/amxmodx/modules/cstrike_amxx_i386.so
f1c14000-f1c15000 rw-p 00019000 103:02 17172706 /home/vuser101/cstrike/addons/amxmodx/modules/cstrike_amxx_i386.so
f1c15000-f1c16000 rw-p 00000000 00:00 0
f1c16000-f1c19000 rwxp 00000000 00:00 0
f1c19000-f1cf9000 rw-p 00000000 00:00 0
f1cf9000-f1cff000 rwxp 00000000 00:00 0
f1cff000-f1fbc000 r-xp 00000000 103:02 17172714 /home/vuser101/cstrike/addons/amxmodx/modules/mysql_amxx_i386.so
f1fbc000-f2034000 rw-p 002bd000 103:02 17172714 /home/vuser101/cstrike/addons/amxmodx/modules/mysql_amxx_i386.so
f2034000-f203c000 rw-p 00000000 00:00 0
f203c000-f203d000 rwxp 00000000 00:00 0
f203d000-f2040000 r-xp 00000000 103:02 17172720 /home/vuser101/cstrike/addons/amxmodx/modules/sockets_amxx_i386.so
f2040000-f2041000 rw-p 00002000 103:02 17172720 /home/vuser101/cstrike/addons/amxmodx/modules/sockets_amxx_i386.so
f2041000-f2047000 r-xp 00000000 103:02 17172707 /home/vuser101/cstrike/addons/amxmodx/modules/nvault_amxx_i386.so
f2047000-f2048000 rw-p 00006000 103:02 17172707 /home/vuser101/cstrike/addons/amxmodx/modules/nvault_amxx_i386.so
f2048000-f20b3000 r-xp 00000000 103:02 17172719 /home/vuser101/cstrike/addons/amxmodx/modules/regex_amxx_i386.so
f20b3000-f20b4000 rw-p 0006a000 103:02 17172719 /home/vuser101/cstrike/addons/amxmodx/modules/regex_amxx_i386.so
f20b4000-f20b8000 rw-p 00000000 00:00 0
f20b8000-f20c1000 rwxp 00000000 00:00 0
f20c1000-f2108000 r-xp 00000000 103:02 17172713 /home/vuser101/cstrike/addons/amxmodx/modules/fakemeta_amxx_i386.so
f2108000-f2109000 rw-p 00046000 103:02 17172713 /home/vuser101/cstrike/addons/amxmodx/modules/fakemeta_amxx_i386.so
f2109000-f210c000 rw-p 00000000 00:00 0
f210c000-f2112000 rwxp 00000000 00:00 0
f2112000-f2117000 rwxp 00000000 00:00 0
f2117000-f2122000 r-xp 00000000 103:02 17172708 /home/vuser101/cstrike/addons/amxmodx/modules/csx_amxx_i386.so
f2122000-f2123000 rw-p 0000b000 103:02 17172708 /home/vuser101/cstrike/addons/amxmodx/modules/csx_amxx_i386.so
f2123000-f218b000 rw-p 00000000 00:00 0
f218b000-f2193000 rwxp 00000000 00:00 0
f2193000-f21e9000 r-xp 00000000 103:02 17172716 /home/vuser101/cstrike/addons/amxmodx/modules/hamsandwich_amxx_i386.so
f21e9000-f21ed000 rw-p 00055000 103:02 17172716 /home/vuser101/cstrike/addons/amxmodx/modules/hamsandwich_amxx_i386.so
f21ed000-f21ef000 rw-p 00000000 00:00 0
f21ef000-f2212000 rwxp 00000000 00:00 0
f2212000-f2228000 r-xp 00000000 103:02 22679403 /home/vuser101/cstrike/addons/reauthcheck/reauthcheck_mm_i386.so
f2228000-f2229000 rw-p 00016000 103:02 22679403 /home/vuser101/cstrike/addons/reauthcheck/reauthcheck_mm_i386.so
f2229000-f223b000 rw-p 00000000 00:00 0
f223b000-f2272000 r-xp 00000000 103:02 22679120 /home/vuser101/cstrike/addons/reunion/reunion_mm_i386.so
f2272000-f2273000 r--p 00036000 103:02 22679120 /home/vuser101/cstrike/addons/reunion/reunion_mm_i386.so
f2273000-f2275000 rw-p 00037000 103:02 22679120 /home/vuser101/cstrike/addons/reunion/reunion_mm_i386.so
f2275000-f2276000 rw-p 00000000 00:00 0
f2276000-f2308000 r-xp 00000000 103:02 17172688 /home/vuser101/cstrike/addons/unprecacher/unprecacher_i386.so
f2308000-f2309000 ---p 00092000 103:02 17172688 /home/vuser101/cstrike/addons/unprecacher/unprecacher_i386.so
f2309000-f230c000 r--p 00092000 103:02 17172688 /home/vuser101/cstrike/addons/unprecacher/unprecacher_i386.so
f230c000-f230d000 rw-p 00095000 103:02 17172688 /home/vuser101/cstrike/addons/unprecacher/unprecacher_i386.so
f230d000-f230e000 rw-p 00000000 00:00 0
f230e000-f2311000 rwxp 00000000 00:00 0
f2311000-f2377000 r-xp 00000000 103:02 17172705 /home/vuser101/cstrike/addons/amxmodx/modules/reapi_amxx_i386.so
f2377000-f2378000 ---p 00066000 103:02 17172705 /home/vuser101/cstrike/addons/amxmodx/modules/reapi_amxx_i386.so
f2378000-f2379000 r--p 00066000 103:02 17172705 /home/vuser101/cstrike/addons/amxmodx/modules/reapi_amxx_i386.so
f2379000-f237e000 rw-p 00067000 103:02 17172705 /home/vuser101/cstrike/addons/amxmodx/modules/reapi_amxx_i386.so
f237e000-f2387000 rw-p 00000000 00:00 0
f2387000-f23f3000 r-xp 00000000 103:02 17172698 /home/vuser101/cstrike/addons/amxmodx/dlls/amxmodx_mm_i386.so
f23f3000-f2403000 rwxp 0006c000 103:02 17172698 /home/vuser101/cstrike/addons/amxmodx/dlls/amxmodx_mm_i386.so
f2403000-f2537000 r-xp 0007c000 103:02 17172698 /home/vuser101/cstrike/addons/amxmodx/dlls/amxmodx_mm_i386.so
f2537000-f253a000 rw-p 001af000 103:02 17172698 /home/vuser101/cstrike/addons/amxmodx/dlls/amxmodx_mm_i386.so
f253a000-f2573000 rw-p 00000000 00:00 0
f2573000-f2576000 rwxp 00000000 00:00 0
f2576000-f2829000 r-xp 00000000 103:02 17052731 /home/vuser101/cstrike/dlls/cs.so
f2829000-f282a000 r--p 002b2000 103:02 17052731 /home/vuser101/cstrike/dlls/cs.so
f282a000-f2849000 rw-p 002b3000 103:02 17052731 /home/vuser101/cstrike/dlls/cs.so
f2849000-f289d000 rw-p 00000000 00:00 0
f289d000-f2901000 r-xp 00000000 103:02 17172671 /home/vuser101/cstrike/addons/metamod/dlls/metamod_i386.so
f2901000-f2902000 r--p 00063000 103:02 17172671 /home/vuser101/cstrike/addons/metamod/dlls/metamod_i386.so
f2902000-f2905000 rw-p 00064000 103:02 17172671 /home/vuser101/cstrike/addons/metamod/dlls/metamod_i386.so
f2905000-f2908000 rw-p 00000000 00:00 0
f2908000-f2919000 rwxp 00000000 00:00 0
f2919000-f511a000 rw-p 00000000 00:00 0
f511a000-f51b7000 r-xp 00000000 103:02 12059188 /opt/hlds_real3/crashhandler.so
f51b7000-f51b9000 rw-p 0009c000 103:02 12059188 /opt/hlds_real3/crashhandler.so
f51b9000-f51c1000 rw-p 00000000 00:00 0
f51c1000-f6c0b000 r-xp 00000000 103:02 12059191 /opt/hlds_real3/steamclient.so
f6c0b000-f6ca0000 r--p 01a49000 103:02 12059191 /opt/hlds_real3/steamclient.so
f6ca0000-f6cae000 rw-p 01ade000 103:02 12059191 /opt/hlds_real3/steamclient.so
f6cae000-f6d11000 rw-p 00000000 00:00 0
f6d11000-f6d17000 r--p 00000000 103:02 12059200 /opt/hlds_real3/filesystem_stdio.so
f6d17000-f6d25000 r-xp 00006000 103:02 12059200 /opt/hlds_real3/filesystem_stdio.so
f6d25000-f6d2b000 r--p 00014000 103:02 12059200 /opt/hlds_real3/filesystem_stdio.so
f6d2b000-f6d2c000 ---p 0001a000 103:02 12059200 /opt/hlds_real3/filesystem_stdio.so
f6d2c000-f6d2d000 r--p 0001a000 103:02 12059200 /opt/hlds_real3/filesystem_stdio.so
f6d2d000-f6d2e000 rw-p 0001b000 103:02 12059200 /opt/hlds_real3/filesystem_stdio.so
f6d2e000-f6d31000 rw-p 00000000 00:00 0
f6d31000-f6d38000 r-xp 00000000 103:02 267746 /usr/lib/librt-2.17.so
f6d38000-f6d39000 r--p 00006000 103:02 267746 /usr/lib/librt-2.17.so
f6d39000-f6d3a000 rw-p 00007000 103:02 267746 /usr/lib/librt-2.17.so
f6d3a000-f6d51000 r-xp 00000000 103:02 267742 /usr/lib/libpthread-2.17.so
f6d51000-f6d52000 r--p 00016000 103:02 267742 /usr/lib/libpthread-2.17.so
f6d52000-f6d53000 rw-p 00017000 103:02 267742 /usr/lib/libpthread-2.17.so
f6d53000-f6d55000 rw-p 00000000 00:00 0
f6d55000-f6d66000 r-xp 00000000 103:02 12059196 /opt/hlds_real3/libsteam_api.so
f6d66000-f6d67000 rw-p 00010000 103:02 12059196 /opt/hlds_real3/libsteam_api.so
f6d67000-f6d68000 rw-p 00000000 00:00 0
f6d68000-f6da8000 r--p 00000000 103:02 12059659 /opt/hlds_real3/engine_i486.so
f6da8000-f6e5c000 r-xp 00040000 103:02 12059659 /opt/hlds_real3/engine_i486.so
f6e5c000-f6eb1000 r--p 000f4000 103:02 12059659 /opt/hlds_real3/engine_i486.so
f6eb1000-f6eb4000 r--p 00148000 103:02 12059659 /opt/hlds_real3/engine_i486.so
f6eb4000-f6eb9000 rw-p 0014b000 103:02 12059659 /opt/hlds_real3/engine_i486.so
f6eb9000-f7474000 rw-p 00000000 00:00 0
f7474000-f7488000 r-xp 00000000 103:02 12059197 /opt/hlds_real3/libgcc_s.so.1
f7488000-f7489000 rw-p 00013000 103:02 12059197 /opt/hlds_real3/libgcc_s.so.1
f7489000-f74c9000 r-xp 00000000 103:02 267724 /usr/lib/libm-2.17.so
f74c9000-f74ca000 r--p 0003f000 103:02 267724 /usr/lib/libm-2.17.so
f74ca000-f74cb000 rw-p 00040000 103:02 267724 /usr/lib/libm-2.17.so
f74cb000-f74cc000 rw-p 00000000 00:00 0
f74cc000-f7593000 r-xp 00000000 103:02 12059204 /opt/hlds_real3/libstdc++.so.6
f7593000-f7597000 r--p 000c6000 103:02 12059204 /opt/hlds_real3/libstdc++.so.6
f7597000-f7599000 rw-p 000ca000 103:02 12059204 /opt/hlds_real3/libstdc++.so.6
f7599000-f759f000 rw-p 00000000 00:00 0
f759f000-f75a2000 r-xp 00000000 103:02 267722 /usr/lib/libdl-2.17.so
f75a2000-f75a3000 r--p 00002000 103:02 267722 /usr/lib/libdl-2.17.so
f75a3000-f75a4000 rw-p 00003000 103:02 267722 /usr/lib/libdl-2.17.so
f75a4000-f7768000 r-xp 00000000 103:02 267716 /usr/lib/libc-2.17.so
f7768000-f7769000 ---p 001c4000 103:02 267716 /usr/lib/libc-2.17.so
f7769000-f776b000 r--p 001c4000 103:02 267716 /usr/lib/libc-2.17.so
f776b000-f776c000 rw-p 001c6000 103:02 267716 /usr/lib/libc-2.17.so
f776c000-f7770000 rw-p 00000000 00:00 0
f7770000-f7771000 r-xp 00000000 00:00 0 [vdso]
f7771000-f7793000 r-xp 00000000 103:02 262777 /usr/lib/ld-2.17.so
f7793000-f7794000 r--p 00021000 103:02 262777 /usr/lib/ld-2.17.so
f7794000-f7795000 rw-p 00022000 103:02 262777 /usr/lib/ld-2.17.so
ff94d000-ff9a4000 rwxp 00000000 00:00 0 [stack]
ff9a4000-ff9a6000 rw-p 00000000 00:00 0
./hlds_r_101: line 53: 19494 Aborted ${HL} "$@"

Re: Levels-XP System

Posted: 19 Apr 2021, 00:36
by Night Fury
What the heck is even that?

Re: Levels-XP System

Posted: 21 Apr 2021, 16:55
by BandiT
I THINK is from my hoost provider, any saving in any data baze from level system plugin is crashing sv and showing me that error, idk wht but i think is form my hoost provider, because i try other plugin level an it-s happening same thing

Re: Levels-XP System

Posted: 22 Apr 2021, 01:54
by Raheem
[mention]BandiT[/mention], my suggestion is to use VPS or dedicates server to host your servers instead of using game server. The following videos can be the start: https://www.youtube.com/playlist?list=P ... x-qDEC6F86 (https://zppv.boards.net/thread/1697/tut ... cs1-6-host). If you are not familiar with VPS/Dedicated or how to deal with them, then try find better game server hosting.

Re: Levels-XP System

Posted: 28 Jun 2021, 12:14
by VicKy
Please Help Me I dont getting any xp for escape succes
Cvars

//Level
ze_maxlevels_increment 1.1
ze_enable_percentage_style 0
ze_max_xp_first_level 300
ze_zombie_infect 20
ze_escape_success 200.0
ze_enable_dmg 1
ze_required_dmg 5000.0
ze_dmg_award 0
ze_start_xp 50
ze_new_level_zero_xp 0
ze_add_commas_to_xp 1
ze_level_up_effects 1

Re: Levels-XP System

Posted: 28 Jun 2021, 14:29
by karan
VicKy wrote: 2 years ago Please Help Me I dont getting any xp for escape succes
Cvars

//Level
ze_maxlevels_increment 1.1
ze_enable_percentage_style 0
ze_max_xp_first_level 300
ze_zombie_infect 20
ze_escape_success 200.0
ze_enable_dmg 1
ze_required_dmg 5000.0
ze_dmg_award 0
ze_start_xp 50
ze_new_level_zero_xp 0
ze_add_commas_to_xp 1
ze_level_up_effects 1
change this value ze_escape_success 200.0 to 200

Re: Levels-XP System

Posted: 28 Jun 2021, 15:05
by VicKy
I did but no work

Re: Levels-XP System

Posted: 28 Jun 2021, 16:11
by VicKy
i remove on zombieescape.cfg this is plugin
error is dont getting xp escape
  1. #include <zombie_escape>
  2.  
  3. // Defines
  4. #define MAX_LEVEL 101
  5. #define MAX_XP 500000
  6. #define TASK_SHOWHUD 2020
  7. #define ID_SHOWHUD (taskid - TASK_SHOWHUD)
  8. #define LEVELUP "levelup_ZE/ze_levelup.wav"
  9.  
  10. enum
  11. {
  12.     Host = 0,
  13.     User,
  14.     Pass,
  15.     DB
  16. }
  17.  
  18. // Constants
  19. new const g_szLevelsVault[] = "Levels"
  20. new const g_szRanksVault[] = "Ranks"
  21. new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
  22. new const g_szTable[] =
  23. " \
  24.     ALTER TABLE `test` \
  25.     ADD IF NOT EXISTS `Level` int(20) NOT NULL DEFAULT '0', \
  26.     ADD IF NOT EXISTS `XP` int(20) NOT NULL DEFAULT '0', \
  27.     ADD IF NOT EXISTS `Max_XP` int(20) NOT NULL DEFAULT '0'; \
  28. "
  29.  
  30. // Messages
  31. const Float:HUD_SPECT_X = -1.0
  32. const Float:HUD_SPECT_Y = 0.70
  33. const Float:HUD_STATS_X = -1.0
  34. const Float:HUD_STATS_Y = 0.90
  35.  
  36. const HUD_STATS_ZOMBIE_R = 200
  37. const HUD_STATS_ZOMBIE_G = 220
  38. const HUD_STATS_ZOMBIE_B = 0
  39.  
  40. const HUD_STATS_HUMAN_R = 0
  41. const HUD_STATS_HUMAN_G = 200
  42. const HUD_STATS_HUMAN_B = 210
  43.  
  44. const HUD_STATS_SPEC_R = 100
  45. const HUD_STATS_SPEC_G = 100
  46. const HUD_STATS_SPEC_B = 100
  47.  
  48. // Variables
  49. new g_iLevel[33],
  50.     g_iXP[33],
  51.     g_iMaxXP[33],
  52.     Float:g_fDamage[33],
  53.     g_MsgSync,
  54.     g_iLevelsVaultHandle,
  55.     g_iRanksVaultHandle,
  56.     Handle:g_hTuple,
  57.     Fw_LevelUP,
  58.     ForwardReturn
  59.  
  60. // Cvars
  61. new g_pCvarZombieInfect,
  62.     g_pCvarEscapeSuccess,
  63.     g_pCvarEnableDamage,
  64.     g_pCvarRequiredDamage,
  65.     g_pCvarDamageAward,
  66.     g_pCvarStartXP,
  67.     g_pCvarMaxLevelsIncrement,
  68.     g_pCvarMaxXPFirstLevel,
  69.     g_pCvarPercentageStyle,
  70.     g_pCvarStartFromZero,
  71.     g_pCvarAddCommas,
  72.     g_pCvarLevelEffects,
  73.     g_pCvarSaveType,
  74.     g_pCvarDBInfo[4]
  75.  
  76. public plugin_natives()
  77. {
  78.     register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
  79.     register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
  80.     register_native("ze_get_user_level", "native_ze_get_user_level", 1)
  81.     register_native("ze_set_user_level", "native_ze_set_user_level", 1)
  82.     register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
  83.     register_native("ze_set_user_max_xp", "native_ze_set_user_max_xp", 1)
  84. }
  85.  
  86. public plugin_precache()
  87. {
  88.     precache_sound(LEVELUP)
  89. }
  90.  
  91. public plugin_init()
  92. {
  93.     register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
  94.    
  95.     // Hook Chains
  96.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
  97.  
  98.     Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
  99.    
  100.     // Cvars
  101.     g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "30")
  102.     g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "150")
  103.     g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "0")
  104.     g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
  105.     g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
  106.     g_pCvarStartXP = register_cvar("ze_start_xp", "50")
  107.     g_pCvarMaxLevelsIncrement = register_cvar("ze_maxlevels_increment", "1.1")
  108.     g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "300")
  109.     g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "0")
  110.     g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
  111.     g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
  112.     g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
  113.     g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
  114.     g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
  115.     g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
  116.     g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
  117.     g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
  118.    
  119.     // Messages
  120.     g_MsgSync = CreateHudSyncObj()
  121.  
  122.     if (get_pcvar_num(g_pCvarSaveType))
  123.     {
  124.         set_task(0.1, "Delay_MySQL_Init")
  125.     }
  126. }
  127.  
  128. public plugin_end()
  129. {
  130.     if (get_pcvar_num(g_pCvarSaveType))
  131.     {
  132.         if (g_hTuple != Empty_Handle)
  133.         {
  134.             SQL_FreeHandle(g_hTuple)
  135.         }
  136.     }
  137. }
  138.  
  139. public Delay_MySQL_Init()
  140. {
  141.     MySQL_Init()
  142. }
  143.  
  144. public MySQL_Init()
  145. {
  146.     if (!get_pcvar_num(g_pCvarSaveType))
  147.         return
  148.    
  149.     new szHost[64], szUser[32], szPass[32], szDB[128]
  150.    
  151.     get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
  152.     get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
  153.     get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
  154.     get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
  155.    
  156.     g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
  157.    
  158.     // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
  159.     new iErrorCode, szError[512], Handle:hSQLConnection
  160.    
  161.     hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
  162.    
  163.     if (hSQLConnection != Empty_Handle)
  164.     {
  165.         log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
  166.         SQL_FreeHandle(hSQLConnection)
  167.     }
  168.     else
  169.     {
  170.         // Disable plugin
  171.         set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
  172.     }
  173.    
  174.     SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
  175. }
  176.  
  177. public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  178. {
  179.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  180. }
  181.  
  182. public client_putinserver(id)
  183. {
  184.     if(is_user_hltv(id) || is_user_bot(id))
  185.         return
  186.    
  187.     // Just 1 second delay
  188.     set_task(1.0, "DelayLoad", id)
  189.  
  190.     // Other tasks
  191.     set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
  192.     set_task(0.1, "Check_MaxXP", id, _, _, "b")
  193. }
  194.  
  195. public DelayLoad(id)
  196. {
  197.     // Load his data
  198.     LoadData(id)
  199. }
  200.  
  201. public client_disconnected(id)
  202. {
  203.     if(is_user_hltv(id) || is_user_bot(id))
  204.         return
  205.        
  206.     remove_task(id+TASK_SHOWHUD)
  207.     remove_task(id)
  208. }
  209.  
  210. public Check_MaxXP(id)
  211. {
  212.     new iCurrentMaxXP = g_iMaxXP[id]
  213.    
  214.     new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
  215.    
  216.     for (new i = 1; i <= g_iLevel[id]; i++)
  217.     {
  218.         iMaxXP = floatround(float(iMaxXP) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
  219.     }
  220.    
  221.     if (iCurrentMaxXP != iMaxXP)
  222.     {
  223.         g_iMaxXP[id] = iMaxXP
  224.     }
  225. }
  226.  
  227. public Show_Hud(taskid)
  228. {  
  229.     new iPlayer = ID_SHOWHUD
  230.    
  231.     if (!is_user_alive(iPlayer))
  232.     {
  233.         iPlayer = pev(iPlayer, pev_iuser2)
  234.        
  235.         if (!is_user_alive(iPlayer))
  236.             return
  237.     }
  238.    
  239.     if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
  240.     {
  241.         if(iPlayer != ID_SHOWHUD)
  242.         {
  243.             set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  244.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
  245.         }
  246.         else if (ze_is_user_zombie(iPlayer))
  247.         {
  248.             set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  249.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
  250.         }
  251.         else
  252.         {
  253.             set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  254.             ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
  255.         }
  256.     }
  257.     else
  258.     {
  259.         if(iPlayer != ID_SHOWHUD)
  260.         {
  261.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
  262.             {
  263.                 new szSpecXP[15], szSpecMaxXP[15]
  264.                
  265.                 AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
  266.                 AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
  267.                
  268.                 set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  269.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
  270.             }
  271.             else
  272.             {
  273.                 set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  274.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
  275.             }  
  276.         }
  277.         else if (ze_is_user_zombie(iPlayer))
  278.         {
  279.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
  280.             {
  281.                 new szZombieXP[15], szZombieMaxXP[15]
  282.                
  283.                 AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
  284.                 AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
  285.                
  286.                 set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  287.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
  288.             }
  289.             else
  290.             {
  291.                 set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  292.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
  293.             }
  294.         }
  295.         else
  296.         {
  297.             if (get_pcvar_num(g_pCvarAddCommas) == 1)
  298.             {
  299.                 new szHumanXP[15], szHumanMaxXP[15]
  300.                
  301.                 AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
  302.                 AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
  303.                
  304.                 set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  305.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
  306.             }
  307.             else
  308.             {
  309.                 set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
  310.                 ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
  311.             }
  312.         }
  313.     }
  314. }
  315.  
  316. public ze_roundend(WinTeam)
  317. {
  318.     if (WinTeam == ZE_TEAM_HUMAN)
  319.     {
  320.         for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
  321.         {
  322.             if (!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
  323.                 continue
  324.            
  325.             g_iXP[id] += get_pcvar_num(g_pCvarEscapeSuccess)
  326.             SaveData(id)
  327.             Check_User_Level(id)
  328.         }
  329.     }
  330.    
  331.     remove_task(TASK_SHOWHUD)
  332. }
  333.  
  334. public Check_User_Level(id)
  335. {
  336.     if(!is_user_connected(id))
  337.         return
  338.  
  339.     if(g_iXP[id] >= g_iMaxXP[id])
  340.     {
  341.         if (get_pcvar_num(g_pCvarStartFromZero) == 1)
  342.         {
  343.             g_iXP[id] = 0
  344.         }
  345.        
  346.         new szName[32]
  347.         g_iLevel[id] ++
  348.         g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
  349.         get_user_name(id, szName, charsmax(szName))
  350.         ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
  351.         ExecuteForward(Fw_LevelUP, ForwardReturn, id)
  352.        
  353.         SaveData(id)
  354.        
  355.         PlaySound(id, LEVELUP)
  356.        
  357.         if (get_pcvar_num(g_pCvarLevelEffects) != 0)
  358.         {
  359.             // Screen Fade
  360.             message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
  361.             write_short(4096*2)
  362.             write_short(4096*5)
  363.             write_short(0x0001)
  364.             write_byte(random(256))
  365.             write_byte(random(256))
  366.             write_byte(random(256))
  367.             write_byte(150)
  368.             message_end()
  369.            
  370.             // Screen Shake
  371.             message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
  372.             write_short(255<<14)
  373.             write_short(10<<14)
  374.             write_short(255<<14)
  375.             message_end()
  376.         }
  377.     }
  378. }
  379.  
  380. public ze_user_infected(iVictim, iInfector)
  381. {
  382.     if (iInfector == 0)
  383.         return
  384.    
  385.     g_iXP[iInfector] += get_pcvar_num(g_pCvarZombieInfect)
  386.     SaveData(iInfector)
  387.     Check_User_Level(iInfector)
  388. }
  389.  
  390. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
  391. {
  392.     // Player Damage Himself
  393.     if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
  394.         return HC_CONTINUE
  395.    
  396.     // Same Team?
  397.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
  398.         return HC_CONTINUE
  399.    
  400.     // Store Damage For every Player
  401.     g_fDamage[iAttacker] += fDamage
  402.    
  403.     // Damage Calculator Equal or Higher than needed damage
  404.     if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
  405.     {
  406.         // Give Player The Coins
  407.         g_iXP[iAttacker] += get_pcvar_num(g_pCvarDamageAward)
  408.         SaveData(iAttacker)
  409.         Check_User_Level(iAttacker)
  410.        
  411.         // Rest The Damage Calculator
  412.         g_fDamage[iAttacker] = 0.0
  413.     }
  414.     return HC_CONTINUE
  415. }
  416.  
  417. public SaveData(id)
  418. {
  419.     new szAuthID[35], szName[32]
  420.     get_user_authid(id, szAuthID, charsmax(szAuthID))
  421.     get_user_name(id, szName, charsmax(szName))
  422.    
  423.     // Set Him to max if he Higher than Max Value
  424.     if (g_iLevel[id] > MAX_LEVEL)
  425.     {
  426.         g_iLevel[id] = MAX_LEVEL
  427.     }
  428.    
  429.     if (g_iXP[id] > MAX_XP)
  430.     {
  431.         g_iXP[id] = MAX_XP
  432.     }
  433.  
  434.     if (!get_pcvar_num(g_pCvarSaveType))
  435.     {
  436.         new szData[256]
  437.         formatex(szData , charsmax(szData), "%i %i %i", g_iLevel[id], g_iXP[id], g_iMaxXP[id])
  438.        
  439.         // Open the Vaults
  440.         g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
  441.         g_iRanksVaultHandle = nvault_open(g_szRanksVault)
  442.  
  443.         // Saves His Data
  444.         nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
  445.         nvault_set(g_iRanksVaultHandle, szAuthID, szName)
  446.        
  447.         // Close Vaults
  448.         nvault_close(g_iLevelsVaultHandle)
  449.         nvault_close(g_iRanksVaultHandle)
  450.     }
  451.     else
  452.     {
  453.         new szQuery[128]
  454.         formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Level` = '%d', `XP` = '%d', `Max_XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], g_iMaxXP[id], szAuthID)
  455.         SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
  456.     }
  457. }
  458.  
  459. public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  460. {
  461.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  462. }
  463.  
  464. public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  465. {
  466.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  467. }
  468.  
  469. public LoadData(id)
  470. {
  471.     new szData[256], szAuthID[35]
  472.    
  473.     get_user_authid(id, szAuthID, charsmax(szAuthID))
  474.    
  475.     if (!get_pcvar_num(g_pCvarSaveType))
  476.     {
  477.         // Useless Variable
  478.         new iTimestamp, iExists
  479.        
  480.         // Open the Vault
  481.         g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
  482.        
  483.         iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
  484.        
  485.         // Close Vault
  486.         nvault_close(g_iLevelsVaultHandle)
  487.        
  488.         if (!iExists)
  489.         {
  490.             g_iLevel[id] = 0
  491.             g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
  492.             g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
  493.             SaveData(id)
  494.         }
  495.         else
  496.         {
  497.             new iLevel[32], iXP[32], iMaxLevel[32]
  498.             parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
  499.            
  500.             g_iLevel[id] = str_to_num(iLevel)
  501.             g_iXP[id] = str_to_num(iXP)
  502.             g_iMaxXP[id] = str_to_num(iMaxLevel)
  503.         }
  504.     }
  505.     else
  506.     {
  507.         new szQuery[128], szData[5]
  508.         formatex(szQuery, charsmax(szQuery), "SELECT * FROM `Players_Information` WHERE ( `SteamID` = '%s' );", szAuthID)
  509.      
  510.         num_to_str(id, szData, charsmax(szData))
  511.         SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
  512.     }
  513. }
  514.  
  515. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
  516. {
  517.     if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
  518.         return
  519.    
  520.     new id = str_to_num(szData)
  521.    
  522.     // No results for this query means this is new player
  523.     if (!SQL_NumResults(hQuery))
  524.     {
  525.         new szSteamId[36], szQuery[128]
  526.         get_user_authid(id, szSteamId, charsmax(szSteamId))
  527.  
  528.         g_iLevel[id] = 0
  529.         g_iXP[id] = 0
  530.         g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
  531.         return
  532.     }
  533.  
  534.     g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
  535.     g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
  536.     g_iMaxXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Max_XP"))
  537. }
  538.  
  539. public native_ze_get_user_xp(id)
  540. {
  541.     if(!is_user_connected(id))
  542.     {
  543.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  544.         return false;
  545.     }
  546.    
  547.     return g_iXP[id]
  548. }
  549.  
  550. public native_ze_set_user_xp(id, amount)
  551. {
  552.     if(!is_user_connected(id))
  553.     {
  554.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  555.         return false;
  556.     }
  557.    
  558.     g_iXP[id] = amount
  559.    
  560.     Check_User_Level(id)
  561.     return true;
  562. }
  563.  
  564. public native_ze_get_user_level(id)
  565. {
  566.     if(!is_user_connected(id))
  567.     {
  568.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  569.         return false;
  570.     }
  571.    
  572.     return g_iLevel[id]
  573. }
  574.  
  575. public native_ze_set_user_level(id, amount)
  576. {
  577.     if(!is_user_connected(id))
  578.     {
  579.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  580.         return false;
  581.     }
  582.    
  583.     g_iLevel[id] = amount
  584.    
  585.     if (get_pcvar_num(g_pCvarStartFromZero) == 1)
  586.     {
  587.         g_iXP[id] = 0
  588.     }
  589.    
  590.     return true;
  591. }
  592.  
  593. public native_ze_get_user_max_xp(id)
  594. {
  595.     if(!is_user_connected(id))
  596.     {
  597.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  598.         return false;
  599.     }
  600.    
  601.     return g_iMaxXP[id]
  602. }
  603.  
  604. public native_ze_set_user_max_xp(id, amount)
  605. {
  606.     if(!is_user_connected(id))
  607.     {
  608.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  609.         return false;
  610.     }
  611.    
  612.     g_iMaxXP[id] = amount
  613.     return true;
  614. }

Re: Levels-XP System

Posted: 11 Aug 2021, 03:52
by nominal07
Test

Re: Levels-XP System

Posted: 23 Aug 2021, 16:39
by VicKy
czirimbolo wrote: 4 years ago Ok here is fixed version of level system by Jack and Raheem. Double exp is working too.

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 41
#define TASK_SHOWHUD 2020
#define TASK_DOUBLE 1133
#define REPEAT_TIME 60.0
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
#define LEVELUP "levelup_ZE/ze_levelup.wav"
 
enum
{
    Host = 0,
    User,
    Pass,
    DB
}
 
new const g_iMaxLevelsXP[MAX_LEVEL] =
{
    3000, // 1
    3500, // 2
    5000, // 3
    7500, // 4
    11000, // 5
    15000, // 6
    20000, // 7
    25000, // 8
    30000, // 9
    40000, // 10
    50000, // 11
    60000, // 12
    75000, // 13
    90000, // 14
    105000, // 15
    120000, // 16
    140000, // 17
    170000, // 18
    200000, // 19
    275000, // 20
    350000, // 21
    500000, // 22
    1000000, // 23
    1750000, // 24
    3000000, // 25
    6000000, // 26
    10000000, // 27
    15000000, // 28
    20000000, // 29
    30000000, // 30
    40000000, // 31		
    62000000, // 32
    75000000, // 33
    90000000, // 34
    105000000, // 35
    125000000, // 36
    135000000, // 37
    155000000, // 38
    175000000, // 39
    200000000, // 40		
    300000000 // 41
}
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
new const g_szLogFile[] = "Levels.log" // MySQL Errors log file
new const g_szTable[] =
" \
    ALTER TABLE `test` \
    ADD IF NOT EXISTS `Level` int(20) NOT NULL DEFAULT '0', \
    ADD IF NOT EXISTS `XP` int(20) NOT NULL DEFAULT '0'; \
"
 
// Messages
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.70
const Float:HUD_STATS_X = 0.01
const Float:HUD_STATS_Y = 0.22
 
const HUD_STATS_ZOMBIE_R = 200
const HUD_STATS_ZOMBIE_G = 220
const HUD_STATS_ZOMBIE_B = 0
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 210
 
const HUD_STATS_SPEC_R = 100
const HUD_STATS_SPEC_G = 100
const HUD_STATS_SPEC_B = 100
 
// Variables
new g_iLevel[33],
    g_iXP[33],
    g_iMaxXP[33],
    Float:g_fDamage[33],
    g_MsgSync,
    g_iLevelsVaultHandle,
    g_iRanksVaultHandle,
    Handle:g_hTuple,
    Fw_LevelUP,
    ForwardReturn,
    bool:g_bIsDoubleHours
 
// Cvars
new g_pCvarZombieInfect,
    g_pCvarEscapeSuccess,
    g_pCvarEnableDamage,
    g_pCvarRequiredDamage,
    g_pCvarDamageAward,
    g_pCvarStartXP,
    g_pCvarPercentageStyle,
    g_pCvarStartFromZero,
    g_pCvarAddCommas,
    g_pCvarLevelEffects,
    g_pCvarSaveType,
    g_pCvarDBInfo[4],
    g_pCvarDoubleXP
 
public plugin_natives()
{
    register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
}
 
public plugin_precache()
{
    precache_sound(LEVELUP)
}
 
public plugin_init()
{
    register_plugin("[ZE] Level-XP System", "1.9", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
 
    Fw_LevelUP = CreateMultiForward("ze_on_levelup", ET_IGNORE, FP_CELL)
   
    // Cvars
    g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    g_pCvarStartXP = register_cvar("ze_start_xp", "0")
    g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "0")
    g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
    g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "0")
    g_pCvarDoubleXP = register_cvar("ze_double_xp", "15-22")
 
    g_pCvarSaveType = register_cvar("ze_levels_save_type", "0")
    g_pCvarDBInfo[Host] = register_cvar("ze_levels_host", "127.0.0.1")
    g_pCvarDBInfo[User] = register_cvar("ze_levels_user", "root")
    g_pCvarDBInfo[Pass] = register_cvar("ze_levels_pass", "password")
    g_pCvarDBInfo[DB] = register_cvar("ze_levels_dbname", "levels_db")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
 
    if (get_pcvar_num(g_pCvarSaveType))
    {
        set_task(0.1, "Delay_MySQL_Init")
    }

    DoubleHours()

    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", TASK_DOUBLE, _, _, "b")
    }
}
 
public plugin_end()
{
    if (get_pcvar_num(g_pCvarSaveType))
    {
        if (g_hTuple != Empty_Handle)
        {
            SQL_FreeHandle(g_hTuple)
        }
    }
}
 
public Delay_MySQL_Init()
{
    MySQL_Init()
}
 
public MySQL_Init()
{
    if (!get_pcvar_num(g_pCvarSaveType))
        return
   
    new szHost[64], szUser[32], szPass[32], szDB[128]
   
    get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
   
    g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
   
    // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    new iErrorCode, szError[512], Handle:hSQLConnection
   
    hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
   
    if (hSQLConnection != Empty_Handle)
    {
        log_amx("[MySQL][LVL] Successfully connected to host: %s (ALL IS OK).", szHost)
        SQL_FreeHandle(hSQLConnection)
    }
    else
    {
        // Disable plugin
        set_fail_state("[LVL] Failed to connect to MySQL database: %s.", szError)
    }
   
    SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
}
 
public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public client_putinserver(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
   
    // Just 1 second delay
    set_task(1.0, "DelayLoad", id)
 
    // Other tasks
    set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
   
    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", id+TASK_DOUBLE, _, _, "b")
    }
}
 
public HappyHours(taskid)
{
    DoubleHours()

    if (!g_bIsDoubleHours)
        remove_task(taskid)
   
    new szDoubleHours[32]
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    set_dhudmessage(0, 255, 0, -1.0, 0.20, 0, 0.0, 10.0)
    show_dhudmessage(0, "DOUBLE XP: %s", szDoubleHours)
}
 
public DelayLoad(id)
{
    // Load his data
    LoadData(id)
}
 
public client_disconnected(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
       
    remove_task(id+TASK_SHOWHUD)
    remove_task(id)
}
 
public Show_Hud(taskid)
{  
    new iPlayer = ID_SHOWHUD
   
    if (!is_user_alive(iPlayer))
    {
        iPlayer = pev(iPlayer, pev_iuser2)
       
        if (!is_user_alive(iPlayer))
            return
    }
   
    if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    {
        if(iPlayer != ID_SHOWHUD)
        {
            set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
        else
        {
            set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
    }
    else
    {
        if(iPlayer != ID_SHOWHUD)
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szSpecXP[15], szSpecMaxXP[15]
               
                AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
                AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
               
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
            }  
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szZombieXP[15], szZombieMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
               
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
        else
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szHumanXP[15], szHumanMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
               
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
    }
}
 
public ze_roundend(WinTeam)
{
    if (WinTeam == ZE_TEAM_HUMAN)
    {
        new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarEscapeSuccess) * 2) : get_pcvar_num(g_pCvarEscapeSuccess)

        for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
        {
            if (!is_user_alive(id) || ze_is_user_zombie(id))
                continue
           
            Reward(id, (g_iXP[id] + iXP))
        }
    }
   
    remove_task(TASK_SHOWHUD)
}
 
public Check_User_Level(id)
{
    if (!is_user_connected(id))
        return
 
    if (g_iLevel[id] < MAX_LEVEL)
    {
    	new szName[32]

        while (g_iXP[id] > g_iMaxXP[id])
        {
            if (get_pcvar_num(g_pCvarStartFromZero) == 1)
            {
                g_iXP[id] = 0
            }

        	g_iLevel[id]++
        	g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
            get_user_name(id, szName, charsmax(szName))
            ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
            ExecuteForward(Fw_LevelUP, ForwardReturn, id)
            SaveData(id)
            PlaySound(id, LEVELUP)
           
            if (get_pcvar_num(g_pCvarLevelEffects) != 0)
            {
                // Screen Fade
                message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
                write_short(4096*2)
                write_short(4096*5)
                write_short(0x0001)
                write_byte(random(256))
                write_byte(random(256))
                write_byte(random(256))
                write_byte(150)
                message_end()
               
                // Screen Shake
                message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
                write_short(255<<14)
                write_short(10<<14)
                write_short(255<<14)
                message_end()
            }
        }
    }
}
 
public ze_user_infected(iVictim, iInfector)
{
    if (iInfector == 0)
        return
 
    new iXP = g_bIsDoubleHours ? (get_pcvar_num(g_pCvarZombieInfect) * 2) : get_pcvar_num(g_pCvarZombieInfect)
    Reward(iInfector, (g_iXP[iInfector] + iXP))
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Player Damage Himself
    if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
        return HC_CONTINUE
   
    // Same Team?
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // Store Damage For every Player
    g_fDamage[iAttacker] += fDamage
   
    // Damage Calculator Equal or Higher than needed damage
    if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    {
        // Player did damage that a multiplication of the cvar? Increase coins by this factor
        new iMultiplier = floatround(g_fDamage[iAttacker] / get_pcvar_float(g_pCvarRequiredDamage))
        new iXP = ((g_bIsDoubleHours ? (get_pcvar_num(g_pCvarDamageAward) * 2) : get_pcvar_num(g_pCvarDamageAward)) * iMultiplier)
        Reward(iAttacker, (g_iXP[iAttacker] + iXP))
       
        // Rest The Damage Calculator
        g_fDamage[iAttacker] = 0.0
    }
    return HC_CONTINUE
}
 
public Reward(id, XP)
{
    if ((g_iLevel[id] + 1) < MAX_LEVEL)
    {
        g_iXP[id] = XP
        Check_User_Level(id)
    }
    else
    {
    	if ((g_iXP[id] + XP) >= g_iMaxLevelsXP[MAX_LEVEL - 1])
        {
            g_iXP[id] = g_iMaxXP[id] = g_iMaxLevelsXP[MAX_LEVEL - 1]
        }
    }
    SaveData(id)
}
 
public SaveData(id)
{
    new szAuthID[35], szName[32]
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
 
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256]
        formatex(szData , charsmax(szData), "%i %i", g_iLevel[id], g_iXP[id])
       
        // Open the Vaults
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
        g_iRanksVaultHandle = nvault_open(g_szRanksVault)
 
        // Saves His Data
        nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
        nvault_set(g_iRanksVaultHandle, szAuthID, szName)
       
        // Close Vaults
        nvault_close(g_iLevelsVaultHandle)
        nvault_close(g_iRanksVaultHandle)
    }
    else
    {
        new szQuery[128]
        formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Level` = '%d', `XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], szAuthID)
        SQL_ThreadQuery(g_hTuple, "QuerySetData", szQuery)
    }
}
 
public QuerySetData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public QuerySetData2(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
{
    SQL_IsFail(iFailState, iError, szError, g_szLogFile)
}
 
public LoadData(id)
{
    new szAuthID[35]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
   
    if (!get_pcvar_num(g_pCvarSaveType))
    {
        new szData[256], iTimestamp, iExists
       
        // Open the Vault
        g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
       
        iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
       
        // Close Vault
        nvault_close(g_iLevelsVaultHandle)
       
        if (!iExists)
        {
            g_iLevel[id] = 0
            g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
            SaveData(id)
        }
        else
        {
            new iLevel[32], iXP[32]
            parse(szData, iLevel, 31, iXP, 31)
           
            g_iLevel[id] = str_to_num(iLevel)
            g_iXP[id] = str_to_num(iXP)
        }
 
        g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
    }
    else
    {
        new szQuery[128], szData[5]
        formatex(szQuery, charsmax(szQuery), "SELECT * FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
   
        num_to_str(id, szData, charsmax(szData))
        SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    }
}
 
public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
{
    if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
        return
   
    new id = str_to_num(szData)
   
    // No results for this query means this is new player
    if (!SQL_NumResults(hQuery))
    {
        g_iLevel[id] = 0
        g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
    }
    else
    {
        g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
        g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
    }
 
    g_iMaxXP[id] = g_iMaxLevelsXP[g_iLevel[id]]
}
 
public native_ze_get_user_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iXP[id]
}
 
public native_ze_set_user_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
    
    DoubleHours()
    new addedXP = (amount - g_iXP[id])
    new iXP = g_bIsDoubleHours ? (addedXP * 2) : addedXP
    Reward(id, g_iXP[id] + iXP)
    return true
}
 
public native_ze_get_user_level(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iLevel[id]
}
 
public native_ze_set_user_level(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    if (amount > MAX_LEVEL)
    {
        log_error(AMX_ERR_NATIVE, "Level must be less than or equal to MAX_LEVEL (%d)", MAX_LEVEL)
        return false
    }
 
    g_iLevel[id] = amount
   
    if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    {
        g_iXP[id] = 0
    }
    SaveData(id)
   
    return true
}
 
public native_ze_get_user_max_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false
    }
   
    return g_iMaxXP[id]
}
 
stock DoubleHours()
{
    new szTime[3], szDoubleHours[32], szDoubleHours_Start[32], szDoubleHours_End[32]
    get_time("%H", szTime, charsmax(szTime))
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    for (new ch = 0; ch <= charsmax(szDoubleHours); ch++)
    {
        if (szDoubleHours[ch] == '-')
            szDoubleHours[ch] = ' '
    }
   
    parse(szDoubleHours, szDoubleHours_Start, charsmax(szDoubleHours_Start), szDoubleHours_End, charsmax(szDoubleHours_End))
   
    new iTime, iDoubleHourStart, iDoubleHourEnd
   
    iTime = str_to_num(szTime)
    iDoubleHourStart = str_to_num(szDoubleHours_Start)
    iDoubleHourEnd = str_to_num(szDoubleHours_End)
   
    if (iDoubleHourEnd > iTime >= iDoubleHourStart)
    {
        g_bIsDoubleHours = true
    }
    else
    {
        g_bIsDoubleHours = false
    }
}
@karan PLease Help I am not getiing xp while escape but i getting xp on damage i dont know why!!