Coins System Fix [Need Testers]

General Discussion
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:

Coins System Fix [Need Testers]

#1

Post by Raheem » 1 Year Ago

Hey ESCAPERS, Hope you are all fine.

I was thinking to track and fix the coins lose issue. Some information that not needed but i tell you: The coins problem is like, suddenly when plugin try to save players coins the plugin find the coins is zero although this player was having coins. So it's saved to zero so everythings gone. What cause it to be zeroed this what i was try to know. And i found nothing but finally read somethings that maybe this zeroing occur at end of plugin when map will be changed, server crash .. etc. If at this time a player disconnected his coins will be saved but to zero because at end of plugin all the array zeroed.

What important now for you is:
  • I'm not sure yet about this but i make the fix and need testers.
Note that i'll wait your feedback to tell me whether it's working or not, Also next version of our Mod is waiting your report. So please be sure to concentrate when you test like: Don't tell me it's not working and player steam id is which changed.. So try report detailed information.

For every case i make logs that will be logged in data folder (addons/amxmodx/data/coins.log), In file named coins.logs You will need also to attach this file when you report what happens.

Thanks for everyone will help, And remember this is for YOU so help us.

Plugin:

Code: Select all

#include <zombie_escape>

// Static (Change it if you need)
new const g_szVaultName[] = "Escape_Coins"

// Variables
new g_iMaxClients, g_iEscapeCoins[33], Float:g_flDamage[33], g_iVaultHandle

new bool:g_bMapChanging = true

// Cvars
new g_pCvarEscapeSuccess, g_pCvarHumanInfected, g_pCvarDamage, g_pCvarDamageCoins, g_pCvarStartCoins, g_pCvarMaxCoins,
g_pCvarEarnChatNotice

public plugin_natives()
{
	register_native("ze_get_escape_coins", "native_ze_get_escape_coins", 1)
	register_native("ze_set_escape_coins", "native_ze_set_escape_coins", 1)
}

public plugin_init()
{
	register_plugin("[ZE] Escape Coins System", ZE_VERSION, AUTHORS)
	
	// Hook Chains
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
	
	// Commands
	register_clcmd("say /EC", "Coins_Info")
	register_clcmd("say_team /EC", "Coins_Info")
	
	// Static Values
	g_iMaxClients = get_member_game(m_nMaxPlayers)
	
	// Cvars
	g_pCvarEscapeSuccess = register_cvar("ze_escape_success_coins", "15")
	g_pCvarHumanInfected = register_cvar("ze_human_infected_coins", "5")
	g_pCvarDamage = register_cvar("ze_damage_required", "300")
	g_pCvarDamageCoins = register_cvar("ze_damage_coins", "4")
	g_pCvarStartCoins = register_cvar("ze_start_coins", "50")
	g_pCvarMaxCoins = register_cvar("ze_max_coins", "200000")
	g_pCvarEarnChatNotice = register_cvar("ze_earn_chat_notice", "1")
	
	// Open the Vault
	g_iVaultHandle = nvault_open(g_szVaultName)
	
	if (g_iVaultHandle == INVALID_HANDLE)
	{
		set_fail_state("Error opening nVault")
	}
	
	// New Map Loaded
	g_bMapChanging = false
}

public Coins_Info(id)
{
	// Coins chat message
	ze_colored_print(id, "%L", LANG_PLAYER, "COINS_INFO", g_iEscapeCoins[id])
}

public client_putinserver(id) 
{
	// Player is bot or hltv? Skip him
	if (is_user_bot(id) || is_user_hltv(id) || !is_user_connected(id))
		return PLUGIN_CONTINUE
	
	LoadCoins(id)
	return PLUGIN_CONTINUE
}

public client_disconnected(id) 
{
	// Player is bot or hltv? Skip him
	if (is_user_bot(id) || is_user_hltv(id) || g_bMapChanging || !is_user_connected(id))
		return PLUGIN_CONTINUE
	
	// Save Coins
	SaveCoins(id)
	
	// Reset This Var
	g_iEscapeCoins[id] = 0
	return PLUGIN_CONTINUE
}

public plugin_end()
{
	// End of Map Stop saving in disconnect
	g_bMapChanging = true
	
	// Save before changing map
	for(new id = 1; id <= g_iMaxClients; id++)
	{
		if (!is_user_connected(id))
		{
			// Reset This Var
			g_iEscapeCoins[id] = 0
			continue
		}
		
		// Save coins for connected users
		SaveCoins(id)
	}
	
	// Close Vault
	nvault_close(g_iVaultHandle)
}

public ze_roundend(WinTeam)
{
	// Win team human?
	if (WinTeam == ZE_TEAM_HUMAN)
	{
		for(new id = 1; id <= g_iMaxClients; id++)
		{
			// Not alive or zombie? Skip it
			if (!is_user_alive(id) || ze_is_user_zombie(id))
				continue
			
			// Give coins reward to alive humans
			g_iEscapeCoins[id] += get_pcvar_num(g_pCvarEscapeSuccess)
			
			// Print chat notice
			if (get_pcvar_num(g_pCvarEarnChatNotice) != 0)
			{
				ze_colored_print(id, "%L", LANG_PLAYER, "ESCAPE_SUCCESS_COINS", get_pcvar_num(g_pCvarEscapeSuccess))
			}
		}
	}
}

public ze_user_infected(iVictim, iInfector)
{
	if (iInfector == 0) // Server ID
		return

	g_iEscapeCoins[iInfector] += get_pcvar_num(g_pCvarHumanInfected)
	
	if (get_pcvar_num(g_pCvarEarnChatNotice) != 0)
	{
		ze_colored_print(iInfector, "%L", LANG_PLAYER, "HUMAN_INFECTED_COINS", get_pcvar_num(g_pCvarHumanInfected))
	}
}

public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:flDamage, bitsDamageType)
{
	// Player Damage Himself? Skip
	if (iVictim == iAttacker)
		return HC_CONTINUE
	
	// Two Players From one Team? Skip
	if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
		return HC_CONTINUE
	
	// Victim or Attacker Not Alive? Skip
	if (!is_user_alive(iVictim) || !is_user_alive(iAttacker))
		return HC_CONTINUE
	
	// Attacker is Zombie? Skip
	if (get_member(iAttacker, m_iTeam) == TEAM_TERRORIST)
		return HC_CONTINUE
	
	// Store Damage For every Player
	g_flDamage[iAttacker] += flDamage
	
	// Damage Calculator Equal or Higher than needed damage
	if (g_flDamage[iAttacker] >= get_pcvar_float(g_pCvarDamage))
	{
		// Give Player The Coins
		g_iEscapeCoins[iAttacker] += get_pcvar_num(g_pCvarDamageCoins)
		
		// Rest The Damage Calculator
		g_flDamage[iAttacker] = 0.0
	}
	return HC_CONTINUE
}

LoadCoins(id)
{
	new szAuthID[35], iStartValue, szMap[100]
	iStartValue = get_pcvar_num(g_pCvarStartCoins)
	get_mapname(szMap, charsmax(szMap))
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	
	
	new iCoins = nvault_get(g_iVaultHandle , szAuthID)
	
	if(iCoins > 0)
	{
		g_iEscapeCoins[id] = iCoins
	}
	else
	{
		g_iEscapeCoins[id] = iStartValue
	}
}

SaveCoins(id)
{
	new szAuthID[35], iMaxValue
	iMaxValue = get_pcvar_num(g_pCvarMaxCoins)
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	
	// Set Him to max if he Higher than Max Value
	if(g_iEscapeCoins[id] > iMaxValue)
	{
		g_iEscapeCoins[id] = iMaxValue
	}
	
	if (g_iEscapeCoins[id] == 0)
	{
		log_to_file("addons/amxmodx/data/coins.log", "Zeroed For: %s", szAuthID)
	}
	
	new szData[16]
	
	num_to_str(g_iEscapeCoins[id], szData, charsmax(szData))
	
	// Save His SteamID, Escape Coins
	nvault_set(g_iVaultHandle, szAuthID, szData)
}

public native_ze_get_escape_coins(id)
{
	return g_iEscapeCoins[id]
}

