Textdraw
#1

Yes, I know there has been many topics about this. But I can't figure out to do this, I have searched, but couldnt get a good match.

I want a textdraw (I know how to create them), that shows how many kills and deaths you have got.
I know its something with TextDrawSetString, but.. How do I do this?
Reply
#2

I'm assuming you're keeping a variable per player with kills and deaths.

OnPlayerDeath(playerid,killerid,reason)
{
Kills[killerid]++;
Deaths[playerid]++;
new string[100];
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[playerid],Deaths[playerid]);
TextDrawSetString(KillsDeathsText[playerid],string);
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[killerid],Deaths[killerid]);
TextDrawSetString(KillsDeathsText[killerid],string);
}
Reply
#3

Quote:
Originally Posted by SilentHuntR
I'm assuming you're keeping a variable per player with kills and deaths.

OnPlayerDeath(playerid,killerid,reason)
{
Kills[killerid]++;
Deaths[playerid]++;
new string[100];
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[playerid],Deaths[playerid]);
TextDrawSetString(KillsDeathsText[playerid],string);
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[killerid],Deaths[killerid]);
TextDrawSetString(KillsDeathsText[killerid],string);
}
Ehm, actually Im not.

I have made a textdraw (textdraw0).
Nothing more.
Reply
#4

well then add the following:


pawn Код:
//Outside of any callbacks
new Kills[MAX_PLAYERS];  //Kills count
new Deaths[MAX_PLAYERS]; //Deaths count
new Text:KillsDeathsText[MAX_PLAYERS]; //The textdraw it will go on

//OnGameModeInit
OnGameModeInit()
{
for(new playerid;playerid<MAX_PLAYERS;playerid++)KillsDeathsText[playerid]=TextDrawCreate(10.0,460.0,"-");
}


//OnPlayerConnect
OnPlayerConnect(playerid)
{
Kills[playerid]=0;
Deaths[playerid]=0;
}

//the previous code given
//OnPlayerDeath
OnPlayerDeath(playerid,killerid,reason)
{
Kills[killerid]++;
Deaths[playerid]++;
new string[100];
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[playerid],Deaths[playerid]);
TextDrawSetString(KillsDeathsText[playerid],string);
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[killerid],Deaths[killerid]);
TextDrawSetString(KillsDeathsText[killerid],string);
}
I'm only not inserting indentation because I'm typing this into the post window and not in pawn, I can't hit TAB =(
Reply
#5

Quote:
Originally Posted by SilentHuntR
well then add the following:


pawn Код:
//Outside of any callbacks
new Kills[MAX_PLAYERS]; //Kills count
new Deaths[MAX_PLAYERS]; //Deaths count
new Text:KillsDeathsText[MAX_PLAYERS]; //The textdraw it will go on

//OnGameModeInit
OnGameModeInit()
{
for(new playerid;playerid<MAX_PLAYERS;playerid++)KillsDeathsText[playerid]=TextDrawCreate(10.0,460.0,"-");
}


//OnPlayerConnect
OnPlayerConnect(playerid)
{
Kills[playerid]=0;
Deaths[playerid]=0;
}

//the previous code given
//OnPlayerDeath
OnPlayerDeath(playerid,killerid,reason)
{
Kills[killerid]++;
Deaths[playerid]++;
new string[100];
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[playerid],Deaths[playerid]);
TextDrawSetString(KillsDeathsText[playerid],string);
format(string,sizeof(string),"Kills:%d -- Deaths:%d",Kills[killerid],Deaths[killerid]);
TextDrawSetString(KillsDeathsText[killerid],string);
}
I'm only not inserting indentation because I'm typing this into the post window and not in pawn, I can't hit TAB =(
Yeh I know, forums ruin indentationz, thanks for the help!!
Reply
#6

heh, forgot

//OnPlayerConnect
OnPlayerConnect(playerid)
{
TextDrawShowForPlayer(playerid,KillsDeathsText[playerid]);
}
Reply
#7

Eh, I added a textdraw named "KillsDeathsText"..

pawn Код:
KillsDeathsText = TextDrawCreate(521, 378, "Kills: -- Deaths:");
TextDrawAlignment(KillsDeathsText, 1);
TextDrawFont(KillsDeathsText, 0);
TextDrawLetterSize(KillsDeathsText, 0.1, 0.1);
TextDrawColor(KillsDeathsText, 0x000000FF);
And now it gives me some errors, idk why..

Quote:

C:\Program\SAMP Server\gamemodes\ktdm.pwn(20 : error 033: array must be indexed (variable "KillsDeathsText")
C:\Program\SAMP Server\gamemodes\ktdm.pwn(209) : error 035: argument type mismatch (argument 1)
C:\Program\SAMP Server\gamemodes\ktdm.pwn(210) : error 035: argument type mismatch (argument 1)
C:\Program\SAMP Server\gamemodes\ktdm.pwn(211) : error 035: argument type mismatch (argument 1)
C:\Program\SAMP Server\gamemodes\ktdm.pwn(212) : error 035: argument type mismatch (argument 1)

Reply
#8

should be

KillsDeathsText[playerid];

and make sure when you did

new Text:KillsDeathsText[MAX_PLAYERS];

that you added the "Text:"
Reply
#9

Quote:
Originally Posted by SilentHuntR
should be

KillsDeathsText[playerid];
What should be that? The KillsDeathsText = TextDrawCreate( ?
Reply
#10

anytime you refer to KillsDeathsText, it should show what player, in most cases "KillsDeathsText[playerid]" is what you're writing to
Reply


Forum Jump:


Users browsing this thread: