[REQ] Any one help me to fix it

Coding Help/Re-API Supported
Post Reply
soumyadip77
Member
Member
India
Posts: 13
Joined: 6 years ago
Contact:

[REQ] Any one help me to fix it

#1

Post by soumyadip77 » 5 years ago

Any one please help me to fix this after map change all coins are going deleted so please fix it or tell how can i and save it will user use ID (STEAM ID)

Code: Select all

#include <zombie_escape>

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

// 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 /EC", "Coins_Info")
	register_clcmd("say_team /EC", "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
	}
	
	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
}

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

#2

Post by Raheem » 5 years ago

I made temporary fix long time ago for the losing coins issue you can find it here: https://github.com/raheem-cs/Zombie-Esc ... system.sma
He who fails to plan is planning to fail

soumyadip77
Member
Member
India
Posts: 13
Joined: 6 years ago
Contact:

#3

Post by soumyadip77 » 5 years ago

can i try to remake this ec ?? i want to know the logic which one you used me new in ZE but old in amxx

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

#4

Post by Raheem » 5 years ago

How coins system works?

Answer: I made array of 32 element to store the coins of each player g_iEscapeCoins[32] then on client_putinserver(id) i first LoadCoins(id) and check if this players steamid exist in nVault file or not if it's found so i load his escape coins and save it in g_iEscapeCoins[id]. And on client_disconnected(id) i save his coins, i save g_iEscapeCoins[id].

Where the problem? The problem is that sometimes for example player have 2000 coins and then g_iEscapeCoins[id] = 2000 and it should when you disconnect save this 2000 but on disconnect the 2000 convert to 0 and g_iEscapeCoins[id] = 0 not 2000 so the player coins reset. This is the problem. Why this array element changed to zero? I don't know i try to trace and debug the problem manytimes with many methods and all failed. When have more time may i think again, ask amxx developers maybe.

Temporary solution is on player disconnect i check if the coins became 0 for this player i don't save this time. This method works nice for some of our Mod users that's why it's employed till now. And if i do not find a final solution this maybe the final one in next releases.

Finally the problem not so much related to our Mod, It's something related to the amxx arrays and their initial values and when an element reset.. etc.

If you have idea why this happens you can help us to fix that.
He who fails to plan is planning to fail

soumyadip77
Member
Member
India
Posts: 13
Joined: 6 years ago
Contact:

#5

Post by soumyadip77 » 5 years ago

Ok

BTW when new version will come ??

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

#6

Post by Raheem » 5 years ago

When i finish my exams and jacks also, We will continue developing the new version.
He who fails to plan is planning to fail

soumyadip77
Member
Member
India
Posts: 13
Joined: 6 years ago
Contact:

#7

Post by soumyadip77 » 5 years ago

No update from last 1 year :(

soumyadip77
Member
Member
India
Posts: 13
Joined: 6 years ago
Contact:

#8

Post by soumyadip77 » 5 years ago

Can you add me in your team plzzzzzz

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

#9

Post by Night Fury » 5 years ago

soumyadip77 wrote: 5 years ago Can you add me in your team plzzzzzz
Raheem, answer.
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
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