Right way to set Max-XPs in Level-System

Helping Topics
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 7 years ago
Contact:

Right way to set Max-XPs in Level-System

#1

Post by Raheem » 6 years ago

Hello,

How are you? Hope you are fine :). In this topic we will learn how we can set right cvars for our levels system.

OK, first you may notice that in our levels system you can't control the xp value needed for next level. So first term you should get is when i say:

Max-XP for level 1
  • Means how much xp i must get so i go to level 1? PlayerXP/NextLevelNeededXP
Our levels system, works like when a player enter server he get 50/100 and his level is 0. This means he need to get 100 xp to go to level 1.

In cvars, you need to define the max-xp for level 1:
  • ze_max_xp_first_level 100
And need to define also the increment rate that max-xp for next levels will be multiplied by:
  • ze_maxlevels_increment 2
How to know XP needed for level 50? maybe it's very high so we need to set right values :idea:

First there is equation, how next level needed xp calculated:
  • nextLevelNeededXP = previousLevelNeededXP * IncrementFactor
Example:
  • One player have 1200 xp and xp needed for next level is 1800. 1200/1800 So if he got the 1800 xp he will go to new level. 1800/UnknownValue and this unknown value is = 1800 * IncrementFactor
    That's how it's calculated.
Seems it's hard to know level 40 will require how much xp so player get. And also you need to set right increment factor. For this reason i wrote a javafx program that will help in calculating max-xp needed for all levels.

Also i'll explain how to set some more increment factors like:
  • From level 0 to level 20 - Increment factor 1.4
    From level 21 to level 40 - Increment factor 1.1
You should also know about: These definations can be changed from source then compile the plugin.

Let's see the software that will help in this: NOTE: You will need installing JVM so this program working, download from here.

How to use it?
  1. Write the starting level number.
  2. Write Max-XP needed so player can reach this starting level.
  3. Write the end level number.
  4. Write the increment factor.
Then you can press any button:
  1. Calculate all max-xp - Will show you list of all levels and max xp needed to reach them.
  2. Calculate end level max-xp - will only calculate the max xp needed to reach the end level.
Some screenshots:
  • ImageImageImage
Example(Screenshot2): Player to reach level 2 he should get 110 xp like: hisXP/110 and so on.

Now you can edit code in levels system to add more factors for ranges (You will edit public Check_User_Level(id)):
    1. public Check_User_Level(id)
    2. {
    3.     if(!is_user_connected(id))
    4.         return
    5.  
    6.     if(g_iXP[id] >= g_iMaxXP[id])
    7.     {
    8.         if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    9.         {
    10.             g_iXP[id] = 0
    11.         }
    12.        
    13.         new szName[32]
    14.         g_iLevel[id] ++
    15.        
    16.         if (g_iLevel[id] >= 0 && g_iLevel[id] < 20)
    17.         {
    18.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.4)
    19.         }
    20.         else if (g_iLevel[id] >= 20 && g_iLevel[id] < 40)
    21.         {
    22.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.2)
    23.         }
    24.         else if (g_iLevel[id] >= 40 && g_iLevel[id] <= 50) // 50 is our max
    25.         {
    26.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.08)
    27.         }
    28.        
    29.         get_user_name(id, szName, charsmax(szName))
    30.         ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
    31.        
    32.         SaveData(id)
    33.        
    34.         PlaySound(id, LEVELUP)
    35.        
    36.         if (get_pcvar_num(g_pCvarLevelEffects) != 0)
    37.         {
    38.             // Screen Fade
    39.             message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
    40.             write_short(4096*2)
    41.             write_short(4096*5)
    42.             write_short(0x0001)
    43.             write_byte(random(256))
    44.             write_byte(random(256))
    45.             write_byte(random(256))
    46.             write_byte(150)
    47.             message_end()
    48.            
    49.             // Screen Shake
    50.             message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
    51.             write_short(255<<14)
    52.             write_short(10<<14)
    53.             write_short(255<<14)
    54.             message_end()
    55.         }
    56.     }
    57. }
And edit public Check_MaxXP(id):
    1. public Check_MaxXP(id)
    2. {
    3.     new iCurrentMaxXP = g_iMaxXP[id]
    4.    
    5.     new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
    6.    
    7.     if (g_iLevel[id] >= 0 && g_iLevel[id] < 20)
    8.     {
    9.         for (new i = 1; i <= g_iLevel[id]; i++)
    10.         {
    11.             iMaxXP = floatround(float(iMaxXP) * 1.4)
    12.         }
    13.     }
    14.    
    15.     if (g_iLevel[id] >= 20 && g_iLevel[id] < 40)
    16.     {
    17.         for (new i = 1; i < 20; i++)
    18.         {
    19.             iMaxXP = floatround(float(iMaxXP) * 1.4)
    20.         }
    21.        
    22.         for (new i = 20; i <= g_iLevel[id]; i++)
    23.         {
    24.             iMaxXP = floatround(float(iMaxXP) * 1.2)
    25.         }
    26.     }
    27.    
    28.     if (g_iLevel[id] >= 40 && g_iLevel[id] <= 50)
    29.     {
    30.         for (new i = 1; i < 20; i++)
    31.         {
    32.             iMaxXP = floatround(float(iMaxXP) * 1.4)
    33.         }
    34.        
    35.         for (new i = 20; i < g_iLevel[id]; i++)
    36.         {
    37.             iMaxXP = floatround(float(iMaxXP) * 1.2)
    38.         }
    39.        
    40.         for (new i = 40; i <= g_iLevel[id]; i++)
    41.         {
    42.             iMaxXP = floatround(float(iMaxXP) * 1.08)
    43.         }
    44.     }
    45.    
    46.     if (iCurrentMaxXP != iMaxXP)
    47.     {
    48.         g_iMaxXP[id] = iMaxXP
    49.     }
    50. }
Any problem, please post down.
Last edited by Raheem 6 years ago, edited 1 time in total.
He who fails to plan is planning to fail

User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 7 years ago
Contact:

#2

Post by Night Fury » 6 years ago

To get max xp to level 50 for example:
IncrementFactor * 50 * current level max xp
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 7 years ago
Contact:

#3

Post by Raheem » 6 years ago

Jack GamePlay wrote: 6 years ago To get max xp to level 50 for example:
IncrementFactor * 50 * current level max xp
No, not right.
He who fails to plan is planning to fail

User avatar
Mark
VIP
VIP
United States of America
Posts: 283
Joined: 6 years ago
Location: Des Moines/USA
Contact:

#4

Post by Mark » 6 years ago

Raheem wrote: 6 years ago
Jack GamePlay wrote: 6 years ago To get max xp to level 50 for example:
IncrementFactor * 50 * current level max xp
No, not right.
so would this work?
  1.         if (get_pcvar_num(g_pCvarStartFromZero) == 1)
  2.         {
  3.             g_iXP[id] = 0
  4.         }
  5.        
  6.         new szName[32]
  7.         g_iLevel[id] ++
  8.        
  9.         if (g_iLevel[id] >= 0 && g_iLevel[id] < 10)
  10.         {
  11.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.3)
  12.         }
  13.         else if (g_iLevel[id] >= 10 && g_iLevel[id] < 20)
  14.         {
  15.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.4)
  16.         }
  17.         else if (g_iLevel[id] >= 20 && g_iLevel[id] <= 30)
  18.         {
  19.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.5)
  20.         }
  21.         else if (g_iLevel[id] >= 30 && g_iLevel[id] < 50)
  22.         {
  23.             g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.6)
  24.         }
  1. 2  -  130
  2. 3  -  169
  3. 4  -  220
  4. 5  -  286
  5. 6  -  371
  6. 7  -  483
  7. 8  -  627
  8. 9  -  816
  9. 10  -  1060
  10. 11  -  1378
  11. 12  -  1791
  12. 13  -  2329
  13. 14  -  3027
  14. 15  -  3936
  15. 16  -  5116
  16. 17  -  6651
  17. 18  -  8647
  18. 19  -  11241
  19. 20  -  14613
  20. 21  -  21920
  21. 22  -  32879
  22. 23  -  49319
  23. 24  -  73978
  24. 25  -  110967
  25. 26  -  166451
  26. 27  -  249677
  27. 28  -  374515
  28. 29  -  561773
  29. 30  -  842659
  30. 31  -  1348254
  31. 32  -  2157207
  32. 33  -  3451531
  33. 34  -  5522450
  34. 35  -  8835920
  35. 36  -  14137472
  36. 37  -  22619955
  37. 38  -  36191928
  38. 39  -  57907086
  39. 40  -  92651337
  40. 41  -  148242139
  41. 42  -  237187422
  42. 43  -  379499876
  43. 44  -  607199801
  44. 45  -  971519682
  45. 46  -  1554431491
  46. 47  -  2487090386
  47. 48  -  3979344618
  48. 49  -  6366951389
  49. 50  -  10187122222

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 7 years ago
Contact:

#5

Post by Raheem » 6 years ago

Will work but 10187122222 is incredible number :lol:, should when level high you low the factor.
He who fails to plan is planning to fail

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 7 years ago
Contact:

#6

Post by Raheem » 6 years ago

I forget set ranges in public Check_MaxXP(id), please see update.
He who fails to plan is planning to fail

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 7 years ago
Contact:

#7

Post by Raheem » 6 years ago

Updated, re-read.
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 599
Joined: 7 years ago
Contact:

#8

Post by czirimbolo » 6 years ago

Ok what about cvar ze_maxlevels_increment ? It work only for level 0 to level 20 in this example?
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 7 years ago
Contact:

#9

Post by Raheem » 6 years ago

Not needed with code i posted, you can remove it even from the code.
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 599
Joined: 7 years ago
Contact:

#10

Post by czirimbolo » 6 years ago

Raheem, can you help me? Here is my level system

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 50
#define MAX_XP 5000000
#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"
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
 
// Messages
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.70
const Float:HUD_STATS_X = -1.0
const Float:HUD_STATS_Y = 0.90
 
const HUD_STATS_ZOMBIE_R = 200
const HUD_STATS_ZOMBIE_G = 220
const HUD_STATS_ZOMBIE_B = 0
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 210
 
const HUD_STATS_SPEC_R = 100
const HUD_STATS_SPEC_G = 100
const HUD_STATS_SPEC_B = 100
 
// Variables
new g_iLevel[33],
    g_iXP[33],
    g_iMaxXP[33],
    Float:g_fDamage[33],
    g_MsgSync,
    g_iLevelsVaultHandle,
    g_iRanksVaultHandle,
    bool:g_bIsDoubleHours
 
// Cvars
new g_pCvarZombieInfect,
    g_pCvarEscapeSuccess,
    g_pCvarEnableDamage,
    g_pCvarRequiredDamage,
    g_pCvarDamageAward,
    g_pCvarStartXP,
    g_pCvarMaxXPFirstLevel,
    g_pCvarPercentageStyle,
    g_pCvarStartFromZero,
    g_pCvarAddCommas,
    g_pCvarLevelEffects,
    g_pCvarDoubleXP
 
public plugin_natives()
{
    register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
    register_native("ze_set_user_max_xp", "native_ze_set_user_max_xp", 1)
}
 
public plugin_precache()
{
    precache_sound(LEVELUP)
}
 
public plugin_init()
{
    register_plugin("[ZE] Level-XP System", "1.8", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
   
    // Cvars
    g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    g_pCvarStartXP = register_cvar("ze_start_xp", "50")
    g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "100")
    g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "1")
    g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
    g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
    g_pCvarDoubleXP = register_cvar("ze_double_xp", "9-12")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
}
 
public client_putinserver(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
   
    // Just 1 second delay
    set_task(1.0, "DelayLoad", id)
 
    // Other tasks
    set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
    set_task(0.1, "Check_MaxXP", id, _, _, "b")
   
    // Message task
    DoubleHours()
   
    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", id+TASK_DOUBLE, _, _, "b")
    }
}
 
public HappyHours(taskid)
{
    new id = taskid - TASK_DOUBLE
   
    DoubleHours()
   
    if (!g_bIsDoubleHours)
        remove_task(taskid)
   
    new szDoubleHours[32]
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    set_dhudmessage(0, 255, 0, -1.0, 0.5, 0, 0.0, 10.0)
    show_dhudmessage(id, "DOUBLE XP: %s", szDoubleHours)
}
 
public DelayLoad(id)
{
    // Load his data
    LoadData(id)
}
 
public client_disconnected(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
       
    remove_task(id+TASK_SHOWHUD)
    remove_task(id)
}
 
public Check_MaxXP(id)
{
    new iCurrentMaxXP = g_iMaxXP[id]
   
    new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
   
    if (g_iLevel[id] >= 0 && g_iLevel[id] < 10)
    {
        for (new i = 1; i <= g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.55)
        }
    }
   
    if (g_iLevel[id] >= 10 && g_iLevel[id] < 25)
    {
        for (new i = 1; i < 10; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.55)
        }
       
        for (new i = 10; i <= g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.28)
        }
    }
   
    if (g_iLevel[id] >= 40 && g_iLevel[id] <= 50)
    {
        for (new i = 1; i < 40; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.28)
        }
       
        for (new i = 20; i < g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.04)
        }
       
        for (new i = 40; i <= g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.04)
        }
    }
   
    if (iCurrentMaxXP != iMaxXP)
    {
        g_iMaxXP[id] = iMaxXP
    }
}
 
public Show_Hud(taskid)
{  
    new iPlayer = ID_SHOWHUD
   
    if (!is_user_alive(iPlayer))
    {
        iPlayer = pev(iPlayer, pev_iuser2)
       
        if (!is_user_alive(iPlayer))
            return
    }
   
    if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    {
        if(iPlayer != ID_SHOWHUD)
        {
            set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
        else
        {
            set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
    }
    else
    {
        if(iPlayer != ID_SHOWHUD)
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szSpecXP[15], szSpecMaxXP[15]
               
                AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
                AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
               
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
            }  
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szZombieXP[15], szZombieMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
               
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
        else
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szHumanXP[15], szHumanMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
               
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
    }
}
 
public ze_roundend(WinTeam)
{
    if (WinTeam == ZE_TEAM_HUMAN)
    {
        for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
        {
            if (!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
                continue
           
            g_iXP[id] += get_pcvar_num(g_pCvarEscapeSuccess)
            SaveData(id)
            Check_User_Level(id)
        }
    }
   
    remove_task(TASK_SHOWHUD)
}
 
public Check_User_Level(id)
{
    if(!is_user_connected(id))
        return
 
    if(g_iXP[id] >= g_iMaxXP[id])
    {
        if (get_pcvar_num(g_pCvarStartFromZero) == 1)
        {
            g_iXP[id] = 0
        }
       
        new szName[32]
        g_iLevel[id] ++
       
        if (g_iLevel[id] >= 0 && g_iLevel[id] < 10)
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.55)
        }
        else if (g_iLevel[id] >= 10 && g_iLevel[id] < 25)
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.28)
        }
		else if (g_iLevel[id] >= 25 && g_iLevel[id] < 40)
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.04)
        }
        else if (g_iLevel[id] >= 40 && g_iLevel[id] <= 50) // 50 is our max
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.02)
        }
       
        get_user_name(id, szName, charsmax(szName))
        ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
       
        SaveData(id)
       
        PlaySound(id, LEVELUP)
       
        if (get_pcvar_num(g_pCvarLevelEffects) != 0)
        {
            // Screen Fade
            message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
            write_short(4096*2)
            write_short(4096*5)
            write_short(0x0001)
            write_byte(random(256))
            write_byte(random(256))
            write_byte(random(256))
            write_byte(150)
            message_end()
           
            // Screen Shake
            message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
            write_short(255<<14)
            write_short(10<<14)
            write_short(255<<14)
            message_end()
        }
    }
}
 
public ze_user_infected(iVictim, iInfector)
{
    if (iInfector == 0)
        return
   
    g_iXP[iInfector] += get_pcvar_num(g_pCvarZombieInfect)
    SaveData(iInfector)
    Check_User_Level(iInfector)
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Player Damage Himself
    if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
        return HC_CONTINUE
   
    // Same Team?
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // Store Damage For every Player
    g_fDamage[iAttacker] += fDamage
   
    // Damage Calculator Equal or Higher than needed damage
    if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    {
        // Give Player The Coins
        g_iXP[iAttacker] += get_pcvar_num(g_pCvarDamageAward)
        SaveData(iAttacker)
        Check_User_Level(iAttacker)
       
        // Rest The Damage Calculator
        g_fDamage[iAttacker] = 0.0
    }
    return HC_CONTINUE
}
 
public SaveData(id)
{
    new szAuthID[35], szName[32]
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
   
    // Set Him to max if he Higher than Max Value
    if(g_iLevel[id] > MAX_LEVEL)
    {
        g_iLevel[id] = MAX_LEVEL
    }
   
    if(g_iXP[id] > MAX_XP)
    {
        g_iXP[id] = MAX_XP
    }
   
    new szData[256]
    formatex(szData , charsmax(szData), "%i %i %i", g_iLevel[id], g_iXP[id], g_iMaxXP[id])
   
    // Open the Vaults
    g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
    g_iRanksVaultHandle = nvault_open(g_szRanksVault)
 
    // Saves His Data
    nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
    nvault_set(g_iRanksVaultHandle, szAuthID, szName)
   
    // Close Vaults
    nvault_close(g_iLevelsVaultHandle)
    nvault_close(g_iRanksVaultHandle)
}
 
public LoadData(id)
{
    new szData[256], szAuthID[35], szName[32]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
   
    // Useless Variable
    new iTimestamp, iExists
   
    // Open the Vault
    g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
   
    iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
   
    // Close Vault
    nvault_close(g_iLevelsVaultHandle)
   
    if (!iExists)
    {
        g_iLevel[id] = 0
        g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
        g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
        SaveData(id)
    }
    else
    {
        new iLevel[32], iXP[32], iMaxLevel[32]
        parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
       
        g_iLevel[id] = str_to_num(iLevel)
        g_iXP[id] = str_to_num(iXP)
        g_iMaxXP[id] = str_to_num(iMaxLevel)
    }
}
 
public native_ze_get_user_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iXP[id]
}
 
public native_ze_set_user_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    DoubleHours()
   
    new iAddedAmount = amount - g_iXP[id]
   
    if (g_bIsDoubleHours)
    {
        g_iXP[id] = g_iXP[id] + (iAddedAmount * 2)
    }
    else
    {
        g_iXP[id] = amount
    }
   
    Check_User_Level(id)
    SaveData(id)
    return true;
}
 
public native_ze_get_user_level(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iLevel[id]
}
 
public native_ze_set_user_level(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_iLevel[id] = amount
   
    if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    {
        g_iXP[id] = 0
    }
   
    SaveData(id)
   
    return true;
}
 
public native_ze_get_user_max_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iMaxXP[id]
}
 
public native_ze_set_user_max_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_iMaxXP[id] = amount
   
    SaveData(id)
   
    return true;
}
 
stock DoubleHours()
{
    new szTime[3], szDoubleHours[32], szDoubleHours_Start[32], szDoubleHours_End[32]
    get_time("%H", szTime, charsmax(szTime))
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    for (new ch = 0; ch <= charsmax(szDoubleHours); ch++)
    {
        if (szDoubleHours[ch] == '-')
            szDoubleHours[ch] = ' '
    }
   
    parse(szDoubleHours, szDoubleHours_Start, charsmax(szDoubleHours_Start), szDoubleHours_End, charsmax(szDoubleHours_End))
   
    new iTime, iDoubleHourStart, iDoubleHourEnd
   
    iTime = str_to_num(szTime)
    iDoubleHourStart = str_to_num(szDoubleHours_Start)
    iDoubleHourEnd = str_to_num(szDoubleHours_End)
   
    if(iDoubleHourEnd > iTime >= iDoubleHourStart)
    {
        g_bIsDoubleHours = true
    }
    else
    {
        g_bIsDoubleHours = false
    }
}
I would like this:

Code: Select all

1,55 factor  1 to 10 level
1,28 factor  10 to 25 level
1,04 factor 25 to 40
1,02  facotr  40 to 50
I messed up public Check_MaxXP(id)
Image

User avatar
Mark
VIP
VIP
United States of America
Posts: 283
Joined: 6 years ago
Location: Des Moines/USA
Contact:

#11

Post by Mark » 6 years ago

czirimbolo wrote: 6 years ago Raheem, can you help me? Here is my level system

Code: Select all

#include <zombie_escape>
 
// Defines
#define MAX_LEVEL 50
#define MAX_XP 5000000
#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"
 
// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[] = "Ranks"
 
// Messages
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.70
const Float:HUD_STATS_X = -1.0
const Float:HUD_STATS_Y = 0.90
 
const HUD_STATS_ZOMBIE_R = 200
const HUD_STATS_ZOMBIE_G = 220
const HUD_STATS_ZOMBIE_B = 0
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 210
 
const HUD_STATS_SPEC_R = 100
const HUD_STATS_SPEC_G = 100
const HUD_STATS_SPEC_B = 100
 
// Variables
new g_iLevel[33],
    g_iXP[33],
    g_iMaxXP[33],
    Float:g_fDamage[33],
    g_MsgSync,
    g_iLevelsVaultHandle,
    g_iRanksVaultHandle,
    bool:g_bIsDoubleHours
 
// Cvars
new g_pCvarZombieInfect,
    g_pCvarEscapeSuccess,
    g_pCvarEnableDamage,
    g_pCvarRequiredDamage,
    g_pCvarDamageAward,
    g_pCvarStartXP,
    g_pCvarMaxXPFirstLevel,
    g_pCvarPercentageStyle,
    g_pCvarStartFromZero,
    g_pCvarAddCommas,
    g_pCvarLevelEffects,
    g_pCvarDoubleXP
 
public plugin_natives()
{
    register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
    register_native("ze_set_user_xp", "native_ze_set_user_xp", 1)
    register_native("ze_get_user_level", "native_ze_get_user_level", 1)
    register_native("ze_set_user_level", "native_ze_set_user_level", 1)
    register_native("ze_get_user_max_xp", "native_ze_get_user_max_xp", 1)
    register_native("ze_set_user_max_xp", "native_ze_set_user_max_xp", 1)
}
 
public plugin_precache()
{
    precache_sound(LEVELUP)
}
 
public plugin_init()
{
    register_plugin("[ZE] Level-XP System", "1.8", "Raheem/JaCk")
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
   
    // Cvars
    g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
    g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
    g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
    g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
    g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
    g_pCvarStartXP = register_cvar("ze_start_xp", "50")
    g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "100")
    g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "1")
    g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
    g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
    g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
    g_pCvarDoubleXP = register_cvar("ze_double_xp", "9-12")
   
    // Messages
    g_MsgSync = CreateHudSyncObj()
}
 
public client_putinserver(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
   
    // Just 1 second delay
    set_task(1.0, "DelayLoad", id)
 
    // Other tasks
    set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
    set_task(0.1, "Check_MaxXP", id, _, _, "b")
   
    // Message task
    DoubleHours()
   
    if (g_bIsDoubleHours)
    {
        set_task(REPEAT_TIME, "HappyHours", id+TASK_DOUBLE, _, _, "b")
    }
}
 
public HappyHours(taskid)
{
    new id = taskid - TASK_DOUBLE
   
    DoubleHours()
   
    if (!g_bIsDoubleHours)
        remove_task(taskid)
   
    new szDoubleHours[32]
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    set_dhudmessage(0, 255, 0, -1.0, 0.5, 0, 0.0, 10.0)
    show_dhudmessage(id, "DOUBLE XP: %s", szDoubleHours)
}
 
public DelayLoad(id)
{
    // Load his data
    LoadData(id)
}
 
public client_disconnected(id)
{
    if(is_user_hltv(id) || is_user_bot(id))
        return
       
    remove_task(id+TASK_SHOWHUD)
    remove_task(id)
}
 
public Check_MaxXP(id)
{
    new iCurrentMaxXP = g_iMaxXP[id]
   
    new iMaxXP = get_pcvar_num(g_pCvarMaxXPFirstLevel)
   
    if (g_iLevel[id] >= 0 && g_iLevel[id] < 10)
    {
        for (new i = 1; i <= g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.55)
        }
    }
   
    if (g_iLevel[id] >= 10 && g_iLevel[id] < 25)
    {
        for (new i = 1; i < 10; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.55)
        }
       
        for (new i = 10; i <= g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.28)
        }
    }
   
    if (g_iLevel[id] >= 40 && g_iLevel[id] <= 50)
    {
        for (new i = 1; i < 40; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.28)
        }
       
        for (new i = 20; i < g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.04)
        }
       
        for (new i = 40; i <= g_iLevel[id]; i++)
        {
            iMaxXP = floatround(float(iMaxXP) * 1.04)
        }
    }
   
    if (iCurrentMaxXP != iMaxXP)
    {
        g_iMaxXP[id] = iMaxXP
    }
}
 
public Show_Hud(taskid)
{  
    new iPlayer = ID_SHOWHUD
   
    if (!is_user_alive(iPlayer))
    {
        iPlayer = pev(iPlayer, pev_iuser2)
       
        if (!is_user_alive(iPlayer))
            return
    }
   
    if (get_pcvar_num(g_pCvarPercentageStyle) != 0)
    {
        if(iPlayer != ID_SHOWHUD)
        {
            set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[iPlayer], (float(g_iXP[iPlayer])/float(g_iMaxXP[iPlayer])) * 100.0)
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
        else
        {
            set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %0.2f %", g_iLevel[ID_SHOWHUD], (float(g_iXP[ID_SHOWHUD])/float(g_iMaxXP[ID_SHOWHUD])) * 100.0)
        }
    }
    else
    {
        if(iPlayer != ID_SHOWHUD)
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szSpecXP[15], szSpecMaxXP[15]
               
                AddCommas(g_iXP[iPlayer], szSpecXP, charsmax(szSpecXP))
                AddCommas(g_iMaxXP[iPlayer], szSpecMaxXP, charsmax(szSpecMaxXP))
               
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[iPlayer], szSpecXP, szSpecMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[iPlayer], g_iXP[iPlayer], g_iMaxXP[iPlayer])
            }  
        }
        else if (ze_is_user_zombie(iPlayer))
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szZombieXP[15], szZombieMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szZombieXP, charsmax(szZombieXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szZombieMaxXP, charsmax(szZombieMaxXP))
               
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szZombieXP, szZombieMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_ZOMBIE_R, HUD_STATS_ZOMBIE_G, HUD_STATS_ZOMBIE_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
        else
        {
            if (get_pcvar_num(g_pCvarAddCommas) == 1)
            {
                new szHumanXP[15], szHumanMaxXP[15]
               
                AddCommas(g_iXP[ID_SHOWHUD], szHumanXP, charsmax(szHumanXP))
                AddCommas(g_iMaxXP[ID_SHOWHUD], szHumanMaxXP, charsmax(szHumanMaxXP))
               
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %s/%s", g_iLevel[ID_SHOWHUD], szHumanXP, szHumanMaxXP)
            }
            else
            {
                set_hudmessage(HUD_STATS_HUMAN_R, HUD_STATS_HUMAN_G, HUD_STATS_HUMAN_B, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
                ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Level: %d | XP: %d/%d", g_iLevel[ID_SHOWHUD], g_iXP[ID_SHOWHUD], g_iMaxXP[ID_SHOWHUD])
            }
        }
    }
}
 
public ze_roundend(WinTeam)
{
    if (WinTeam == ZE_TEAM_HUMAN)
    {
        for(new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
        {
            if (!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
                continue
           
            g_iXP[id] += get_pcvar_num(g_pCvarEscapeSuccess)
            SaveData(id)
            Check_User_Level(id)
        }
    }
   
    remove_task(TASK_SHOWHUD)
}
 
public Check_User_Level(id)
{
    if(!is_user_connected(id))
        return
 
    if(g_iXP[id] >= g_iMaxXP[id])
    {
        if (get_pcvar_num(g_pCvarStartFromZero) == 1)
        {
            g_iXP[id] = 0
        }
       
        new szName[32]
        g_iLevel[id] ++
       
        if (g_iLevel[id] >= 0 && g_iLevel[id] < 10)
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.55)
        }
        else if (g_iLevel[id] >= 10 && g_iLevel[id] < 25)
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.28)
        }
		else if (g_iLevel[id] >= 25 && g_iLevel[id] < 40)
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.04)
        }
        else if (g_iLevel[id] >= 40 && g_iLevel[id] <= 50) // 50 is our max
        {
            g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * 1.02)
        }
       
        get_user_name(id, szName, charsmax(szName))
        ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
       
        SaveData(id)
       
        PlaySound(id, LEVELUP)
       
        if (get_pcvar_num(g_pCvarLevelEffects) != 0)
        {
            // Screen Fade
            message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
            write_short(4096*2)
            write_short(4096*5)
            write_short(0x0001)
            write_byte(random(256))
            write_byte(random(256))
            write_byte(random(256))
            write_byte(150)
            message_end()
           
            // Screen Shake
            message_begin(MSG_ONE, get_user_msgid("ScreenShake"), {0,0,0}, id)
            write_short(255<<14)
            write_short(10<<14)
            write_short(255<<14)
            message_end()
        }
    }
}
 
public ze_user_infected(iVictim, iInfector)
{
    if (iInfector == 0)
        return
   
    g_iXP[iInfector] += get_pcvar_num(g_pCvarZombieInfect)
    SaveData(iInfector)
    Check_User_Level(iInfector)
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Player Damage Himself
    if (iVictim == iAttacker || !is_user_alive(iVictim) || !is_user_alive(iAttacker) || ze_is_user_zombie(iAttacker) || !get_pcvar_num(g_pCvarEnableDamage))
        return HC_CONTINUE
   
    // Same Team?
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // Store Damage For every Player
    g_fDamage[iAttacker] += fDamage
   
    // Damage Calculator Equal or Higher than needed damage
    if (g_fDamage[iAttacker] >= get_pcvar_float(g_pCvarRequiredDamage))
    {
        // Give Player The Coins
        g_iXP[iAttacker] += get_pcvar_num(g_pCvarDamageAward)
        SaveData(iAttacker)
        Check_User_Level(iAttacker)
       
        // Rest The Damage Calculator
        g_fDamage[iAttacker] = 0.0
    }
    return HC_CONTINUE
}
 
public SaveData(id)
{
    new szAuthID[35], szName[32]
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
   
    // Set Him to max if he Higher than Max Value
    if(g_iLevel[id] > MAX_LEVEL)
    {
        g_iLevel[id] = MAX_LEVEL
    }
   
    if(g_iXP[id] > MAX_XP)
    {
        g_iXP[id] = MAX_XP
    }
   
    new szData[256]
    formatex(szData , charsmax(szData), "%i %i %i", g_iLevel[id], g_iXP[id], g_iMaxXP[id])
   
    // Open the Vaults
    g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
    g_iRanksVaultHandle = nvault_open(g_szRanksVault)
 
    // Saves His Data
    nvault_set(g_iLevelsVaultHandle, szAuthID, szData)
    nvault_set(g_iRanksVaultHandle, szAuthID, szName)
   
    // Close Vaults
    nvault_close(g_iLevelsVaultHandle)
    nvault_close(g_iRanksVaultHandle)
}
 
public LoadData(id)
{
    new szData[256], szAuthID[35], szName[32]
   
    get_user_authid(id, szAuthID, charsmax(szAuthID))
    get_user_name(id, szName, charsmax(szName))
   
    // Useless Variable
    new iTimestamp, iExists
   
    // Open the Vault
    g_iLevelsVaultHandle = nvault_open(g_szLevelsVault)
   
    iExists = nvault_lookup(g_iLevelsVaultHandle, szAuthID, szData, charsmax(szData), iTimestamp)
   
    // Close Vault
    nvault_close(g_iLevelsVaultHandle)
   
    if (!iExists)
    {
        g_iLevel[id] = 0
        g_iXP[id] = get_pcvar_num(g_pCvarStartXP)
        g_iMaxXP[id] = get_pcvar_num(g_pCvarMaxXPFirstLevel)
        SaveData(id)
    }
    else
    {
        new iLevel[32], iXP[32], iMaxLevel[32]
        parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
       
        g_iLevel[id] = str_to_num(iLevel)
        g_iXP[id] = str_to_num(iXP)
        g_iMaxXP[id] = str_to_num(iMaxLevel)
    }
}
 
public native_ze_get_user_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iXP[id]
}
 
public native_ze_set_user_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    DoubleHours()
   
    new iAddedAmount = amount - g_iXP[id]
   
    if (g_bIsDoubleHours)
    {
        g_iXP[id] = g_iXP[id] + (iAddedAmount * 2)
    }
    else
    {
        g_iXP[id] = amount
    }
   
    Check_User_Level(id)
    SaveData(id)
    return true;
}
 
public native_ze_get_user_level(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iLevel[id]
}
 
public native_ze_set_user_level(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_iLevel[id] = amount
   
    if (get_pcvar_num(g_pCvarStartFromZero) == 1)
    {
        g_iXP[id] = 0
    }
   
    SaveData(id)
   
    return true;
}
 
public native_ze_get_user_max_xp(id)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    return g_iMaxXP[id]
}
 
public native_ze_set_user_max_xp(id, amount)
{
    if(!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_iMaxXP[id] = amount
   
    SaveData(id)
   
    return true;
}
 
stock DoubleHours()
{
    new szTime[3], szDoubleHours[32], szDoubleHours_Start[32], szDoubleHours_End[32]
    get_time("%H", szTime, charsmax(szTime))
   
    get_pcvar_string(g_pCvarDoubleXP, szDoubleHours, charsmax(szDoubleHours))
   
    for (new ch = 0; ch <= charsmax(szDoubleHours); ch++)
    {
        if (szDoubleHours[ch] == '-')
            szDoubleHours[ch] = ' '
    }
   
    parse(szDoubleHours, szDoubleHours_Start, charsmax(szDoubleHours_Start), szDoubleHours_End, charsmax(szDoubleHours_End))
   
    new iTime, iDoubleHourStart, iDoubleHourEnd
   
    iTime = str_to_num(szTime)
    iDoubleHourStart = str_to_num(szDoubleHours_Start)
    iDoubleHourEnd = str_to_num(szDoubleHours_End)
   
    if(iDoubleHourEnd > iTime >= iDoubleHourStart)
    {
        g_bIsDoubleHours = true
    }
    else
    {
        g_bIsDoubleHours = false
    }
}
I would like this:

Code: Select all

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

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 599
Joined: 7 years ago
Contact:

#12

Post by czirimbolo » 6 years ago

Something is wrong, when I reach 10level, my XP is counting from 0, not from (for example) 12 000 exp. Is it right?
Image

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 0 guests