public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid == playerid)
{
new message[256];
GetPlayerName(playerid, playername, sizeof(playername));
SendDeathMessage(killerid, playerid, reason);
format(message, sizeof(message), ">> %s has killed himself.", playername);
SendClientMessageToAll(SYSTEM_COLOR, message);
}
if(killerid != INVALID_PLAYER_ID || killerid != playerid)
{
new rand = random(sizeof(SoundOnDeath)), Float:Xp, Float:Yp, Float:Zp, Float:Xk, Float:Yk, Float:Zk;
GetPlayerPos(playerid, Xp, Yp, Zp);
GetPlayerPos(killerid, Xk, Yk, Zk);
PlayerPlaySound(killerid, SoundOnDeath[rand][0],Xk,Yk,Zk);
SendDeathMessage(killerid, playerid, reason);
SetPVarInt(playerid, "PKills", PlayerInfo[killerid][pKills]++);
SetPVarInt(playerid, "PDeaths", PlayerInfo[playerid][pDeaths]++);
roundstats[playerid][rKills]++;
roundstats[playerid][rDeaths]++;
SetPlayerHealth(killerid, 100);
SetPlayerArmour(killerid, 100);
}
return 1;
}
enum rInfo
{
rKills,
rDeaths
}
new roundstats[MAX_PLAYERS][rInfo];
stock GetHighestKiller() // TOP KILLER.
{
new kills;
new player = -1;
for (new i=0, mx = GetMaxPlayers(); i!=mx; ++i)
{
if(IsPlayerConnected(i))
{
if (roundstats[i][rKills] > kills)
{
player = i;
kills = roundstats[i][rKills];
}
}
}
return player;
}
public OnPlayerSpawn(playerid)
{
new Text:messagetextdraw;
new topkillermessage[256];
messagetextdraw = TextDrawCreate(1.0, 5.6, "");
new highestkillerid = GetHighestKiller();
GetPlayerName(highestkillerid, playername, sizeof(playername));
format(topkillermessage, sizeof(topkillermessage), "%s has the most amount of kills.", playername);
TextDrawSetString(messagetextdraw,topkillermessage);
TextDrawShowForPlayer(playerid, messagetextdraw);
}
|
I am wondering, which new Textdraw ?
You got some textdraw and than you just use TextDrawSetString to overwrite the existing text Also any event related thing should be put where the event is handled => If someone gets a kill it should be OnPlayerDeath, after you increase the kill counter check for the new highest killer |
new Text:messagetextdraw; new topkillermessage[256]; new highestkillerid = GetHighestKiller(); GetPlayerName(highestkillerid, playername, sizeof(playername)); format(topkillermessage, sizeof(topkillermessage), "%s has the most amount of kills.", playername); TextDrawSetString(messagetextdraw,topkillermessage); TextDrawShowForPlayer(playerid, messagetextdraw);
//
if(killerid != INVALID_PLAYER_ID || killerid != playerid)
{
new rand = random(sizeof(SoundOnDeath)), Float:Xk, Float:Yk, Float:Zk;
GetPlayerPos(killerid, Xk, Yk, Zk);
PlayerPlaySound(killerid, SoundOnDeath[rand][0],Xk,Yk,Zk);
SendDeathMessage(killerid, playerid, reason);
SetPVarInt(killerid, "PKills", PlayerInfo[killerid][pKills]++);
SetPVarInt(playerid, "PDeaths", PlayerInfo[playerid][pDeaths]++);
roundstats[playerid][rKills]++;
roundstats[playerid][rDeaths]++;
SetPlayerHealth(killerid, 100);
SetPlayerArmour(killerid, 100);
new topkillermessage[128];
new highestkillerid = GetHighestKiller();
GetPlayerName(highestkillerid, topkillermessage, MAX_PLAYER_NAME);
strcat(topkillermessage, " has the most amount of kills.");
TextDrawSetString(YOUR_TEXTDRAW, topkillermessage);
}
|
Put it in OnPlayerDeath ...
pawn Код:
|
new LASTMESSAGE[100]; strcat(LASTMESSAGE,topkillermessage, " has the most amount of kills."); TextDrawSetString(LASTMESSAGE, topkillermessage);
// globally
new Text: gKillText;
// OnGameModeInit
gKillText = TextDrawCreate(320.0, 240.0, "~r~Highest Kills~n~~w~Noone");
// OnPlayerConnect
TextDrawShowForPlayer(playerid, gKillText);
// OnPlayerDeath
if(killerid != INVALID_PLAYER_ID || killerid != playerid)
{
// CODE
new string[128];
GetPlayerName(GetHighestKiller(), string, MAX_PLAYER_NAME);
format(string, sizeof string, "~r~Highest Kills~n~~w~%s", string);
TextDrawSetString(gKillText, string);
}
|
Normally you do it like that, you use a global variable, create the textdraw somewhere at the beginning (= OnGameModeInit), show it to everyone if they connect and update it where you want it (we want it to be if the kill variable change = OnPlayerDeath)
pawn Код:
If you update it anywhere else (for example if a new round starts) just update the textdraw there likewise Also there is something wrong with your code "roundstats[playerid][rKills]++;", additionally there is no need to pVars at all |

|
it's late now i'm going to sleep then work on this tomorrow, what's wrong with roundstats[playerid][rKills]++; ?
![]() btw thanks for the help bro ![]() |
|
Because they are kills I guessed I should be killerid instead of playerid
|