Page 1 of 2

Re: Best Defender

Posted: 08 Jun 2017, 17:47
by Raheem
Version 1.2 out.

Re: Best Defender

Posted: 07 Jul 2017, 06:00
by Raheem
New version released. Some important fixes inserted. Please if you run this plugin to update it.

Re: Best Defender

Posted: 15 Jul 2017, 08:22
by CaseyG
Raheeem wrote: 6 years ago New version released. Some important fixes inserted. Please if you run this plugin to update it.
Thanks for the plugin!

Re: Best Defender

Posted: 15 Jul 2017, 17:56
by Raheem
You are welcome.

Re: Best Defender

Posted: 15 Aug 2018, 10:46
by sPe3doN
Raheem can you remove escape coins & multi jump ? I want only xp

Re: Best Defender

Posted: 15 Aug 2018, 12:37
by czirimbolo
here are the cvars:

ze_best_def_give_xp "40" - you can change this value
ze_best_def_give_ec 0
ze_give_multijump 0

am I right?

Re: Best Defender

Posted: 15 Aug 2018, 21:27
by sPe3doN
czirimbolo wrote: 5 years ago here are the cvars:

ze_best_def_give_xp "40" - you can change this value
ze_best_def_give_ec 0
ze_give_multijump 0

am I right?
nah not like theat.. i want this plugin work with out multi jump plugin

Re: Best Defender

Posted: 15 Aug 2018, 23:34
by Raheem

Code: Select all

#include <zombie_escape>
#include <ze_levels>

// Variables
new Float:g_fDamage[33], g_iBestDefIndex

// Cvars
new cvar_show_chat_notice, cvar_give_xp, cvar_give_escape_coins, cvar_show_stats

public plugin_init()
{
	register_plugin("[ZE] Best Defender", "1.3", "Raheem")
	
	// Hook Chains
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
	RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
	
	// Cvars
	cvar_show_chat_notice = register_cvar("ze_best_def_chat_notice", "1")
	cvar_give_xp = register_cvar("ze_best_def_give_xp", "40")
	cvar_give_escape_coins = register_cvar("ze_best_def_give_ec", "20")
	cvar_show_stats = register_cvar("ze_show_best_def_stats", "1")
	
	// Commands
	register_clcmd("say /mydamage", "Cmd_BestDefenderStats")
}

public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
	if (!is_user_alive(iVictim) || !is_user_alive(iAttacker))
		return HC_CONTINUE
	
	g_fDamage[iAttacker] += fDamage
	return HC_CONTINUE
}

public ze_roundend()
{
	Get_Best_Defender()
}

public Cmd_BestDefenderStats(id)
{
	Get_Best_Defender()
	
	switch (get_pcvar_num(cvar_show_stats))
	{
		case 1:
		{
			if (id == g_iBestDefIndex)
			{
				ze_colored_print(id, "!tYou are now Best Defender !y[!g%d!y] !y:)", floatround(g_fDamage[g_iBestDefIndex]))
			}
			else
			{
				ze_colored_print(id, "!tYour Damage !g%d!y, !tYou need !g%d !tDamage To be Best Defender!y.", floatround(g_fDamage[id]), floatround(g_fDamage[g_iBestDefIndex] - g_fDamage[id]))
			}
		}
		case 2:
		{
			if (id == g_iBestDefIndex)
			{
				set_hudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
				show_hudmessage(id, "You are now Best Defender [%d] :)", floatround(g_fDamage[g_iBestDefIndex]))
			}
			else
			{
				set_hudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
				show_hudmessage(id, "Your Damage %d, You need %d Damage To be Best Defender.", floatround(g_fDamage[id]), floatround(g_fDamage[g_iBestDefIndex] - g_fDamage[id]))
			}
		}
		case 3:
		{
			if (id == g_iBestDefIndex)
			{
				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
				show_dhudmessage(id, "You are now Best Defender [%d] :)", floatround(g_fDamage[g_iBestDefIndex]))
			}
			else
			{
				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
				show_dhudmessage(id, "Your Damage %d, You need %d Damage To be Best Defender.", floatround(g_fDamage[id]), floatround(g_fDamage[g_iBestDefIndex] - g_fDamage[id]))
			}
		}
	}
}

public Fw_PlayerSpawn_Post(id)
{
	if (get_pcvar_num(cvar_show_chat_notice) != 0)
	{
		new szName[32]
		get_user_name(g_iBestDefIndex, szName, charsmax(szName))
		
		if (g_iBestDefIndex == 0 || g_fDamage[g_iBestDefIndex] == 0.0)
			return
		
		ze_colored_print(id, "!tBest Defender: !g%s. !tDamage: !g%i. !tAwards: !g%d XP, %d EC!y.", szName, floatround(g_fDamage[g_iBestDefIndex]), get_pcvar_num(cvar_give_xp), get_pcvar_num(cvar_give_escape_coins))
	}
	
	if (get_pcvar_num(cvar_give_xp) != 0 || get_pcvar_num(cvar_give_escape_coins) != 0)
	{
		if (g_iBestDefIndex == 0 || g_iBestDefIndex != id || g_fDamage[g_iBestDefIndex] == 0.0)
			return
		
		ze_set_escape_coins(g_iBestDefIndex, get_pcvar_num(cvar_give_escape_coins) + ze_get_escape_coins(g_iBestDefIndex))
		ze_set_user_xp(g_iBestDefIndex, get_pcvar_num(cvar_give_xp) + ze_get_user_xp(g_iBestDefIndex))
	}
}

public ze_game_started()
{
	set_task(5.0, "RestDamage")
}

public RestDamage()
{
	for (new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
	{
		g_fDamage[i] = 0.0
	}
}

public Get_Best_Defender()
{
	new Float:fTemp = 0.0
	
	for (new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
	{
		if (!is_user_connected(i))
			continue
		
		if (g_fDamage[i] > fTemp)
		{
			fTemp = g_fDamage[i]
			g_iBestDefIndex = i
		}
	}
}

Re: Best Defender

Posted: 19 Aug 2018, 18:01
by czirimbolo
L 08/19/2018 - 18:40:10: [ZE] Invalid Player id (6)
L 08/19/2018 - 18:40:10: [AMXX] Displaying debug trace (plugin "ze_best_defender.amxx", version "1.3")
L 08/19/2018 - 18:40:10: [AMXX] Run time error 10: native error (native "ze_get_escape_coins")
L 08/19/2018 - 18:40:10: [AMXX] [0] ze_best_defender.sma::Fw_PlayerSpawn_Post (line 123)

Re: Best Defender

Posted: 22 Aug 2018, 17:16
by czirimbolo
can you fix this? I have everyday this error couple of times

Re: Best Defender

Posted: 23 Aug 2018, 19:55
by Raheem
In our new ZE version we make that native can't set user coins if he is not connected, so always should check if user connected or not. This is just a log error.

Fix here:
  • Code: Select all

    #include <zombie_escape>
    #include <ze_multijump>
    #include <ze_levels>
    
    // Variables
    new Float:g_fDamage[33], g_iBestDefIndex
    
    // Cvars
    new cvar_give_multijump, cvar_show_chat_notice, cvar_give_xp, cvar_give_escape_coins, cvar_show_stats
    
    public plugin_init()
    {
    	register_plugin("[ZE] Best Defender", "1.3", "Raheem")
    	
    	// Hook Chains
    	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    	RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
    	
    	// Cvars
    	cvar_give_multijump = register_cvar("ze_give_multijump", "1")
    	cvar_show_chat_notice = register_cvar("ze_best_def_chat_notice", "1")
    	cvar_give_xp = register_cvar("ze_best_def_give_xp", "40")
    	cvar_give_escape_coins = register_cvar("ze_best_def_give_ec", "20")
    	cvar_show_stats = register_cvar("ze_show_best_def_stats", "1")
    	
    	// Commands
    	register_clcmd("say /mydamage", "Cmd_BestDefenderStats")
    }
    
    public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    {
    	if (!is_user_alive(iVictim) || !is_user_alive(iAttacker))
    		return HC_CONTINUE
    	
    	g_fDamage[iAttacker] += fDamage
    	return HC_CONTINUE
    }
    
    public ze_roundend()
    {
    	Get_Best_Defender()
    }
    
    public Cmd_BestDefenderStats(id)
    {
    	Get_Best_Defender()
    	
    	switch (get_pcvar_num(cvar_show_stats))
    	{
    		case 1:
    		{
    			if (id == g_iBestDefIndex)
    			{
    				ze_colored_print(id, "!tYou are now Best Defender !y[!g%d!y] !y:)", floatround(g_fDamage[g_iBestDefIndex]))
    			}
    			else
    			{
    				ze_colored_print(id, "!tYour Damage !g%d!y, !tYou need !g%d !tDamage To be Best Defender!y.", floatround(g_fDamage[id]), floatround(g_fDamage[g_iBestDefIndex] - g_fDamage[id]))
    			}
    		}
    		case 2:
    		{
    			if (id == g_iBestDefIndex)
    			{
    				set_hudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
    				show_hudmessage(id, "You are now Best Defender [%d] :)", floatround(g_fDamage[g_iBestDefIndex]))
    			}
    			else
    			{
    				set_hudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
    				show_hudmessage(id, "Your Damage %d, You need %d Damage To be Best Defender.", floatround(g_fDamage[id]), floatround(g_fDamage[g_iBestDefIndex] - g_fDamage[id]))
    			}
    		}
    		case 3:
    		{
    			if (id == g_iBestDefIndex)
    			{
    				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
    				show_dhudmessage(id, "You are now Best Defender [%d] :)", floatround(g_fDamage[g_iBestDefIndex]))
    			}
    			else
    			{
    				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.3, 2, 3.0, 5.0)
    				show_dhudmessage(id, "Your Damage %d, You need %d Damage To be Best Defender.", floatround(g_fDamage[id]), floatround(g_fDamage[g_iBestDefIndex] - g_fDamage[id]))
    			}
    		}
    	}
    }
    
    public Fw_PlayerSpawn_Post(id)
    {
    	if (get_pcvar_num(cvar_show_chat_notice) != 0)
    	{
    		new szName[32]
    		get_user_name(g_iBestDefIndex, szName, charsmax(szName))
    		
    		if (g_iBestDefIndex == 0 || g_fDamage[g_iBestDefIndex] == 0.0)
    			return
    		
    		if (get_pcvar_num(cvar_give_multijump) == 0)
    		{
    			ze_colored_print(id, "!tBest Defender: !g%s. !tDamage: !g%i. !tAwards: !g%d XP, %d EC!y.", szName, floatround(g_fDamage[g_iBestDefIndex]), get_pcvar_num(cvar_give_xp), get_pcvar_num(cvar_give_escape_coins))
    		}
    		else
    		{
    			ze_colored_print(id, "!tBest Defender: !g%s. !tDamage: !g%i. !tAwards: !g%d XP, %d EC, Multi-Jump!y.", szName, floatround(g_fDamage[g_iBestDefIndex]), get_pcvar_num(cvar_give_xp), get_pcvar_num(cvar_give_escape_coins))
    		}
    	}
    	
    	if (get_pcvar_num(cvar_give_multijump) != 0)
    	{
    		if (g_iBestDefIndex == 0 || g_iBestDefIndex != id || g_fDamage[g_iBestDefIndex] == 0.0)
    			return
    		
    		ze_give_user_multijump(g_iBestDefIndex)
    	}
    	
    	if (get_pcvar_num(cvar_give_xp) != 0 || get_pcvar_num(cvar_give_escape_coins) != 0)
    	{
    		if (g_iBestDefIndex == 0 || g_iBestDefIndex != id || g_fDamage[g_iBestDefIndex] == 0.0)
    			return
    		
    		if (!is_user_connected(g_iBestDefIndex))
    			return
    		
    		ze_set_escape_coins(g_iBestDefIndex, get_pcvar_num(cvar_give_escape_coins) + ze_get_escape_coins(g_iBestDefIndex))
    		ze_set_user_xp(g_iBestDefIndex, get_pcvar_num(cvar_give_xp) + ze_get_user_xp(g_iBestDefIndex))
    	}
    }
    
    public ze_game_started()
    {
    	set_task(5.0, "RestDamage")
    }
    
    public RestDamage()
    {
    	for (new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
    	{
    		g_fDamage[i] = 0.0
    	}
    }
    
    public Get_Best_Defender()
    {
    	new Float:fTemp = 0.0
    	
    	for (new i = 1; i <= get_member_game(m_nMaxPlayers); i++)
    	{
    		if (!is_user_connected(i))
    			continue
    		
    		if (g_fDamage[i] > fTemp)
    		{
    			fTemp = g_fDamage[i]
    			g_iBestDefIndex = i
    		}
    	}
    }

Re: Best Defender

Posted: 15 Sep 2018, 09:46
by Muhammet20
oh , raheem , good job bro , if i want anything i see you posted them , thanks you so much , but i have problem i want your help , in ze_no_block plugin when some one blocking , its not damaging , please help me and fast answer , thanks for best deffender plugin , bye

Re: Best Defender

Posted: 15 Sep 2018, 12:21
by Raheem
Hey bro, You need to post your problem here: viewtopic.php?f=15&t=1929

About No Block plugin, it will not work with latest ReHLDS. In latest ReHLDS they removed the ability of player to block moving entity. So no need to use no block plugin.

Re: Best Defender

Posted: 07 May 2019, 20:37
by neverminddw
Well there is a problem here. You forgot that with this code when u shot at your team mates (Human shot Human)
g_fDamage[iAttacker] += fDamage
So that means damage counts when you shot humans. Here's the fix.

Fix... if user iVictim's team == 2 (team CT) then return... damage wont count in that case.

Change:
  1. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
  2. {
  3.     if (!is_user_alive(iVictim) || !is_user_alive(iAttacker))
  4.         return HC_CONTINUE
  5.    
  6.     g_fDamage[iAttacker] += fDamage
  7.     return HC_CONTINUE
  8. }
To:
  1. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
  2. {
  3.     if (!is_user_alive(iVictim) || !is_user_alive(iAttacker) || get_user_team(iVictim) == 2)
  4.         return HC_CONTINUE
  5.    
  6.     g_fDamage[iAttacker] += fDamage
  7.     return HC_CONTINUE
  8. }

Re: Best Defender

Posted: 11 May 2019, 15:01
by Spir0x
Bro nevermind, what problem are you talking about ?
on my server this plugin working fine without any bug.

Re: Best Defender

Posted: 11 May 2019, 16:58
by neverminddw
Nope... if you shot humans damage counts the same way as shooting zombies.
That's why you must add this > get_user_team(iVictim) == 2)
then return
So damage will not be count if u shot humans.

Re: Best Defender

Posted: 12 May 2019, 10:32
by Raheem
neverminddw wrote: 5 years ago Nope... if you shot humans damage counts the same way as shooting zombies.
That's why you must add this > get_user_team(iVictim) == 2)
then return
So damage will not be count if u shot humans.
Oh, i don't know how i forget this. This bug not detected by me because i never used this plugin.

Thanks for fix, i'll update next version.