Plugin Available GIVE XP

Unpaid Requests, Public Plugins
czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 542
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

GIVE XP

#1

Post by czirimbolo » 1 Year Ago

Hello, can someone make a plugin with giving or taking XP ? Something like that viewtopic.php?f=15&t=54

The same plugin but instead of coins I would like to give XP with a command, only for admin
Image

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 283
Joined: 1 Year Ago
Location: Des Moines/USA
Donation: 1x donated in total €10.00
Has thanked: 6 times
Been thanked: 21 times
Age: 34
Contact:

#2

Post by Mark » 1 Year Ago

czirimbolo wrote:
1 Year Ago
Hello, can someone make a plugin with giving or taking XP ? Something like that viewtopic.php?f=15&t=54

The same plugin but instead of coins I would like to give XP with a command, only for admin
Try!
  1. #include <zombie_escape>
  2. #include <ze_levels>
  3.  
  4. #define ACCESS ADMIN_RCON
  5.  
  6. public plugin_init ()
  7. {
  8.     register_plugin("[ZE] Give XP", "1.0", "?")
  9.     register_clcmd("ze_givexp", "Cmd_GiveXP", ACCESS, "- ze_givexp <name> <amount>")
  10. }
  11.  
  12. public Cmd_GiveXP(id)
  13. {
  14.     if (!(get_user_flags(id) & ACCESS))
  15.     {
  16.         client_print(id, print_console, "You have no access to that command")
  17.         return PLUGIN_HANDLED
  18.     }
  19.    
  20.     new szName[32], szAmount[10]
  21.    
  22.     read_argv (1, szName, charsmax (szName))
  23.     read_argv (2, szAmount, charsmax (szAmount))
  24.    
  25.     new iTargetIndex = get_user_index(szName)
  26.    
  27.     if (!iTargetIndex)
  28.     {
  29.         client_print(id, print_console, "[ZE] Player not found!")
  30.         return PLUGIN_HANDLED
  31.     }
  32.    
  33.     new iXPAmout = str_to_num (szAmount)
  34.    
  35.     ze_set_user_xp(iTargetIndex, ze_get_user_xp(iTargetIndex) + iXPAmout)
  36.     return PLUGIN_HANDLED
  37. }

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 542
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

#3

Post by czirimbolo » 1 Year Ago

hmm, It worked but after quit the game or changing the map, I have my old value of XP. Can you fix it?
Image

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 283
Joined: 1 Year Ago
Location: Des Moines/USA
Donation: 1x donated in total €10.00
Has thanked: 6 times
Been thanked: 21 times
Age: 34
Contact:

#4

Post by Mark » 1 Year Ago

czirimbolo wrote:
1 Year Ago
hmm, It worked but after quit the game or changing the map, I have my old value of XP. Can you fix it?
Not sure why im running it on my server with no problem. You sure?

User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 626
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 49 times
Age: 19
Contact:

#5

Post by Mohamed Alaa » 1 Year Ago

czirimbolo wrote:
1 Year Ago
hmm, It worked but after quit the game or changing the map, I have my old value of XP. Can you fix it?
His code is correct.
Want your own mod edition? PM me.
Accepting web projects.
CS 1.6 hosting: powergamingtech.com

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:

#6

Post by Raheem » 1 Year Ago

Problem in level system, i'll make new native for saving to be used after setting player xp/level. Or i'll save on setting xp/level automatic.

Please post your level system code.
You don't know? Learn and you will know.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 542
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

#7

Post by czirimbolo » 1 Year Ago

here is, but with your double XP, I have not tested it yet

Code: Select all

#include <zombie_escape>

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

// 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_pCvarMaxLevelsIncrement, 
	g_pCvarMaxXPFirstLevel,
	g_pCvarPercentageStyle, 
	g_pCvarStartFromZero, 
	g_pCvarAddCommas, 
	g_pCvarLevelEffects,
	g_pCvarDoubleXP

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

public plugin_precache()
{
	precache_sound(LEVELUP)
}

public plugin_init()
{
	register_plugin("[ZE] Level-XP System", "1.8", "Raheem/JaCk")
	
	// Hook Chains
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
	
	// Cvars
	g_pCvarZombieInfect = register_cvar("ze_zombie_infect", "3")
	g_pCvarEscapeSuccess = register_cvar("ze_escape_success", "5")
	g_pCvarEnableDamage = register_cvar("ze_enable_dmg", "1")
	g_pCvarRequiredDamage = register_cvar("ze_required_dmg", "50.0")
	g_pCvarDamageAward = register_cvar("ze_dmg_award", "3")
	g_pCvarStartXP = register_cvar("ze_start_xp", "50")
	g_pCvarMaxLevelsIncrement = register_cvar("ze_maxlevels_increment", "2.0")
	g_pCvarMaxXPFirstLevel = register_cvar("ze_max_xp_first_level", "100")
	g_pCvarPercentageStyle = register_cvar("ze_enable_percentage_style", "1")
	g_pCvarStartFromZero = register_cvar("ze_new_level_zero_xp", "0")
	g_pCvarAddCommas = register_cvar("ze_add_commas_to_xp", "1")
	g_pCvarLevelEffects = register_cvar("ze_level_up_effects", "1")
	g_pCvarDoubleXP = register_cvar("ze_double_xp", "9-12")
	
	// Messages
	g_MsgSync = CreateHudSyncObj()
}

public client_putinserver(id)
{
	if(is_user_hltv(id) || is_user_bot(id))
		return
	
	// Just 1 second delay
	set_task(1.0, "DelayLoad", id)

	// Other tasks
	set_task(1.0, "Show_Hud", id+TASK_SHOWHUD, _, _, "b")
	set_task(0.1, "Check_MaxXP", id, _, _, "b")
}

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

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

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

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

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

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

	if(g_iXP[id] >= g_iMaxXP[id])
	{
		if (get_pcvar_num(g_pCvarStartFromZero) == 1)
		{
			g_iXP[id] = 0
		}
		
		new szName[32]
		g_iLevel[id] ++
		g_iMaxXP[id] = floatround(float(g_iMaxXP[id]) * get_pcvar_float(g_pCvarMaxLevelsIncrement))
		get_user_name(id, szName, charsmax(szName))
		ze_colored_print(0, "!g%s !tNow in Level %i!y!", szName, g_iLevel[id])
		
		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)
	return true;
}

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

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

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

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

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
	}
}
Image

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:

#8

Post by Raheem » 1 Year Ago

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

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 542
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

#9

Post by czirimbolo » 1 Year Ago

its working well Raheem, thanks!
Image

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 542
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

#10

Post by czirimbolo » 1 Year Ago

one more thing. I wanted to have atleast 15 level and added to myself max xp (500 000 like in code) BUT my level was 14 not 50 (in code max level is 50). Can you fix this? I cant gain golds weapons with that
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests