plugin that when zombie infect 3 human get 20 xp

Unpaid Requests, Public Plugins
Post Reply
User avatar
Luxurious
Senior Member
Senior Member
Egypt
Posts: 150
Joined: 1 Year Ago
Location: Egypt
Has thanked: 3 times
Been thanked: 4 times
Contact:

plugin that when zombie infect 3 human get 20 xp

#1

Post by Luxurious » 2 Weeks Ago

I need Some plugin that when zombie infect 3 (with cvar) human get some xp (with cvar)

or add it to level system

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] =
{
    20, // 1
    60, // 2
    120, // 3
    200, // 4 
    300, // 5
    420, // 6
    560, // 7
    720, // 8
    900, // 9
    1100, // 10
    1320, // 11
    1560, // 12
    1820, // 13
    2100, // 14
    2400, // 15
    2070, // 16
    3060, // 17
    3420, // 18
    3800, // 19
    4200, // 20
    5200, // 21
    6700, // 22
    8700, // 23
    11200, // 24
    14200, // 25
    17700, // 26
    21700, // 27
    26200, // 28
    31200, // 29
    36700, // 30
    37700, // 31		
    52700, // 32
    72000, // 33
    97700, // 34
    127700, // 35
    167700, // 36
    217700, // 37
    277000, // 38
    357000, // 39
    457000 // 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.0
const Float:HUD_SPECT_Y = 0.30
const Float:HUD_STATS_X = 0.00
const Float:HUD_STATS_Y = 0.06
 
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", "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 | Escape: %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 | Escape: %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 | 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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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
    }
}
BeTalk Zombie-Escape V1.4
IP : 51.77.103.159:27015

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1972
Joined: 2 Years Ago
Location: Egypt
Has thanked: 32 times
Been thanked: 108 times
Age: 22
Contact:

#2

Post by Raheem » 1 Week Ago

Test:

  1. #include <zombie_escape>
  2. #include <ze_levels>
  3.  
  4. new g_pCvarZombieInfectNum, g_pCvarXP
  5.  
  6. new g_iInfections[33]
  7.  
  8. public plugin_init()
  9. {
  10.     register_plugin("Give XP", "1.0", "Raheem")
  11.    
  12.     g_pCvarZombieInfectNum = register_cvar("ze_infect_humans_num", "3")
  13.     g_pCvarXP = register_cvar("ze_xp_reward", "20")
  14. }
  15.  
  16. public ze_user_infected(iVictim, iInfector)
  17. {
  18.     if (g_iInfections[iInfector] >= get_pcvar_num(g_pCvarZombieInfectNum))
  19.     {
  20.         ze_set_user_xp(iInfector, ze_get_user_xp(iInfector) + get_pcvar_num(g_pCvarXP))
  21.         g_iInfections[iInfector] = 0
  22.     }
  23.     else
  24.     {
  25.         g_iInfections[iInfector]++
  26.     }
  27. }
You don't know? Learn and you will know.

User avatar
Luxurious
Senior Member
Senior Member
Egypt
Posts: 150
Joined: 1 Year Ago
Location: Egypt
Has thanked: 3 times
Been thanked: 4 times
Contact:

#3

Post by Luxurious » 1 Week Ago

Raheem wrote:
1 Week Ago
Test:

  1. #include <zombie_escape>
  2. #include <ze_levels>
  3.  
  4. new g_pCvarZombieInfectNum, g_pCvarXP
  5.  
  6. new g_iInfections[33]
  7.  
  8. public plugin_init()
  9. {
  10.     register_plugin("Give XP", "1.0", "Raheem")
  11.    
  12.     g_pCvarZombieInfectNum = register_cvar("ze_infect_humans_num", "3")
  13.     g_pCvarXP = register_cvar("ze_xp_reward", "20")
  14. }
  15.  
  16. public ze_user_infected(iVictim, iInfector)
  17. {
  18.     if (g_iInfections[iInfector] >= get_pcvar_num(g_pCvarZombieInfectNum))
  19.     {
  20.         ze_set_user_xp(iInfector, ze_get_user_xp(iInfector) + get_pcvar_num(g_pCvarXP))
  21.         g_iInfections[iInfector] = 0
  22.     }
  23.     else
  24.     {
  25.         g_iInfections[iInfector]++
  26.     }
  27. }
You Can Make Some Hud for it ?
Like when some one is zombie got : infects : %s/3 ?
BeTalk Zombie-Escape V1.4
IP : 51.77.103.159:27015

User avatar
sPe3doN
Senior Member
Senior Member
Algeria
Posts: 211
Joined: 2 Years Ago
Has thanked: 14 times
Been thanked: 7 times
Age: 20
Contact:

#4

Post by sPe3doN » 1 Week Ago

Luxurious wrote:
1 Week Ago
Raheem wrote:
1 Week Ago
Test:

  1. #include <zombie_escape>
  2. #include <ze_levels>
  3.  
  4. new g_pCvarZombieInfectNum, g_pCvarXP
  5.  
  6. new g_iInfections[33]
  7.  
  8. public plugin_init()
  9. {
  10.     register_plugin("Give XP", "1.0", "Raheem")
  11.    
  12.     g_pCvarZombieInfectNum = register_cvar("ze_infect_humans_num", "3")
  13.     g_pCvarXP = register_cvar("ze_xp_reward", "20")
  14. }
  15.  
  16. public ze_user_infected(iVictim, iInfector)
  17. {
  18.     if (g_iInfections[iInfector] >= get_pcvar_num(g_pCvarZombieInfectNum))
  19.     {
  20.         ze_set_user_xp(iInfector, ze_get_user_xp(iInfector) + get_pcvar_num(g_pCvarXP))
  21.         g_iInfections[iInfector] = 0
  22.     }
  23.     else
  24.     {
  25.         g_iInfections[iInfector]++
  26.     }
  27. }
You Can Make Some Hud for it ?
Like when some one is zombie got : infects : %s/3 ?
try:

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] =
{
    20, // 1
    60, // 2
    120, // 3
    200, // 4 
    300, // 5
    420, // 6
    560, // 7
    720, // 8
    900, // 9
    1100, // 10
    1320, // 11
    1560, // 12
    1820, // 13
    2100, // 14
    2400, // 15
    2070, // 16
    3060, // 17
    3420, // 18
    3800, // 19
    4200, // 20
    5200, // 21
    6700, // 22
    8700, // 23
    11200, // 24
    14200, // 25
    17700, // 26
    21700, // 27
    26200, // 28
    31200, // 29
    36700, // 30
    37700, // 31		
    52700, // 32
    72000, // 33
    97700, // 34
    127700, // 35
    167700, // 36
    217700, // 37
    277000, // 38
    357000, // 39
    457000 // 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.0
const Float:HUD_SPECT_Y = 0.30
const Float:HUD_STATS_X = 0.00
const Float:HUD_STATS_Y = 0.06
 
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_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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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
 
    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
    }
}

User avatar
Luxurious
Senior Member
Senior Member
Egypt
Posts: 150
Joined: 1 Year Ago
Location: Egypt
Has thanked: 3 times
Been thanked: 4 times
Contact:

#5

Post by Luxurious » 1 Week Ago

sPe3doN wrote:
1 Week Ago
Luxurious wrote:
1 Week Ago
Raheem wrote:
1 Week Ago
Test:

  1. #include <zombie_escape>
  2. #include <ze_levels>
  3.  
  4. new g_pCvarZombieInfectNum, g_pCvarXP
  5.  
  6. new g_iInfections[33]
  7.  
  8. public plugin_init()
  9. {
  10.     register_plugin("Give XP", "1.0", "Raheem")
  11.    
  12.     g_pCvarZombieInfectNum = register_cvar("ze_infect_humans_num", "3")
  13.     g_pCvarXP = register_cvar("ze_xp_reward", "20")
  14. }
  15.  
  16. public ze_user_infected(iVictim, iInfector)
  17. {
  18.     if (g_iInfections[iInfector] >= get_pcvar_num(g_pCvarZombieInfectNum))
  19.     {
  20.         ze_set_user_xp(iInfector, ze_get_user_xp(iInfector) + get_pcvar_num(g_pCvarXP))
  21.         g_iInfections[iInfector] = 0
  22.     }
  23.     else
  24.     {
  25.         g_iInfections[iInfector]++
  26.     }
  27. }
You Can Make Some Hud for it ?
Like when some one is zombie got : infects : %s/3 ?
try:

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] =
{
    20, // 1
    60, // 2
    120, // 3
    200, // 4 
    300, // 5
    420, // 6
    560, // 7
    720, // 8
    900, // 9
    1100, // 10
    1320, // 11
    1560, // 12
    1820, // 13
    2100, // 14
    2400, // 15
    2070, // 16
    3060, // 17
    3420, // 18
    3800, // 19
    4200, // 20
    5200, // 21
    6700, // 22
    8700, // 23
    11200, // 24
    14200, // 25
    17700, // 26
    21700, // 27
    26200, // 28
    31200, // 29
    36700, // 30
    37700, // 31		
    52700, // 32
    72000, // 33
    97700, // 34
    127700, // 35
    167700, // 36
    217700, // 37
    277000, // 38
    357000, // 39
    457000 // 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.0
const Float:HUD_SPECT_Y = 0.30
const Float:HUD_STATS_X = 0.00
const Float:HUD_STATS_Y = 0.06
 
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_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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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
 
    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
    }
}
Working but when i make 6 infictions it showing 6/5
BeTalk Zombie-Escape V1.4
IP : 51.77.103.159:27015

User avatar
sPe3doN
Senior Member
Senior Member
Algeria
Posts: 211
Joined: 2 Years Ago
Has thanked: 14 times
Been thanked: 7 times
Age: 20
Contact:

#6

Post by sPe3doN » 6 Days Ago

Luxurious wrote:
1 Week Ago
sPe3doN wrote:
1 Week Ago
Luxurious wrote:
1 Week Ago


You Can Make Some Hud for it ?
Like when some one is zombie got : infects : %s/3 ?
try:

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] =
{
    20, // 1
    60, // 2
    120, // 3
    200, // 4 
    300, // 5
    420, // 6
    560, // 7
    720, // 8
    900, // 9
    1100, // 10
    1320, // 11
    1560, // 12
    1820, // 13
    2100, // 14
    2400, // 15
    2070, // 16
    3060, // 17
    3420, // 18
    3800, // 19
    4200, // 20
    5200, // 21
    6700, // 22
    8700, // 23
    11200, // 24
    14200, // 25
    17700, // 26
    21700, // 27
    26200, // 28
    31200, // 29
    36700, // 30
    37700, // 31		
    52700, // 32
    72000, // 33
    97700, // 34
    127700, // 35
    167700, // 36
    217700, // 37
    277000, // 38
    357000, // 39
    457000 // 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.0
const Float:HUD_SPECT_Y = 0.30
const Float:HUD_STATS_X = 0.00
const Float:HUD_STATS_Y = 0.06
 
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_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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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
 
    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
    }
}
Working but when i make 6 infictions it showing 6/5
Hmm I 'll fix it when I have time

[ Post made via Android ]

User avatar
Luxurious
Senior Member
Senior Member
Egypt
Posts: 150
Joined: 1 Year Ago
Location: Egypt
Has thanked: 3 times
Been thanked: 4 times
Contact:

#7

Post by Luxurious » 6 Days Ago

sPe3doN wrote:
6 Days Ago
Luxurious wrote:
1 Week Ago
sPe3doN wrote:
1 Week Ago


try:

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] =
{
    20, // 1
    60, // 2
    120, // 3
    200, // 4 
    300, // 5
    420, // 6
    560, // 7
    720, // 8
    900, // 9
    1100, // 10
    1320, // 11
    1560, // 12
    1820, // 13
    2100, // 14
    2400, // 15
    2070, // 16
    3060, // 17
    3420, // 18
    3800, // 19
    4200, // 20
    5200, // 21
    6700, // 22
    8700, // 23
    11200, // 24
    14200, // 25
    17700, // 26
    21700, // 27
    26200, // 28
    31200, // 29
    36700, // 30
    37700, // 31		
    52700, // 32
    72000, // 33
    97700, // 34
    127700, // 35
    167700, // 36
    217700, // 37
    277000, // 38
    357000, // 39
    457000 // 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.0
const Float:HUD_SPECT_Y = 0.30
const Float:HUD_STATS_X = 0.00
const Float:HUD_STATS_Y = 0.06
 
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_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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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 | Escape: %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
 
    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
    }
}
Working but when i make 6 infictions it showing 6/5
Hmm I 'll fix it when I have time

Np , its solved ! thx
BeTalk Zombie-Escape V1.4
IP : 51.77.103.159:27015

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests