Here is what you should know before using this:
-/rank commands do not work (I was too lazy to make them work so I just ignored it)
-Removed HUD for level because I made it with ze_hud.sma
-I made alot of edits, this is far (not faaar) away than the original source.
-This is the Level XP (150*(1+LEVEL*1.3) where LEVEL is current player's level.
Code: Select all
#include <zombie_escape>
// Defines
#define MAX_LEVEL 1000
#define MAX_XP 500000
#define LEVELUP "levelup_ZE/ze_levelup.wav"
// Constants
new g_szVaultLevel, g_szVaultXP
// Variables
new g_iLevel[33], g_iXP[33],
Float:g_fDamage[33],
g_MsgSync
// Cvars
new Cvar_ZM_Infect, Cvar_Escape_Success, Cvar_Enable_DMG, Cvar_Required_DMG,
Cvar_DMG_Award,
Cvar_Start_From_Zero, Cvar_Enable_Rank,
Cvar_Levels_To_Show, Cvar_Save_Time, Cvar_Level_Effects
//Level on Chat
new CT_Name[] = "Humans"
new T_Name[] = "Zombies"
new Spec_Name[] = "Spectators"
public plugin_natives()
{
register_native("ze_get_user_xp", "native_ze_get_user_xp", 1)
register_native("ze_get_user_maxxp", "native_ze_get_user_maxxp", 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)
}
public plugin_precache()
{
precache_sound(LEVELUP)
}
public plugin_init()
{
register_plugin("[ZE] Level-XP System", "1.5", "Raheem/JaCk")
// Hook Chains
RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
// Cvars
Cvar_ZM_Infect = register_cvar("ze_zombie_infect", "10")
Cvar_Escape_Success = register_cvar("ze_escape_success", "30")
Cvar_Enable_DMG = register_cvar("ze_enable_dmg", "1")
Cvar_Required_DMG = register_cvar("ze_required_dmg", "250.0")
Cvar_DMG_Award = register_cvar("ze_dmg_award", "5")
Cvar_Start_From_Zero = register_cvar("ze_new_level_zero_xp", "1")
//Cvar_Enable_Rank = register_cvar("ze_enable_rank_system", "1")
//Cvar_Levels_To_Show = register_cvar("ze_levels_rank_number", "10")
Cvar_Save_Time = register_cvar("ze_save_every", "10.0")
Cvar_Level_Effects = register_cvar("ze_level_up_effects", "1")
g_szVaultLevel = nvault_open("Level_Vault")
g_szVaultXP = nvault_open("XP_Vault")
// Commands
/*register_clcmd("say /lvlrank", "Cmd_Rank")
register_clcmd("say_team /lvlrank", "Cmd_Rank")
register_clcmd("say /myrank", "Cmd_Stats")
register_clcmd("say_team /myrank", "Cmd_Stats")*/
register_concmd("give_xppoint", "Cmd_Level", ADMIN_IMMUNITY)
//level on Chat
register_clcmd("say", "hook_say")
register_clcmd("say_team", "hook_say_team")
register_message(get_user_msgid("SayText"), "Blockdoublemessages")
}
public plugin_end() {
nvault_close(g_szVaultLevel)
nvault_close(g_szVaultXP)
}
public client_putinserver(id)
{
if(is_user_hltv(id) || is_user_bot(id))
return
LoadData(id)
set_task(get_pcvar_float(Cvar_Save_Time), "Save_Levels", id, _, _, "b")
}
public client_connected(id)
{
LoadData(id)
}
public client_authorized(id)
{
LoadData(id)
}
public client_disconnected(id)
{
if(is_user_hltv(id) || is_user_bot(id))
return
remove_task(id)
SaveData(id)
}
public Save_Levels(id)
{
SaveData(id)
}
public ze_roundend(WinTeam)
{
for(new id = 1; id <= 32; id++)
{
if(!is_user_alive(id) || get_member(id, m_iTeam) == TEAM_TERRORIST)
return
if (WinTeam == ZE_TEAM_HUMAN)
{
g_iXP[id] += get_pcvar_num(Cvar_Escape_Success)
Check_User_Level(id)
}
}
}
public Check_User_Level(id)
{
if(!is_user_connected(id))
return
if(g_iXP[id] >= floatround(150*(1+g_iLevel[id]*1.3)))
{
if (get_pcvar_num(Cvar_Start_From_Zero) == 1)
{
g_iXP[id] = 0
}
new szName[32]
g_iLevel[id] ++
get_user_name(id, szName, charsmax(szName))
ze_colored_print(0, "!g%s !yis now on !tLevel %i!y!", szName, g_iLevel[id])
PlaySound(0, LEVELUP)
if (get_pcvar_num(Cvar_Level_Effects) != 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(Cvar_ZM_Infect)
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(Cvar_Enable_DMG))
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(Cvar_Required_DMG))
{
// Give Player The Coins
g_iXP[iAttacker] += get_pcvar_num(Cvar_DMG_Award)
Check_User_Level(iAttacker)
// Rest The Damage Calculator
g_fDamage[iAttacker] = 0.0
}
return HC_CONTINUE
}
public Cmd_Level(id,level,cid)
{
if (!cmd_access(id,level,cid,2,false))
return PLUGIN_HANDLED
new Arg[32], user, temp
read_argv(1, Arg, 31)
user = cmd_target(id, Arg, CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF)
read_argv(2, Arg, 5)
temp = str_to_num(Arg)
if(temp >= 1000) temp = 1000
if(1<=user<=32) {
g_iXP[user] += temp
Check_User_Level(user)
get_user_name(user, Arg, charsmax(Arg))
ze_colored_print(0, "Player !t%s !yhas got !g%d XP Points!y.", Arg, temp)
}
else {
new iPlayers[32], iNum
get_players(iPlayers, iNum, "c")
for(new i = 0; i<iNum; i++) {
g_iXP[iPlayers[i]] += temp
Check_User_Level(iPlayers[i])
}
ze_colored_print(0, "!tEverybody !yhas got !g%d XP Points!y.", temp)
}
return PLUGIN_HANDLED
}
/*public LoadData(id)
{
new szData[256], szName[32]
get_user_name(id, szName, charsmax(szName))
if(fvault_get_data(g_szVaultName, szName, szData, charsmax(szData)))
{
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)
}
else
{
g_iLevel[id] = 0
g_iXP[id] = get_pcvar_num(Cvar_Start_XP)
}
}*/
public plugin_pause()
{
new iPlayers[32], iNum
get_players(iPlayers, iNum, "c")
for(new i; i<iNum; i++)
SaveData(iPlayers[i])
}
// Load System After Unpause The Plugin
public plugin_unpause()
{
new iPlayers[32], iNum
get_players(iPlayers, iNum, "c")
for(new i; i<iNum; i++)
LoadData(iPlayers[i])
}
public LoadData(id)
{
new szData[256], szDataXp[256], szName[32], key[64], key_xp[64]
get_user_name(id, szName, charsmax(szName))
format(key, 63, "%s-/", szName)
//format(szData, 255, "%i#", g_level[id])
format(key_xp, 63, "%s-/", szName)
//format(szDataXp, 255, "%i#", level_exp[id])
nvault_get(g_szVaultLevel, key, szData, 255)
nvault_get(g_szVaultXP, key_xp, szDataXp, 255)
replace_all(szData, 255, "#", " ")
replace_all(szDataXp, 255, "#", " ")
new givelevel[32], give_exp[32]
parse(szData, givelevel, 31)
parse(szDataXp, give_exp, 31)
g_iLevel[id] = str_to_num(givelevel)
g_iXP[id] = str_to_num(give_exp)
return PLUGIN_CONTINUE
}
/*public SaveData(id)
{
new szAuthID[32]
get_user_name(id, szAuthID, charsmax(szAuthID))
// 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 , 255, "%i %i", g_iLevel[id], g_iXP[id])
// Saves His Data
fvault_set_data(g_szVaultName, szAuthID, szData)
}*/
public SaveData(id)
{
new szAuthID[32]
get_user_name(id, szAuthID, charsmax(szAuthID))
new szData[256], szDataXp[256], key[64], key_xp[64]
format(key, 63, "%s-/", szAuthID)
format(szData, 255, "%i#", g_iLevel[id])
format(key_xp, 63, "%s-/", szAuthID)
format(szDataXp, 255, "%i#", g_iXP[id])
nvault_set(g_szVaultLevel, key, szData)
nvault_set(g_szVaultXP, key_xp, szDataXp)
return PLUGIN_CONTINUE;
}
// Rank System Writen by Raheem
/*public Cmd_Rank(id)
{
if (get_pcvar_num(Cvar_Enable_Rank) == 0)
return
// Max elements in Levels.txt and Rank.txt (They are same)
new iTotal = fvault_size(g_szVaultName)
new szKey[32], // To hold SteamID from Levels.txt
szData[64], // To hold Levels, XP from Levels.txt
szKeyRank[32], // To hold SteamID from Ranks.txt
szDataRank[64] // To hold Names from Ranks.txt
new Array:iLevels, // Dynamic Array to hold all Levels (szData) from Levels.txt
Array:iXPs, // Dynamic Array to hold all XPs (szData) from Levels.txt
Array:szLevelsSteamIDs, // Dynamic Array to hold all SteamIDs (szKey) from Levels.txt
Array:szRankSteamIDs // Dynamic Array to hold all SteamIDs (szKeyRank) from Ranks.txt
// Create Our Arrays with proper lengths [As we don't know iTotal Length so we use Dynamic]
iLevels = ArrayCreate(32)
iXPs = ArrayCreate(32)
szLevelsSteamIDs = ArrayCreate(32)
szRankSteamIDs = ArrayCreate(32)
// Some integer counters to be used down
new i, j, iIndex, iShowCount = 0
// Format motd Header
new szMotd[1501], iLen
iLen = formatex(szMotd, charsmax(szMotd), "<body bgcolor=#000000><font color=#CBA50B><h3><pre>")
iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3s %-32s %-11s %s^n", "#", "Name", "# Level", "# XP")
// Loop through all elements in our Levels.txt and Rank.txt
for(i = 0; i < iTotal; i++)
{
// Get SteamID from Levels.txt and save to szKey
fvault_get_keyname(g_szVaultName, i, szKey, charsmax(szKey))
// Get Levels, XP for every SteamID from Levels.txt and save to szData
fvault_get_data(g_szVaultName, szKey, szData, charsmax(szData))
// Get SteamID from Ranks.txt and save to szKeyRank
fvault_get_keyname(g_szRankVaultName, i, szKeyRank, charsmax(szKeyRank))
// Get Name from Ranks.txt and save to szDataRank
fvault_get_data(g_szRankVaultName, szKeyRank, szDataRank, charsmax(szDataRank))
// Spliting szData to Level and XP and Save them
new iLevel[32], iXP[32], iMaxLevel[32]
parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
// Save our Level to Dynamic Array
ArrayPushCell(iLevels, str_to_num(iLevel))
// Save our XP to Dynamic Array
ArrayPushCell(iXPs, str_to_num(iXP))
// Save SteamID comes from Levels.txt to our Dynamic Array
ArrayPushString(szLevelsSteamIDs, szKey)
// Save SteamID from Rank.txt to our Dynamic Array
ArrayPushString(szRankSteamIDs, szKeyRank)
}
// Loop through all elements in our Levels Dynamic Array [To Rank like 5, 4, 2, 0]
for (i = 0; i < ArraySize(iLevels); i++)
{
// Every time to compare i with element down him it's i+1
for (j = i + 1; j < ArraySize(iLevels); j++)
{
// The down element is higher than upper one?
if (ArrayGetCell(iLevels, j) > ArrayGetCell(iLevels, i))
{
// If yes change the two elements position (j to come upper and i to be down)
ArraySwap(iLevels, i, j);
ArraySwap(szLevelsSteamIDs, i, j); // Change also for steam so we get ranked steam ids
ArraySwap(iXPs, i, j); // Rank also XP
}
else if (ArrayGetCell(iLevels, j) == ArrayGetCell(iLevels, i)) // They are Equal?
{
// Rank now Depend on Who have much XP
if (ArrayGetCell(iXPs, j) > ArrayGetCell(iXPs, i))
{
ArraySwap(iLevels, i, j);
ArraySwap(szLevelsSteamIDs, i, j);
ArraySwap(iXPs, i, j);
}
}
}
}
// Loop through all elements in our texts
for(i = 0; i < iTotal; i++)
{
new szString[35];
ArrayGetString(szLevelsSteamIDs, i, szString, charsmax(szString))
// Another loop to get same SteamID from Rank.txt like one we get in szString [So we can get player name based on his steamid even if he was offline we already saved his name]
for (j = 0; j < iTotal; j++)
{
// Save SteamID from Ranks.txt to szTemp
new szTemp[35];
ArrayGetString(szRankSteamIDs, j, szTemp, charsmax(szTemp))
// Compare if the two steamids same save this index
if (equal(szString, szTemp))
{
iIndex = j
break
}
}
// Check how much values we formated if more than our cvar break the loop
if (iShowCount >= get_pcvar_num(Cvar_Levels_To_Show))
break
new szNameF[32]
ArrayGetString(szRankSteamIDs, iIndex, szNameF, charsmax(szNameF))
// Add player information to our Motd
iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3d %-32s %-11d %d^n", i + 1, szNameF, ArrayGetCell(iLevels, i), ArrayGetCell(iXPs, i))
// Increase the counter by 1
iShowCount++
}
// Format end of motd
iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</body></font></h3></pre>")
// Finally Show motd to the player
show_motd(id, szMotd, "Levels Rank")
// Free our memory
ArrayDestroy(iLevels)
ArrayDestroy(iXPs)
ArrayDestroy(szLevelsSteamIDs)
ArrayDestroy(szRankSteamIDs)
}
public Cmd_Stats(id)
{
// Max elements in Levels.txt and Rank.txt (They are same)
new iTotal = fvault_size(g_szVaultName)
new szKey[32], // To hold SteamID from Levels.txt
szData[64] // To hold Levels, XP from Levels.txt
new Array:iLevels, // Dynamic Array to hold all Levels (szData) from Levels.txt
Array:iXPs // Dynamic Array to hold all XPs (szData) from Levels.txt
// Create Our Arrays with proper lengths [As we don't iTotal Length so we use Dynamic]
iLevels = ArrayCreate(32)
iXPs = ArrayCreate(32)
// Some integer counters to be used down
new i, j
// Loop through all elements in our Levels.txt and Rank.txt
for(i = 0; i < iTotal; i++)
{
// Get SteamID from Levels.txt and save to szKey
fvault_get_keyname(g_szVaultName, i, szKey, charsmax(szKey))
// Get Levels, XP for every SteamID from Levels.txt and save to szData
fvault_get_data(g_szVaultName, szKey, szData, charsmax(szData))
// Spliting szData to Level and XP and Save them
new iLevel[32], iXP[32], iMaxLevel[32]
parse(szData, iLevel, 31, iXP, 31, iMaxLevel, 31)
// Save our Level to Dynamic Array
ArrayPushCell(iLevels, str_to_num(iLevel))
// Save our XP to Dynamic Array
ArrayPushCell(iXPs, str_to_num(iXP))
}
// Loop through all elements in our Levels Dynamic Array [To Rank like 5, 4, 2, 0]
for (i = 0; i < ArraySize(iLevels); i++)
{
// Every time to compare i with element down him it's i+1
for (j = i + 1; j < ArraySize(iLevels); j++)
{
// The down element is higher than upper one?
if (ArrayGetCell(iLevels, j) > ArrayGetCell(iLevels, i))
{
// If yes change the two elements position (j to come upper and i to be down)
ArraySwap(iLevels, i, j);
ArraySwap(iXPs, i, j); // Rank also XP
}
else if (ArrayGetCell(iLevels, j) == ArrayGetCell(iLevels, i)) // They are Equal?
{
// Rank now Depend on Who have much XP
if (ArrayGetCell(iXPs, j) > ArrayGetCell(iXPs, i))
{
ArraySwap(iLevels, i, j);
ArraySwap(iXPs, i, j);
}
}
}
}
new iIndex = 0;
for (i = 0; i < ArraySize(iLevels); i++)
{
if (ArrayGetCell(iLevels, i) == g_iLevel[id] && ArrayGetCell(iXPs, i) == g_iXP[id])
{
iIndex = i
break;
}
}
ze_colored_print(id, "!tYour rank is !g%i !tof !g%i!y.", iIndex + 1, iTotal - 1)
// Free our memory
ArrayDestroy(iLevels)
ArrayDestroy(iXPs)
}*/
public native_ze_get_user_xp(id)
{
if(!is_user_connected(id))
{
log_amx("[ZE] Invalid Player.")
}
return g_iXP[id]
}
public native_ze_set_user_xp(id, amount)
{
if(!is_user_connected(id))
{
log_amx("[ZE] Invalid Player.")
}
g_iXP[id] = amount
Check_User_Level(id)
}
public native_ze_get_user_level(id)
{
if(!is_user_connected(id))
{
log_amx("[ZE] Invalid Player.")
}
return g_iLevel[id]
}
public native_ze_set_user_level(id, amount)
{
if(!is_user_connected(id))
{
log_amx("[ZE] Invalid Player.")
}
g_iLevel[id] = amount
if (get_pcvar_num(Cvar_Start_From_Zero) == 1)
{
g_iXP[id] = 0
}
}
public native_ze_get_user_maxxp(id)
{
if(!is_user_connected(id))
{
log_amx("[ZE] Invalid Player.")
}
return floatround(150*(1+g_iLevel[id]*1.3))
}
public hook_say(id)
{
new szName[32], szMessage[200]
get_user_name(id, szName, charsmax(szName))
read_args(szMessage, charsmax(szMessage))
remove_quotes(szMessage)
if(!is_valid_msg(szMessage) || !is_user_connected(id))
return PLUGIN_CONTINUE
if(ze_is_user_zombie(id))
{
format(szMessage, charsmax(szMessage), "^1%s%s [^4Level %i^1] ^3%s ^1:%s %s", is_user_alive(id) ? "" : "(DEAD) ", (get_user_flags(id) & ADMIN_KICK) ? "[^4ADMIN^1]" : "", g_iLevel[id], szName, (get_user_flags(id) & ADMIN_KICK) ? "^4" : "", szMessage)
}
else if(get_member(id, m_iTeam) == TEAM_SPECTATOR)
{
format(szMessage, charsmax(szMessage), "^1[^4Spec^1] [^4Level %i^1] ^3%s ^1:%s %s", g_iLevel[id], szName, (get_user_flags(id) & ADMIN_KICK) ? "^4" : "", szMessage)
}
else
{
format(szMessage, charsmax(szMessage), "^1%s%s [^4Level %i^1] ^3%s ^1:%s %s", is_user_alive(id) ? "" : "(DEAD) ", (get_user_flags(id) & ADMIN_KICK) ? "[^4ADMIN^1]" : "", g_iLevel[id], szName, (get_user_flags(id) & ADMIN_KICK) ? "^4" : "", szMessage)
}
for(new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
{
if(!is_user_connected(i))
continue
message_begin(MSG_ONE, get_user_msgid("SayText"), {0, 0, 0}, i)
write_byte(id)
write_string(szMessage)
message_end()
}
return PLUGIN_CONTINUE
}
public hook_say_team(id)
{
if(!is_user_connected(id))
return PLUGIN_CONTINUE
new szName[32], szMessage[200]
get_user_name(id, szName, charsmax(szName))
read_args(szMessage, charsmax(szMessage))
remove_quotes(szMessage)
if(!is_valid_msg(szMessage))
return PLUGIN_CONTINUE
if(is_user_alive(id))
{
format(szMessage, charsmax(szMessage), "^1(^3%s^1) [^4Level %i^1] ^3%s ^1:%s %s", get_member(id, m_iTeam) == TEAM_CT ? CT_Name : T_Name, g_iLevel[id], szName, (get_user_flags(id) & ADMIN_KICK) ? "^4" : "", szMessage)
}
else
{
format(szMessage, charsmax(szMessage), "^1(^3%s^1) [^4Dead^1] [^4Level %i^1] ^3%s ^1:%s %s", Spec_Name, g_iLevel[id], szName, (get_user_flags(id) & ADMIN_KICK) ? "^4" : "", szMessage)
}
for(new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
{
if(!is_user_connected(i) || get_user_team(i) != get_user_team(id))
continue
message_begin(MSG_ONE, get_user_msgid("SayText"), {0, 0, 0}, i)
write_byte(id)
write_string(szMessage)
message_end()
}
return PLUGIN_CONTINUE
}
bool:is_valid_msg(const szMessage[])
{
if(szMessage[0] == '@' || !strlen(szMessage) || szMessage[0] == '/' || szMessage[0] == '#')
return false
if(containi(szMessage, "270") != -1 || containi(szMessage, "server") != -1 || containi(szMessage, "free") != -1)
return false
return true
}
public Blockdoublemessages()
{
return PLUGIN_HANDLED
}