AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   need simplest code! (https://forums.alliedmods.net/showthread.php?t=237749)

joelverghese 03-29-2014 00:46

need simplest code!
 
Hello,
I need a simplest code which plays a sound when a player is knifed !

amx_tiger 03-29-2014 03:42

Re: need simplest code!
 
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



souvikdas95 03-29-2014 09:02

Re: need simplest code!
 
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".

amx_tiger 03-29-2014 09:30

Re: need simplest code!
 
Quote:

Originally Posted by souvikdas95 (Post 2117419)
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.

souvikdas95 03-29-2014 10:24

Re: need simplest code!
 
okay, if you consider that way


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

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