Resolved Updating Levels Systeme

Coding Help/Re-API Supported
Post Reply
User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 593
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 19
Contact:

Updating Levels Systeme

#1

Post by Spir0x » 1 Week Ago

Brother help me there i want to update my levels system plugin 1.8 to the latest version 1.9 becuz in my levels systeme code there's a double xp time and i can't move it on the new version.

Levels systeme v1.8 with double XP:

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 50
#define MAX_XP 10672
#define TASK_SHOWHUD 2020
#define TASK_DOUBLE 1133
#define REPEAT_TIME 60.0
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
#define LEVELUP "Premuim_ZE/ze_promoted.mp3"
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
 
// 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.15
 
const HUD_STATS_ZOMBIE_R = 0
const HUD_STATS_ZOMBIE_G = 230
const HUD_STATS_ZOMBIE_B = 255
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 230
const HUD_STATS_HUMAN_B = 255
 
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,
    bool:g_bIsDoubleHours
 
// 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_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)
    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.8", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
   
    // 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_pCvarDoubleXP = register_cvar("ze_double_xp", "9-12")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
}
 
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")
    set_task(0.1, "Check_MaxXP", id, _, _, "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.5, 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 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/50 || 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/50 || 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/50 || 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/50 || 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/50 || 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/50 || 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/50 || 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/50 | 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/50 | 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
           
            DoubleHours()
           
            if (g_bIsDoubleHours)
            {
                g_iXP[id] = g_iXP[id] + (get_pcvar_num(g_pCvarEscapeSuccess) * 2)
            }
            else
            {
                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, "!tPlayer !g%s !tNow in Level %i!y!", szName, g_iLevel[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
   
    DoubleHours()
   
    if (g_bIsDoubleHours)
    {
        g_iXP[iInfector] = g_iXP[iInfector] + (get_pcvar_num(g_pCvarZombieInfect) * 2)
    }
    else
    {
        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
        DoubleHours()
       
        if (g_bIsDoubleHours)
        {
            g_iXP[iAttacker] = g_iXP[iAttacker] + (get_pcvar_num(g_pCvarDamageAward) * 2)
        }
        else
        {
            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
    }
   
    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)
}
 
public LoadData(id)
{
    new szData[256], szAuthID[35], szName[32]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
   
    // 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)
    }
}
 
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 iAddedAmount = amount - g_iXP[id]
   
    if (g_bIsDoubleHours)
    {
        g_iXP[id] = g_iXP[id] + (iAddedAmount * 2)
    }
    else
    {
        g_iXP[id] = amount
    }
 
    Check_User_Level(id)
    SaveData(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
    }
   
    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]
}
 
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
   
    SaveData(id)
   
    return true;
}
 
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
    }
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1036{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1036{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
Latet levels systeme v1.9 without double XP:

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 `Players_Information` ( `id` int(12) NOT NULL AUTO_INCREMENT, `SteamID` varchar(36) NOT NULL,`Level` int(20) NOT NULL,`XP` int(20) NOT NULL,`Max_XP` int(20) NOT NULL, PRIMARY KEY (`id`) );"

// 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_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")
	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 `Players_Information` SET `Level` = '%d', `XP` = '%d', `Max_XP` = '%d' WHERE ( `SteamID` = '%s' );", g_iLevel[id], g_iXP[id], g_iMaxXP[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 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 * FROM `Players_Information` 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))
	{
		new szSteamId[36], szQuery[128]
		get_user_authid(id, szSteamId, charsmax(szSteamId))

		g_iLevel[id] = 0
		g_iXP[id] = 0
		g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
        
        // now we will insturt the values into our table.
		formatex(szQuery, charsmax(szQuery), "INSERT INTO `Players_Information` ( `SteamID` , `Level` , `XP` , `Max_XP`) VALUES ('%s', '%d', '%d', '%d');", szSteamId, g_iLevel[id], g_iXP[id], g_iMaxXP[id])
		SQL_ThreadQuery(g_hTuple, "QuerySetData2", szQuery)
		return
	}

	g_iLevel[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Level"))
	g_iXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "XP"))
	g_iMaxXP[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Max_XP"))
}

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;
}
I trynna make money, not friends.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1792
Joined: 2 Years Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 88 times
Age: 21
Contact:

#2

Post by Raheem » 3 Days Ago

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest