AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   message appears when the player is killed (https://forums.alliedmods.net/showthread.php?t=238545)

alfredo 04-12-2014 22:55

message appears when the player is killed
 
everything is there who can help me. if a player is killed will display a message !! :)

Flick3rR 04-13-2014 15:26

Re: message appears when the player is killed
 
What kind of message do you want? Chat message, or HUD? And, what to be the text of the message, maybe some colors?

Buckshot 04-13-2014 17:42

Re: message appears when the player is killed
 
PHP Code:

#include < amxmodx > 
#include < hamsandwich >

public plugin_init( ) {
    
register_plugin"Death Message""1.0""BuckShot" )
    
RegisterHamHam_Killed"player""Fwd_Ham_Killed_Post")
}

public 
Fwd_Ham_Killed_PostiVictimiAttacker ) {
    new 
szAttackername32 ]
    new 
szVictimname32 ]
    
get_user_nameiAttackerszAttackernamecharsmaxszAttackername ) )
    
get_user_nameiVictimszVictimnamecharsmaxszVictimname ) )
    
client_print0print_chat"%s was killed by %s"szVictimnameszAttackername )


Example. Will display a message saying "Player was killed by player" when a player dies.

swapped 04-14-2014 04:42

Re: message appears when the player is killed
 
Quote:

Originally Posted by Buckshot (Post 2124175)
PHP Code:

#include < amxmodx > 
#include < hamsandwich >

public plugin_init( ) {
    
register_plugin"Death Message""1.0""BuckShot" )
    
RegisterHamHam_Killed"player""Fwd_Ham_Killed_Post")
}

public 
Fwd_Ham_Killed_PostiVictimiAttacker ) {
    new 
szAttackername32 ]
    new 
szVictimname32 ]
    
get_user_nameiAttackerszAttackernamecharsmaxszAttackername ) )
    
get_user_nameiVictimszVictimnamecharsmaxszVictimname ) )
    
client_print0print_chat"%s was killed by %s"szVictimnameszAttackername )


Example. Will display a message saying "Player was killed by player" when a player dies.

why use hamsandwich when you can use DeatMsg directly ?

This code will show an meesage to a victim and one msg to the victim

if headshot the message of the victim will be :

Code:

You have been headshoted !
if is not headshot the meesage of the victim will be :

Code:

You have been normal killed (without headshot)
if is headshot the message of the attacker will be :

Code:

You give headshot to other player
if is not headshot the meesage of the attacker will be :

Code:

You normal kill the player (without headshot)
The source code :

PHP Code:

#include <amxmodx>

public plugin_init()
{
    
register_event("DeathMsg""death_msg_function""a");
}

public 
death_msg_function()
{
    new 
victim read_data);
    new 
attacker read_data);
    new 
hs read_data);

    if(
hs)
    {
        
client_print(victim print_chat"You have been headshoted !")

        
client_print(attacker print_chat"You give headshot to other player");
    }

    else
    {
        
client_print(victim print_chat"You have been normal killed (without headshot) ");

        
client_print(attacker print_chat"You normal kill the player (without headshot) ");    
    }



Flick3rR 04-14-2014 15:42

Re: message appears when the player is killed
 
And here I've added some more abbilities in your messages, swapped! I've got the victim and attacke names, also added some colors to the chat messages! Here you go:
PHP Code:

#include <amxmodx> 

public plugin_init() 

    
register_event("DeathMsg""death_msg_function""a"); 


public 
death_msg_function() 

    new 
victim read_data); 
    new 
attacker read_data); 
    new 
hs read_data); 
    new 
NameVictim[32]
    
get_user_name(victimNameVictim31)
    new 
NameAttacker[32]
    
get_user_name(attackerNameAttacker31)

    if(
hs
    { 
        
ColorMessage(victim"You have been headshoted by %s!"NameAttacker

        
ColorMessage(attacker"You have headshoted %s!"NameVictim); 
    } 

    else 
    { 
        
ColorMessage(victim,  "You have been normal killed by %s"NameAttacker); 

        
ColorMessage(attacker"You have normal killed %s"NameVictim);     
    } 
}  

/*You can add some colors to the chat messages
^4 - green color
^3 - team color
^1 - normal chat color
Example: ^3You have been ^4headshoted ^3by ^4%s!*/

stock ColorMessage(const id, const input[], any:...){
            new 
count 1players[32];
            static 
msg191 ];
            
vformat(msg190input3);
            if (
idplayers[0] = id; else get_players(players count "ch"); {
                for (new 
0counti++){
                    if (
is_user_connected(players[i])){
                        
message_begin(MSG_ONE_UNRELIABLE get_user_msgid("SayText"), _players[i]);
                        
write_byte(players[i]);
                        
write_string(msg);
                        
message_end();}}}
        } 


Buckshot 04-16-2014 21:51

Re: message appears when the player is killed
 
Quote:

Originally Posted by swapped (Post 2124320)
why use hamsandwich when you can use DeatMsg directly ?

Because deathmsg doesn't hook all ways of dying. It hooks when you get shot, but not when the bomb explodes for example.. Ham_Killed does. Even if it would i would still use ham_killed, since i don't gotta create 2 new separate variables for the victim & attacker indexes, i could just get them straight when declaring the function..

swapped 04-17-2014 01:12

Re: message appears when the player is killed
 
Quote:

Originally Posted by Buckshot (Post 2125621)
Because deathmsg doesn't hook all ways of dying. It hooks when you get shot, but not when the bomb explodes for example.. Ham_Killed does. Even if it would i would still use ham_killed, since i don't gotta create 2 new separate variables for the victim & attacker indexes, i could just get them straight when declaring the function..

Since now exist some cases when you are forced to use deathmsg and some cases when you Need to use ham_killed, my opinion is to use deathmsg insteand of including a new module, now all is about what you wanna do.


But i need you to ask "why?" to include a new module just for print a message in chat ? when we can use deathmsg.

HamletEagle 04-17-2014 06:57

Re: message appears when the player is killed
 
Ok,let's test:

DeathMsg:
Code:

date: Thu Apr 17 03:51:47 2014 map: fy_snow
type |                            name |      calls | time / min / max
-------------------------------------------------------------------
  n |                  register_event |          1 | 0.000003 / 0.000003 / 0.000003
  n |                        read_data |          3 | 0.000005 / 0.000002 / 0.000002
  n |                    client_print |          2 | 0.000006 / 0.000002 / 0.000004
  p |              death_msg_function |          1 | 0.000011 / 0.000011 / 0.000011
  p |                      plugin_init |          1 | 0.000003 / 0.000003 / 0.000003
0 natives, 0 public callbacks, 2 function calls were not executed.

Ham:

Code:

date: Thu Apr 17 03:53:58 2014 map: fy_snow
type |                            name |      calls | time / min / max
-------------------------------------------------------------------
  n |                  register_plugin |          1 | 0.000002 / 0.000002 / 0.000002
  n |                      RegisterHam |          1 | 0.000041 / 0.000041 / 0.000041
  n |                    get_user_name |          2 | 0.000004 / 0.000002 / 0.000002
  n |                    client_print |          1 | 0.000004 / 0.000004 / 0.000004
  p |              Fwd_Ham_Killed_Post |          1 | 0.000008 / 0.000008 / 0.000008
  p |                      plugin_init |          1 | 0.000005 / 0.000005 / 0.000005
6 natives, 1 public callbacks, 3 function calls were not executed.

So:

register_event | 1 | 0.000003 / 0.000003 / 0.000003
death_msg_function | 1 | 0.000011 / 0.000011 / 0.000011

RegisterHam | 1 | 0.000041 / 0.000041 / 0.000041
Fwd_Ham_Killed_Post | 1 | 0.000008 / 0.000008 / 0.000008

Both are called just 1 time. Ham Killed is faster( 0.000008 )..

So, Ham Killed is better than DeathMsg( in terms of duration of execution ).

YamiKaitou 04-17-2014 07:10

Re: message appears when the player is killed
 
Quote:

Originally Posted by HamletEagle (Post 2125753)
Both are called just 1 time. Ham Killed is faster( 0.000008 )..

So, Ham Killed is better than DeathMsg( in terms of duration of execution ).

You forgot the amount of time it took to register the Ham. DeathMsg is 0.000014 and HamKilled is 0.000049, DeathMsg is the clear winner. But, it all comes down to what you are trying to do

Buckshot 04-17-2014 13:12

Re: message appears when the player is killed
 
Quote:

Originally Posted by swapped (Post 2125649)
Since now exist some cases when you are forced to use deathmsg and some cases when you Need to use ham_killed, my opinion is to use deathmsg insteand of including a new module, now all is about what you wanna do.


But i need you to ask "why?" to include a new module just for print a message in chat ? when we can use deathmsg.

I just told you.............

This guy wants to learn how to display a message when a player is killed, he doesn't tell us WHEN he wants to detect when a player is killed, if he jumps from a cliff, gets shot or dies by the bombs explosion. Ham_Killed will detect all types of deaths. Deathmsg will not display when a player is killed by bomb explosion for example, and i think there are a few other types of deaths too that deathmsg can't find... Then why teach him deathmsg if he wants to check when a player is killed by a bomb explosion.. we don't know if he wants that or not? He did not specify a reason to when he wants to check a player death, and in what way... So i just learned him ham_killed. Your method will not work if that's what he wants. What is the point of even arguing? :S


All times are GMT -4. The time now is 17:52.

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