Damage & Death Effect

Unpaid Requests, Public Plugins
Post Reply
User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

Damage & Death Effect

#1

Post by ArminC » 6 years ago

Can someone make a plugin like this.. but to be stable.. more people said that this make the server to crash (unstable).

Code: Select all

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

//Define fade type
#define FFADE_OUT 0x0001
#define SPECMODE_ALIVE 0

//CVAR
new cvar_death, cvar_red, cvar_green, cvar_blue, cvar_damage

//MSG
new g_MsgScreenFade, g_MsgScreenShake

public plugin_init()
{
	// Register plugin call
	register_plugin("Damage & Death Effect", "1.3.3", "YKH =]")

	//CVAR
	cvar_death = register_cvar("amx_killed_effect_on", "1")
    	cvar_red  = register_cvar("death_color_r","0")
    	cvar_green  =  register_cvar("death_color_g","0")
    	cvar_blue =  register_cvar("death_color_b","0") 
    	cvar_damage =  register_cvar("damage_num","60")

	//Forward
	RegisterHam(Ham_Killed, "player", "fw_Killed")
	RegisterHam(Ham_Killed, "player", "Ham_Killed_player_Post", 1);
	RegisterHam(Ham_TakeDamage, "player", "fw_Damage")

	// Message IDs
	g_MsgScreenFade = get_user_msgid("ScreenFade")
	g_MsgScreenShake = get_user_msgid("ScreenShake")
}

public fw_Killed(victim)
{
	if(get_pcvar_num(cvar_death))
	{
		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, victim)
		write_short(12288)	// Duration
		write_short(12288)	// Hold time
		write_short(FFADE_OUT)	// Fade type
		write_byte (get_pcvar_num(cvar_red))		// Red
		write_byte (get_pcvar_num(cvar_green))		// Green
		write_byte (get_pcvar_num(cvar_blue))		// Blue
		write_byte (255)	// Alpha
		message_end()
	}
}
public Ham_Killed_player_Post(victim, attacker)
{
	set_pev(victim, pev_iuser1, SPECMODE_ALIVE);
		
	return HAM_IGNORED;
}

public fw_Damage(victim, inflictor, attacker, Float:damage, damage_type)
{
	if ((victim != attacker) && (damage > get_pcvar_num(cvar_damage)))
	{
		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenShake, _, victim)
		write_short( 1<<14 )
		write_short( 1<<14 )
		write_short( 1<<14 )
		message_end();

		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, victim)
		write_short( 1<<10 )
		write_short( 1<<10 )
		write_short( 1<<12 )
		write_byte( 250 )
		write_byte( 0 )
		write_byte( 0 )
		write_byte( 125 )
		message_end()
	}
}
(https://forums.alliedmods.net/showthread.php?t=86110)

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

#2

Post by Raheem » 6 years ago

Try first. Also i can't see problems in the code + Tested to work without any problem or crashes.
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#3

Post by ArminC » 6 years ago

User message, not that I (me) found a bug.

-- Anyway I will test it, if something is bad.. I will reply as usual =)

PS: I think that I will populate you forum only with my topics *wow* :lol:

EDIT: I saw that on your ZE version you have

Code: Select all

if ((victim != attacker) && (damage > get_pcvar_num(cvar_damage)) && (get_member(victim, m_iTeam) != get_member(attacker, m_iTeam)))
and the normal have:

Code: Select all

if ((victim != attacker) && (damage > get_pcvar_num(cvar_damage)))
if I add by myself it give: error 017: undefined symbol "get_member"

So how I could add to Normal/ZP?

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

#4

Post by Raheem » 6 years ago

TRY FIRST.
ArminC wrote: 6 years ago PS: I think that I will populate you forum only with my topics *wow* :lol:
LOL, It's popular for Zombie Escape ONLY, bro this because we only specialize in ZOMBIE ESCAPE because we like ZE VERY much.

if ((victim != attacker) && (damage > get_pcvar_num(cvar_damage))) Have no more optimization using ReAPI as simply victim is the victim index and it's and integer and same attacker is attacker index which integer if this integer NOT EQUAL this integer. This what victim != attacker means.
get_member(victim, m_iTeam) Means get user team, Which team he is now on.

So in brief:

victim != attacker means attacker not victim, If you attack yourself so in this case attacker = victim like if you hit yourself with your fire grenade.
get_member(victim, m_iTeam) != get_member(attacker, m_iTeam) means that the victim and attacker not in same team.

Also you will need to include reapi: #include <reapi> so you can use get_member() native.
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#5

Post by ArminC » 6 years ago

Thanks for the explanation :) I manage to fix it with the reapi (from your message), I didn't know that was requried lol :oops:

PS: By populate .. I didn't mean what you tought. Just I said that all of my topics will be everywhere you see with the eyes (a.k.a I have opened sooo many posts :D)

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

#6

Post by Raheem » 6 years ago

ArminC wrote: 6 years ago Thanks for the explanation :) I manage to fix it with the reapi (from your message), I didn't know that was requried lol :oops:
Don't be selfish and post the final code you made 😉
ArminC wrote: 6 years ago PS: By populate .. I didn't mean what you tought. Just I said that all of my topics will be everywhere you see with the eyes (a.k.a I have opened sooo many posts :D)
I see your posts will be more than mine 😂 😂 😂
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#7

Post by ArminC » 6 years ago

Lol.. I don't know if you were ironical with the code or not.. but here it is..

Code: Select all

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>

//Define fade type
#define FFADE_OUT 0x0001
#define SPECMODE_ALIVE 0

//CVAR
new cvar_death, cvar_red, cvar_green, cvar_blue, cvar_damage

//MSG
new g_MsgScreenFade, g_MsgScreenShake

public plugin_init()
{
	// Register plugin call
	register_plugin("Damage & Death Effect", "1.3.4", "YKH =]")

	//CVAR
	cvar_death = register_cvar("amx_killed_effect_on", "1")
	cvar_red = register_cvar("death_color_r","0")
	cvar_green = register_cvar("death_color_g","0")
	cvar_blue = register_cvar("death_color_b","0") 
	cvar_damage = register_cvar("damage_num","50")

	//Forward
	RegisterHam(Ham_Killed, "player", "fw_Killed")
	RegisterHam(Ham_Killed, "player", "Ham_Killed_player_Post", 1);
	RegisterHam(Ham_TakeDamage, "player", "fw_Damage")
	
	// Message IDs
	g_MsgScreenFade = get_user_msgid("ScreenFade")
	g_MsgScreenShake = get_user_msgid("ScreenShake")
}

public fw_Killed(victim)
{
	if(get_pcvar_num(cvar_death))
	{
		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, victim)
		write_short(12288)	// Duration
		write_short(12288)	// Hold time
		write_short(FFADE_OUT)	// Fade type
		write_byte (get_pcvar_num(cvar_red))		// Red
		write_byte (get_pcvar_num(cvar_green))		// Green
		write_byte (get_pcvar_num(cvar_blue))		// Blue
		write_byte (255)	// Alpha
		message_end()
	}
}
public Ham_Killed_player_Post(victim, attacker)
{
	set_pev(victim, pev_iuser1, SPECMODE_ALIVE);
		
	return HAM_IGNORED;
}

public fw_Damage(victim, inflictor, attacker, Float:damage, damage_type)
{
	if ((victim != attacker) && (damage > get_pcvar_num(cvar_damage)) && (get_member(victim, m_iTeam) != get_member(attacker, m_iTeam)))
	{
		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenShake, _, victim)
		write_short( 1<<14 )
		write_short( 1<<14 )
		write_short( 1<<14 )
		message_end();

		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, victim)
		write_short( 1<<10 )
		write_short( 1<<10 )
		write_short( 1<<12 )
		write_byte( 250 )
		write_byte( 0 )
		write_byte( 0 )
		write_byte( 125 )
		message_end()
	}
}
It's aproximatley the same as your ze (archive) code.. for normal .. I did fixed the identation loose.. let's post it for others anyway :idea:

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

#8

Post by Raheem » 6 years ago

Optimized:
  • Code: Select all

    #include <amxmodx>
    #include <reapi>
    
    //Define fade type
    #define FFADE_OUT 0x0001
    #define SPECMODE_ALIVE 0
    
    //CVAR
    new cvar_death, cvar_red, cvar_green, cvar_blue, cvar_damage
    
    //MSG
    new g_MsgScreenFade, g_MsgScreenShake
    
    public plugin_init()
    {
    	// Register plugin call
    	register_plugin("Damage & Death Effect", "1.3.4", "YKH =]")
    
    	//CVAR
    	cvar_death = register_cvar("amx_killed_effect_on", "1")
    	cvar_red = register_cvar("death_color_r","0")
    	cvar_green = register_cvar("death_color_g","0")
    	cvar_blue = register_cvar("death_color_b","0") 
    	cvar_damage = register_cvar("damage_num","50")
    
    	//Forward
    	RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
    	RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    	
    	// Message IDs
    	g_MsgScreenFade = get_user_msgid("ScreenFade")
    	g_MsgScreenShake = get_user_msgid("ScreenShake")
    }
    
    public Fw_PlayerKilled_Post(victim)
    {
    	if (!is_user_connected(victim))
    		return HC_CONTINUE
    	
    	if(get_pcvar_num(cvar_death))
    	{
    		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, victim)
    		write_short(12288)	// Duration
    		write_short(12288)	// Hold time
    		write_short(FFADE_OUT)	// Fade type
    		write_byte (get_pcvar_num(cvar_red))		// Red
    		write_byte (get_pcvar_num(cvar_green))		// Green
    		write_byte (get_pcvar_num(cvar_blue))		// Blue
    		write_byte (255)	// Alpha
    		message_end()
    	}
    	
    	set_entvar(victim, var_iuser1, SPECMODE_ALIVE)
    	return HC_CONTINUE;
    }
    
    public Fw_TakeDamage_Post(victim, inflictor, attacker, Float:damage, damage_type)
    {
    	if (!is_user_connected(victim) || !is_user_connected(attacker))
    		return
    	
    	if ((victim != attacker) && (damage > get_pcvar_num(cvar_damage)) && (get_member(victim, m_iTeam) != get_member(attacker, m_iTeam)))
    	{
    		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenShake, _, victim)
    		write_short( 1<<14 )
    		write_short( 1<<14 )
    		write_short( 1<<14 )
    		message_end();
    
    		message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, victim)
    		write_short( 1<<10 )
    		write_short( 1<<10 )
    		write_short( 1<<12 )
    		write_byte( 250 )
    		write_byte( 0 )
    		write_byte( 0 )
    		write_byte( 125 )
    		message_end()
    	}
    }
He who fails to plan is planning to fail

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 3 guests