Sorry I didn't read that.
Well since killer is an argument that is sent through the message "DeathMsg" you cannot use it like before.
The best way would be to loop through players and check which are connected/alive (whichever you want) and then display it to everyone. You only have to loop the actual show_hudmessage(), not set_hudmessage.
Here are some examples, they all work:
Code:
#include <amxmodx>
public plugin_init() {
register_plugin("Test Plugin ", "", "");
}
public showKillstreak(id)
{
new iPlayers
new Players[32]
get_players(Players, iPlayers, "ach")
/*
* This will retreive player ID's of the players that are matching the condition of "flags"
* In this case "ac" means we return people who are:
* "a" Not dead (One could say alive, dead people doesn't have a killstreak)
* "c" Not a bot (They can't see messages)
* "h" Not HLTV (They aren't playing, they don't have a killstreak)
*
* iPlayers is a return that will be set to the number of players inside of "Players" array.
*
* Explenation of parameter 3, flags:
* "a" - don't collect dead players.
* "b" - don't collect alive players.
* "c" - skip bots.
* "d" - skip real players.
* "e" - match with team.
* "f" - match with part of name.
* "g" - ignore case sensitivity.
* "h" - skip HLTV.
*/
// This line can stay outside of the loop, the arguments will get saved for all players
set_hudmessage(0, 95, 245, 0.0, 0.0, 0, 0.0, 1.1, 0.1, 0.5, 15)
/* This creates a loop. The loop will start with 0 since that's what we set i to.
* It will then repeat what's inside of the loop until i reaches iPlayers.
* It will add 1 to i after every loop.
* If we set it to ++i it will be added before the loop is started but that destroys the point of this.
*
* Inside this Players[] array all the relevant indexes of players are stored.
* It then get's the first relevant index with Players[i] (Players[0] in the first loop)
* That index will then be used inside g_Kills.
*
* Let's say that the first loop has an i value of 0, which it always is.
* Players[i] (Players[0]) can for example hold a player ID of 4 because that is the first ID that matches our flags ("ach").
* So basically it calls the variable g_Kills[4]
*/
for ( new i = 0 ; i <= iPlayers ; i++ )
show_hudmessage(id, "Killstreak: %i", g_Kills[Players[i]])
}
Here is another way where we don't use get_players() and instead make our own filter.
The outcome is the same, it's just another way of doing it.
Code:
#include <amxmodx>
#include <fakemeta>
// One of these methods require global_get() which is a function of the fakemeta library.
// So we have to include that before we can use the functions, otherwise the script won't compile.
new g_MaxClients
public plugin_init() {
register_plugin("Test Plugin ", "", "");
g_MaxClients = global_get(glb_maxClients);
/* This is set to max players, this makes sure we don't do any work where it's not needed.
* It basically replaces iPlayers in the previous example.
*/
}
public showKillstreak(id)
{
// This line can stay outside of the loop, the arguments will get saved for all players
set_hudmessage(0, 95, 245, 0.0, 0.0, 0, 0.0, 1.1, 0.1, 0.5, 15)
/* Here the maxclients are set to 32.
* This is generally seen as bad coding habits since some servers have, for example, 24 players.
* We could avoid this extra work of looping through 8 ID's that will never exist in next example
*/
for ( new i = 0 ; i <= 32 ; i++ ) {
if ( is_user_connected(i) && is_user_alive(i) && ! is_user_bot(i) && ! is_user_hltv(i) )
show_hudmessage(id, "Killstreak: %i", g_Kills[i])
}
/* In this example we take use of global_get(glb_MaxClients) and store that value in a variable.
* This means that if the maxclients are set to, for example, 24 the variable g_MaxClients would be set to that.
* This would stop us from looping through those ID's that will never exist.
*/
for ( new i = 0 ; i < g_MaxClients ; i++ ) {
if ( is_user_connected(i) && is_user_alive(i) && ! is_user_bot(i) && ! is_user_hltv(i) )
show_hudmessage(id, "Killstreak: %i", g_Kills[i])
}
}
I suggest you longen the time of the HudMessage and shorten the set_task() interval. You could add a second HudMessage to update every time the kills get updated instead. If the channel is the same on both messages the new one will overwrite the old one:
Code:
#include <amxmodx>
#include <fun>
#define PLUGIN "MISC Killstreak"
#define VERSION "1.0"
#define AUTHOR "subs"
new g_MsgScoreInfo
new g_Kills[33]
new g_MaxClients
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("DeathMsg", "msgDeath", "a", "1>0")
set_task(10.0, "showKillstreak", 0, "", 0, "b")
g_MsgScoreInfo = get_user_msgid("ScoreInfo")
g_MaxClients = global_get(glb_maxClients);
}
public msgDeath(id)
{
new killer = read_data(1)
new victim = read_data(2)
if ( is_user_connected(victim) )
g_Kills[victim] = 0
if ( is_user_connected(killer) )
{
g_Kills[killer]++ // Start killstreak counter
set_user_frags(killer, get_user_frags(killer) + clamp(g_Kills[killer] / 5, 0, 2))
message_begin(MSG_ALL, g_MsgScoreInfo) // Add points to scoreboard
write_byte(killer)
write_short(get_user_frags(killer))
write_short(get_user_deaths(killer))
write_short(0)
write_short(get_user_team(killer))
message_end()
}
// Whenever there's a change it will update immediately instead of waiting for the next loop.
// There are only 4 channels of hudmessages and -1 which is auto (1-4). I changed to channel 2.
// If it conflicts with another message, try another channel by changing the last parameter.
// Remember to change it in showKillstreak() aswell.
set_hudmessage(0, 95, 245, 0.0, 0.0, 0, 0.0, 10.1, 0.1, 0.5, 2)
show_hudmessage(id, "Killstreak: %i", g_Kills[killer])
}
public showKillstreak(id)
{
set_hudmessage(0, 95, 245, 0.0, 0.0, 0, 0.0, 10.1, 0.1, 0.5, 2)
for ( new i = 0 ; i <= g_MaxClients ; i++ ) {
if ( is_user_connected(i) && is_user_alive(i) && ! is_user_bot(i) && ! is_user_hltv(i) )
show_hudmessage(id, "Killstreak: %i", g_Kills[i])
}
}
__________________