Textdraw Update ?
#1

Hi Every one !
I want Make Textdraw will show player kills like this
pawn Код:
pKills = TextDrawCreate(3.000000, 423.000000, "Kills : %s",AccountInfo[playerid][Kills]);
Or How :0
Reply
#2

Create a public function, to destroy, and then create the draw.
Set a timer to call the public every X seconds, and then it get's "updated"
Reply
#3

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
Create a public function, to destroy, and then create the draw.
Set a timer to call the public every X seconds, and then it get's "updated"
What :0 Lol i am not the pro so can you give me example e.e
Thanks for the Fast Reply
Reply
#4

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
Create a public function, to destroy, and then create the draw.
Set a timer to call the public every X seconds, and then it get's "updated"
Why update it on a timer? Just update it under OnPlayerDeath. Why would you waste resources on a timer?
Reply
#5

pawn Код:
//onplayerspawn put this
SetTimer("Killdraw",10000,1); //it "updates" the textdraw every 10 seconds

forward Killdraw(playerid);
public Killdraw(playerid)
{
    TextDrawDestroy()//destroy the textdraw
    Text:TextDrawCreate()//create it again
}
@MP2 yes that's also possible, my bad, i can make a code of that aswell if he wants it that way..

If you want it the way MP2 said, then add this:

pawn Код:
Killdraw(killerid);
under onplayerdeath
Reply
#6

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
pawn Код:
//onplayerspawn put this
SetTimer("Killdraw",10000,1); //it "updates" the textdraw every 10 seconds

forward Killdraw(playerid);
public Killdraw(playerid)
{
    TextDrawDestroy()//destroy the textdraw
    Text:TextDrawCreate()//create it again
}
@MP2 yes that's also possible, my bad, i can make a code of that aswell if he wants it that way..
*facepalm* Ever heard of the "killerid" variable in OnPlayerDeath? Plus why would he need to create a new one when he can just TextDrawSetString ? https://sampwiki.blast.hk/wiki/TextDrawSetString

Edit: Oh you edited your post... Then only see the 2nd sentence
Reply
#7

You are doing it wrong... For this you will need 1 textdraw for each player, use CreatePlayerTextDraw like in the following code, or else everything will mix up:

pawn Код:
new PlayerText:pKills[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    pKills[playerid] = CreatePlayerTextDraw(playerid, 3.0, 423.0, "_"); //Creates a textdraw for the player that just joined
    // TextDraw settings here (font, text size, etc.) ... Remember to use the per-player variant! (Player[...])
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PlayerTextDrawDestroy(playerid, pKills[playerid]); //Destroys the textdraw
    return 1;
}

stock UpdateKillsDisplay(playerid)
{
    new _str[32];
    format(_str, sizeof(_str), "Kills : %d", AccountInfo[playerid][Kills]); //Formats the text... %d means an integer will be inserted there
    PlayerTextDrawSetString(playerid, pKills[playerid], _str); //Updates the player's textdraw with the text we just formatted
    PlayerTextDrawShow(playerid, pKills[playerid]); //Make sure the textdraw is visible
    return 1;
}
Now you can use "UpdateKillsDisplay" in OnPlayerDeath for example:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    //Anything else you have in this callback (Updating variables, etc)
    if(killerid != INVALID_PLAYER_ID) UpdateKillsDisplay(killerid); //If player didn't suicide, update the display of the killer
    return 1;
}
Reply
#8

Quote:
Originally Posted by OPremium
Посмотреть сообщение
You are doing it wrong... For this you will need 1 textdraw for each player, use CreatePlayerTextDraw like in the following code, or else everything will mix up:

pawn Код:
new PlayerText:pKills[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    pKills[playerid] = CreatePlayerTextDraw(playerid, 3.0, 423.0, "_"); //Creates a textdraw for the player that just joined
    // TextDraw settings here (font, text size, etc.) ... Remember to use the per-player variant! (Player[...])
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PlayerTextDrawDestroy(playerid, pKills[playerid]); //Destroys the textdraw
    return 1;
}

stock UpdateKillsDisplay(playerid)
{
    new _str[32];
    format(_str, sizeof(_str), "Kills : %d", AccountInfo[playerid][Kills]); //Formats the text... %d means an integer will be inserted there
    PlayerTextDrawSetString(playerid, pKills[playerid], _str); //Updates the player's textdraw with the text we just formatted
    PlayerTextDrawShow(playerid, pKills[playerid]); //Make sure the textdraw is visible
    return 1;
}
Now you can use "UpdateKillsDisplay" in OnPlayerDeath for example:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    //Anything else you have in this callback (Updating variables, etc)
    if(killerid != INVALID_PLAYER_ID) UpdateKillsDisplay(killerid); //If player didn't suicide, update the display of the killer
    return 1;
}
i think this is Long Way ..
I Make this and its Work and short (Just for More info)
pawn Код:
new Text:Kills;
pawn Код:
Textdraw1 = TextDrawCreate(414.000000, 424.000000, "Kills:~r~");
    TextDrawBackgroundColor(Kills, 16711935);
    TextDrawFont(Kills, 2);
    TextDrawLetterSize(Kills, 0.559999, 2.299999);
    TextDrawColor(Kills, 65535);
    TextDrawSetOutline(Kills, 1);
    TextDrawSetProportional(Kills, 1);
pawn Код:
public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer( playerid, Kills);
}
pawn Код:
OnPlayerUpdate(playerid)
{
new str[120];
format(str, sizeof(str),"Kills : %d",AccountInfo[playerid][Kills]);
TextDrawSetString(Kills, str );
Reply
#9

Quote:
Originally Posted by [D]ry[D]esert
Посмотреть сообщение
i think this is Long Way ..
I Make this and its Work and short (Just for More info)
pawn Код:
new Text:Kills;
pawn Код:
Textdraw1 = TextDrawCreate(414.000000, 424.000000, "Kills:~r~");
    TextDrawBackgroundColor(Kills, 16711935);
    TextDrawFont(Kills, 2);
    TextDrawLetterSize(Kills, 0.559999, 2.299999);
    TextDrawColor(Kills, 65535);
    TextDrawSetOutline(Kills, 1);
    TextDrawSetProportional(Kills, 1);
pawn Код:
public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer( playerid, Kills);
}
pawn Код:
OnPlayerUpdate(playerid)
{
new str[120];
format(str, sizeof(str),"Kills : %d",AccountInfo[playerid][Kills]);
TextDrawSetString(Kills, str );
Ever heard of code optimization? Oh wait, this is SA:MP, of course you haven't. Why would someone use OnPlayerUpdate and call a function every half a second if he can call it only when needed (OnPlayerDeath) ?!
Reply
#10

Quote:
Originally Posted by king_hual
Посмотреть сообщение
Ever heard of code optimization? Oh wait, this is SA:MP, of course you haven't. Why would someone use OnPlayerUpdate and call a function every half a second if he can call it only when needed (OnPlayerDeath) ?!
I am Not just using Kills ..
i am useing Score: Deaths: Kills: ect..
So that will be better if i use it in OnPlayerUpdate
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)