public native_ze_set_escape_coins(id, iAmount)
{
	new szAuthID[35], szMap[100]
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	get_mapname(szMap, charsmax(szMap))
	g_iEscapeCoins[id] = iAmount
}
You don't know? Learn and you will know.

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 633
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 7 times
Age: 19
Contact:

#2

Post by Spir0x » 1 Year Ago

and what is this on your github ??

Code: Select all

#include <zombie_escape>

// Static (Change it if you need)
new const g_szVaultName[] = "Golds"

// Variables
new g_iMaxClients, g_iEscapeCoins[33], Float:g_fDamage[33], g_iVaultHandle

// Cvars
new Cvar_Escape_Success, Cvar_Human_Infected, Cvar_Damage, Cvar_Damage_Coins, Cvar_Start_Coins, Cvar_Max_Coins,
Cvar_Earn_ChatNotice

public plugin_natives()
{
	register_native("ze_get_escape_coins", "native_ze_get_escape_coins", 1)
	register_native("ze_set_escape_coins", "native_ze_set_escape_coins", 1)
}

public plugin_init()
{
	register_plugin("[ZE] Escape Coins System", ZE_VERSION, AUTHORS)
	
	// Hook Chains
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
	
	// Commands
	register_clcmd("say /golds", "Coins_Info")
	register_clcmd("say_team /golds", "Coins_Info")
	
	// Static Values
	g_iMaxClients = get_member_game(m_nMaxPlayers)
	
	// Cvars
	Cvar_Escape_Success = register_cvar("ze_escape_success_coins", "15")
	Cvar_Human_Infected = register_cvar("ze_human_infected_coins", "5")
	Cvar_Damage = register_cvar("ze_damage_required", "300")
	Cvar_Damage_Coins = register_cvar("ze_damage_coins", "4")
	Cvar_Start_Coins = register_cvar("ze_start_coins", "50")
	Cvar_Max_Coins = register_cvar("ze_max_coins", "200000")
	Cvar_Earn_ChatNotice = register_cvar("ze_earn_chat_notice", "1")
	
	// Open the Vault
	g_iVaultHandle = nvault_open(g_szVaultName)
	
	if (g_iVaultHandle == INVALID_HANDLE)
	{
		set_fail_state("Error opening nVault")
	}
}

public Coins_Info(id)
{
	ze_colored_print(id, "%L", LANG_PLAYER, "COINS_INFO", g_iEscapeCoins[id])
}

public client_putinserver(id) 
{
	if (is_user_bot(id) || is_user_hltv(id))
		return
	
	LoadCoins(id)
}

public client_disconnected(id) 
{
	if (is_user_bot(id) || is_user_hltv(id))
		return
	
	SaveCoins(id)
}

public plugin_end()
{
	nvault_close(g_iVaultHandle)
}

public ze_roundend(WinTeam)
{
	for(new id = 1; id <= g_iMaxClients; id++)
	{
		if (!is_user_alive(id) || ze_is_user_zombie(id))
			continue
		
		if (WinTeam == ZE_TEAM_HUMAN)
		{
			g_iEscapeCoins[id] += get_pcvar_num(Cvar_Escape_Success)
			
			if (get_pcvar_num(Cvar_Earn_ChatNotice) != 0)
			{
				ze_colored_print(id, "%L", LANG_PLAYER, "ESCAPE_SUCCESS_COINS", get_pcvar_num(Cvar_Escape_Success))
			}
		}
	}
}

public ze_user_infected(iVictim, iInfector)
{
	if (iInfector == 0) // Server ID
		return

	g_iEscapeCoins[iInfector] += get_pcvar_num(Cvar_Human_Infected)
	
	if (get_pcvar_num(Cvar_Earn_ChatNotice) != 0)
	{
		ze_colored_print(iInfector, "%L", LANG_PLAYER, "HUMAN_INFECTED_COINS", get_pcvar_num(Cvar_Human_Infected))
	}
}

public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
	// Player Damage Himself
	if (iVictim == iAttacker)
		return HC_CONTINUE
	
	// Two Players From one Team
	if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
		return HC_CONTINUE
	
	// iVictim or iAttacker Not Alive
	if (!is_user_alive(iVictim) || !is_user_alive(iAttacker))
		return HC_CONTINUE
	
	// Attacker is Zombie
	if (get_member(iAttacker, m_iTeam) == TEAM_TERRORIST)
		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_Damage))
	{
		// Give Player The Coins
		g_iEscapeCoins[iAttacker] += get_pcvar_num(Cvar_Damage_Coins)
		
		// Rest The Damage Calculator
		g_fDamage[iAttacker] = 0.0
	}
	return HC_CONTINUE
}

LoadCoins(id)
{
	new szAuthID[35], iStartValue
	iStartValue = get_pcvar_num(Cvar_Start_Coins)
	
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	
	new iCoins = nvault_get(g_iVaultHandle , szAuthID)
	
	if(iCoins != 0)
	{
		g_iEscapeCoins[id] = iCoins
	}
	else
	{
		g_iEscapeCoins[id] = iStartValue
	}
}

SaveCoins(id)
{
	new szAuthID[35], iMaxValue
	iMaxValue = get_pcvar_num(Cvar_Max_Coins)
	get_user_authid(id, szAuthID, charsmax(szAuthID))
	
	// Set Him to max if he Higher than Max Value
	if(g_iEscapeCoins[id] > iMaxValue)
	{
		g_iEscapeCoins[id] = iMaxValue
	}
	
	// Temporary solution to prevent saving if coins for player turned to 0
	if (g_iEscapeCoins[id] > 0)
	{
		new szData[16]
		num_to_str(g_iEscapeCoins[id], szData, charsmax(szData))
		
		// Save His SteamID, Escape Coins
		nvault_set(g_iVaultHandle, szAuthID, szData)
	}
}

public native_ze_get_escape_coins(id)
{
	return g_iEscapeCoins[id]
}

public native_ze_set_escape_coins(id, iAmount)
{
	g_iEscapeCoins[id] = iAmount
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1036\\ f0\\ fs16 \n\\ par }
*/
I trynna make money, not friends.

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:

#3

Post by Raheem » 1 Year Ago

No man, This is a new fixed one i coded today.
You don't know? Learn and you will know.

Rain1153
Senior Member
Senior Member
India
Posts: 278
Joined: 1 Year Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 19
Contact:

#4

Post by Rain1153 » 1 Year Ago

Can you release the new version for level system too which won't reset Damn i will be the first one to test that :)
LOL

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:

#5

Post by Raheem » 1 Year Ago

Test it for coins first, If it's working for sure i'll make it for LEVELS ASAP.
You don't know? Learn and you will know.

Rain1153
Senior Member
Senior Member
India
Posts: 278
Joined: 1 Year Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 19
Contact:

#6

Post by Rain1153 » 1 Year Ago

alright im testing now :D
LOL

Rain1153
Senior Member
Senior Member
India
Posts: 278
Joined: 1 Year Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 19
Contact:

#7

Post by Rain1153 » 1 Year Ago

It doesn't reset for me in my server lets see what others say. :D
LOL

johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 2 Years Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 22
Contact:

#8

Post by johnnysins2000 » 1 Year Ago

Rain1153 wrote:
1 Year Ago
It doesn't reset for me in my server lets see what others say. :D
Well I will test it

Although I am using his GitHub fix which he posted !

Use this temporarily fix for now.!


https://github.com/raheem-cs/Zombie-Esc ... b05e911ebe
Nobody Is That Busy If They Make Time :roll:

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 633
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 7 times
Age: 19
Contact:

#9

Post by Spir0x » 1 Year Ago

johnnysins2000 wrote:
1 Year Ago
Rain1153 wrote:
1 Year Ago
It doesn't reset for me in my server lets see what others say. :D
Well I will test it

Although I am using his GitHub fix which he posted !

Use this temporarily fix for now.!

i'm using this one :P


https://github.com/raheem-cs/Zombie-Esc ... b05e911ebe
I trynna make money, not friends.

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 633
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 7 times
Age: 19
Contact:

#10

Post by Spir0x » 1 Year Ago

guys for me the latest one on github is working fine i never lose coins. i think no need to this ?
I trynna make money, not friends.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests