TextDraw + Score
#1

How can do i make the textdraw show the player's score? and also update when the player's score goes higher? I need it please help
Reply
#2

OnplayerUpdate + GetPlayerScore + Textdraw

some tutorials of it..

http://forum.sa-mp.com/showthread.ph...light=Textdraw

http://forum.sa-mp.com/showthread.ph...light=Textdraw
Reply
#3

I did the OnPlayerUpdate and getplayer score but idk how to make the Score show in a TextDraw..
Reply
#4

Create a shitload of textdraws, for each player one, and change the score to whatever it becomes ^^

pawn Код:
//On top, UNDER your includes:
new Text:score[MAX_PLAYERS] = {-1, -1, ...};
#define SetPlayerScoreEx(%1,%2) SetPlayerScore((%1), (%2)); new txtstring[11]; format(txtstring, 2, "%d", (%2)); TextDrawSetString(score[(%1)], txtstring);
 

public OnPlayerConnect(playerid)
{
  score[playerid] = TextDrawCreate(11, 280, 0);
  //Other code
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  TextDrawDestroy(score[playerid]);
  //other codes
  return 1;
}
Hope it works, change all "SetPlayerScore"-s to "SetPlayerScoreEx"
Reply
#5

ummmm okkk?
Reply
#6

Quote:
Originally Posted by ColdXX
Посмотреть сообщение
ummmm okkk?
I have the feeling I either did not explain something correctly, or you did not understand me correctly lmao. Ask questions if you have any, milk cows or just try it and see what'll happen.
Reply
#7

Ok i did it,but i get some Problem. When the score changes ,it changes on text draw but something like this

1 back to 0 ,1 back to 0 forever!
Reply
#8

Fix your signature !!!
Reply
#9

Quote:
Originally Posted by ColdXX
Посмотреть сообщение
When u said Make Textdraws for everyone....for all players? i mean wtfomghax!
And didnt really understood much of ur script. Could u explain a bit more?
Well, since text draw strings automatically change, and most players will have different scores, there need to be (unfortunately) as much textdraws as players :P



Oh and I forgot something at OnPlayerConnect:

pawn Код:
public OnPlayerConnect(playerid)
{
  score[playerid] = TextDrawCreate(11, 280, "0");
  TextDrawShowForPlayer(playerid, score[playerid]);
  //Other code
  return 1;
}
Now I'll be going through the script:

pawn Код:
//On top, UNDER your includes:
new Text:score[MAX_PLAYERS]; //Creates all the textdraws. The "{-1, -1, ...};" meant that ALL variables have a standard value of "-1", but later I saw this was kinda useless as a textdraw doesn't gets created if the player doesn't joins :P
#define SetPlayerScoreEx(%1,%2) SetPlayerScore((%1), (%2)); new txtstring[11]; format(txtstring, 2, "%d", (%2)); TextDrawSetString(score[(%1)], txtstring) //This is something which might be hard to understand, scroll to the bottom of mah post for a function ^^
 

public OnPlayerConnect(playerid)
{
  score[playerid] = TextDrawCreate(11, 280, "Score: 0"); //Creating the textdraw
  TextDrawShowForPlayer(playerid, score[playerid]); //Showing it for the player, standard value of zero "0"
  //Other code
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  TextDrawDestroy(score[playerid]); //Destroys the textdraw. It's kinda useless to have it around when the player is not connected ^^
  //other codes
  return 1;
}
Here's the function, instead of the #define, which'll be more clear (I hope):

pawn Код:
stock SetPlayerScoreEx(playerid, score)
{
  if(!IsPlayerConnected(playerid)) return; //If the player is NOT connected, the textdraws will probably bug up.
  SetPlayerScore(playerid, score); //Sets the score.
  new string[11+7]; //Why 11? 11 is the max length of an integer (A non-float value). And +8 for "score: ".
  format(string, sizeof string, "Score: %d", score); // Formats the string which contains the score.
  TextDrawSetString(score[playerid], string);
}
Note that I improved some things in THIS version, should you use it copy it from THIS post, not my previous. I hope I was clear, and you're always free to ask for questions (DON'T PM ME OR IMA KILL YOU).
Reply
#10

Fixed did it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)