Raised This Month: $ Target: $400
 0% 

need simplest code!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joelverghese
Member
Join Date: Oct 2011
Old 03-29-2014 , 00:46   need simplest code!
Reply With Quote #1

Hello,
I need a simplest code which plays a sound when a player is knifed !
joelverghese is offline
amx_tiger
Junior Member
Join Date: Aug 2012
Old 03-29-2014 , 03:42   Re: need simplest code!
Reply With Quote #2

Not tested, but it should work:

On death:
PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_plugin("Knifed Player""1.0""");
    
    
register_event("DeathMsg""hook_KnifeKill""a""4&kni");
}

public 
plugin_precache()
{
    
precache_sound("misc/my_sound.wav");
}

public 
hook_KnifeKill()
{
    new 
attacker read_data(1);
    new 
victim read_data(2);
    
    if(!
is_user_connected(attacker) || !is_user_connected(victim)) 
        return 
PLUGIN_HANDLED;        
    
    
client_cmd(attacker"spk misc/my_sound.wav");
    
client_cmd(victim"spk misc/my_sound.wav");
    
    return 
PLUGIN_CONTINUE;

On TakeDamage:

PHP Code:
#include <amxmodx>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("Knifed Player""1.0""");
    
    
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage"0);
}

public 
plugin_precache()
{
    
precache_sound("misc/my_sound.wav");
}

public 
hook_TakeDamage(idinflictorattackerdamagedamagebits

    if (!
is_user_alive(id) || !is_user_alive(attacker) || get_user_team(id) == get_user_team(attacker))
        return 
HAM_IGNORED;
        
    if ( 
get_user_weapon(attacker) == CSW_KNIFE
    {
        
client_cmd(id"spk misc/my_sound");
        
client_cmd(attacker"spk misc/my_sound");
    }
    
    return 
HAM_IGNORED


Last edited by amx_tiger; 03-29-2014 at 03:43.
amx_tiger is offline
souvikdas95
Senior Member
Join Date: Mar 2012
Old 03-29-2014 , 09:02   Re: need simplest code!
Reply With Quote #3

FYI, TakeDamage can be compared with HL1 event "Damage". They get executed as many times as you hit and damage a player. In other words, it's a massively overloaded function, hence not good for hooking simple events like Death. However, just in case, to provide an intuition, it's lately considered by some scripters that this event can be hooked to predict Pre-Death which is absolutely wrong. In practice, DeathMsg gets executed much before Damage during death. So, you can expect some accuracy in kill detection especially during RoundEnd which is another event to define Round Ending. So, if you ask me which event would be better, I would naturally go for "DeathMsg".

Last edited by souvikdas95; 03-29-2014 at 09:04.
souvikdas95 is offline
amx_tiger
Junior Member
Join Date: Aug 2012
Old 03-29-2014 , 09:30   Re: need simplest code!
Reply With Quote #4

Quote:
Originally Posted by souvikdas95 View Post
They get executed as many times as you hit and damage a player. In other words, it's a massively overloaded function, hence not good for hooking simple events like Death. However, just in case, to provide an intuition, it's lately considered by some scripters that this event can be hooked to predict Pre-Death which is absolutely wrong.
I know, but he did not mention when to play the sound(s), he just said "when players is knifed" which means 2 possibilities:
1. When the player take a damage from knife.
2. When the player is killed by a knife.
amx_tiger is offline
souvikdas95
Senior Member
Join Date: Mar 2012
Old 03-29-2014 , 10:24   Re: need simplest code!
Reply With Quote #5

okay, if you consider that way
souvikdas95 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode