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