Round stats text getting over-layed.
#1

o/ guys,

So I am working onn this script and it's based on rounds where you kill anyone you can (DM).
I've been trying to get this to work properly but it seems like it's not willing to cooperate with me.
Here's the code bit:
(btw I don't get any errors when compilaing/running.)
Код:
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);
}
The issue is once a new HighestKiller comes up, the new TEXTDRAW gets layed over the old one and you can't read much. and I tried using TextDrawDestroy but I can't do it.

I was wondering if there is a way to detect when highestkillerid changes in order to destroy the old textdraw and create the new textdraw.

If anyone could help me that'd be great!

Thank you =)
Reply
#2

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
Reply
#3

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
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
Thanks, here's the code under OnPlayerSpawn:
Код:
        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);
Do you have any idea on how to update that string every time a new highestkillerid is obtained?
Reply
#4

Put it in OnPlayerDeath ...

pawn Код:
//
    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);
    }
At YOUR_TEXTDRAW you need to use the textdraw you created in OnGameModeInit, also the OLD textdraw which you store in a variable
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Put it in OnPlayerDeath ...

pawn Код:
//
    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);
    }
At YOUR_TEXTDRAW you need to use the textdraw you created in OnGameModeInit, also the OLD textdraw which you store in a variable
shouldn't I use ?
Код:
new LASTMESSAGE[100];
strcat(LASTMESSAGE,topkillermessage, " has the most amount of kills.");
TextDrawSetString(LASTMESSAGE, topkillermessage);
because there isn't any new textdraw that I created in OnGameModeInit callback and it would be out of bounds since it's in another callback (OnGameModeInit and OnPlayerDeath).

What do you think?





EDIT: I'm going to use Timers and public functions, see where that leads me. I will update you =)
Reply
#6

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 Код:
// 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);
    }
You don't need timers, just use OnPlayerDeath ... because it is the only place where you increase rKills, isn't it?
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
Reply
#7

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
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 Код:
// 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);
    }
You don't need timers, just use OnPlayerDeath ... because it is the only place where you increase rKills, isn't it?
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
Reply
#8

Quote:
Originally Posted by Lofti
Посмотреть сообщение
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 it should be killerid instead of playerid
Reply
#9

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Because they are kills I guessed I should be killerid instead of playerid
fixed and everything is working, thank you for the help bro!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)