Stats in textdraws -
System64 - 05.10.2011
Hi all!
Today I'm gonna show you how to make stats in textdraws (Player stats)! Note: This is not just copy paste tutorial then you already need some PAWN knowledge!
1. We need variable for showed stats and 2 forward for custom functions! I use RyDeR`s bit system!
pawn Code:
new rBit1: StatsShowing <MAX_PLAYERS>;
forward ShowStats(playerid, id);
forward CheckPlayerStatsKeys(playerid);
2. We have to create command for showing player stats, I use YCMD!
pawn Code:
YCMD:stats(playerid, params[], help)
{
#pragma unused help
#pragma unused params
SetTimerEx("CheckPlayerStatsKeys", 200, 1, "d", playerid); //setting timer for checking player keys
ShowStats(playerid, playerid); //function where we create textdraws
TogglePlayerControllable(playerid, 0); //freezing players
rBit1_Set(StatsShowing, playerid, 1); //ssetting variable on true
//functions for showing stats
return 1;
}
Example:
pawn Code:
YCMD:stats(playerid, params[], help)
{
#pragma unused help
#pragma unused params
SetTimerEx("CheckPlayerStatsKeys", 200, 1, "d", playerid);
ShowStats(playerid, playerid);
TogglePlayerControllable(playerid, 0);
rBit1_Set(StatsShowing, playerid, 1);
TextDrawShowForPlayer(playerid, StatsBox[playerid]);
TextDrawShowForPlayer(playerid, StatsName[playerid]);
TextDrawShowForPlayer(playerid, StatsID[playerid]);
TextDrawShowForPlayer(playerid, StatsMoney[playerid]);
TextDrawShowForPlayer(playerid, StatsScore[playerid]);
TextDrawShowForPlayer(playerid, StatsKills[playerid]);
TextDrawShowForPlayer(playerid, StatsDeaths[playerid]);
TextDrawShowForPlayer(playerid, StatsStatus[playerid]);
TextDrawShowForPlayer(playerid, StatsOnline[playerid]);
TextDrawShowForPlayer(playerid, StatsWarns[playerid]);
return 1;
}
3. Function ShowStats (We create textdraws in it!)
pawn Code:
public ShowStats(playerid, id)
{
//here put functions for textdraws etc. just look at the example
return 1;
}
Example (Take a look on format functions, you have to put your variables in it for eq. warns kills etc...)
pawn Code:
public ShowStats(playerid, id)
{
new tdstring[512];
StatsBox[id] = TextDrawCreate(258.000000, 200.000000, ".");
TextDrawBackgroundColor(StatsBox[id], 255);
TextDrawFont(StatsBox[id], 1);
TextDrawLetterSize(StatsBox[id], 0.029999, 12.999998);
TextDrawColor(StatsBox[id], -1);
TextDrawSetOutline(StatsBox[id], 0);
TextDrawSetProportional(StatsBox[id], 1);
TextDrawSetShadow(StatsBox[id], 1);
TextDrawUseBox(StatsBox[id], 1);
TextDrawBoxColor(StatsBox[id], 50);
TextDrawTextSize(StatsBox[id], 36.000000, 60.000000);
format(tdstring, sizeof(tdstring), "IME: ~w~%s", GetName(id));
StatsName[id] = TextDrawCreate(61.000000, 210.000000, tdstring);
TextDrawBackgroundColor(StatsName[id], 255);
TextDrawFont(StatsName[id], 2);
TextDrawLetterSize(StatsName[id], 0.500000, 1.000000);
TextDrawColor(StatsName[id], -16776961);
TextDrawSetOutline(StatsName[id], 0);
TextDrawSetProportional(StatsName[id], 1);
TextDrawSetShadow(StatsName[id], 1);
format(tdstring, sizeof(tdstring), "ID: ~w~%d", id);
StatsID[id] = TextDrawCreate(61.000000, 220.000000, tdstring);
TextDrawBackgroundColor(StatsID[id], 255);
TextDrawFont(StatsID[id], 2);
TextDrawLetterSize(StatsID[id], 0.500000, 1.000000);
TextDrawColor(StatsID[id], -16776961);
TextDrawSetOutline(StatsID[id], 0);
TextDrawSetProportional(StatsID[id], 1);
TextDrawSetShadow(StatsID[id], 1);
format(tdstring, sizeof(tdstring), "Novac: ~w~%d", AC_GetPlayerMoney(id));
StatsMoney[id] = TextDrawCreate(61.000000, 230.000000, tdstring);
TextDrawBackgroundColor(StatsMoney[id], 255);
TextDrawFont(StatsMoney[id], 2);
TextDrawLetterSize(StatsMoney[id], 0.500000, 1.000000);
TextDrawColor(StatsMoney[id], -16776961);
TextDrawSetOutline(StatsMoney[id], 0);
TextDrawSetProportional(StatsMoney[id], 1);
TextDrawSetShadow(StatsMoney[id], 1);
format(tdstring, sizeof(tdstring), "Bodovi: ~w~%d", GetPlayerScore(id));
StatsScore[id] = TextDrawCreate(61.000000, 240.000000, tdstring);
TextDrawBackgroundColor(StatsScore[id], 255);
TextDrawFont(StatsScore[id], 2);
TextDrawLetterSize(StatsScore[id], 0.500000, 1.000000);
TextDrawColor(StatsScore[id], -16776961);
TextDrawSetOutline(StatsScore[id], 0);
TextDrawSetProportional(StatsScore[id], 1);
TextDrawSetShadow(StatsScore[id], 1);
format(tdstring, sizeof(tdstring), "Ubojstva: ~w~%d", PlayerInfo[id][pKills]);
StatsKills[id] = TextDrawCreate(61.000000, 250.000000, tdstring);
TextDrawBackgroundColor(StatsKills[id], 255);
TextDrawFont(StatsKills[id], 2);
TextDrawLetterSize(StatsKills[id], 0.500000, 1.000000);
TextDrawColor(StatsKills[id], -16776961);
TextDrawSetOutline(StatsKills[id], 0);
TextDrawSetProportional(StatsKills[id], 1);
TextDrawSetShadow(StatsKills[id], 1);
format(tdstring, sizeof(tdstring), "Smrti: ~w~%d", PlayerInfo[id][pDeaths]);
StatsDeaths[id] = TextDrawCreate(61.000000, 260.000000, tdstring);
TextDrawBackgroundColor(StatsDeaths[id], 255);
TextDrawFont(StatsDeaths[id], 2);
TextDrawLetterSize(StatsDeaths[id], 0.500000, 1.000000);
TextDrawColor(StatsDeaths[id], -16776961);
TextDrawSetOutline(StatsDeaths[id], 0);
TextDrawSetProportional(StatsDeaths[id], 1);
TextDrawSetShadow(StatsDeaths[id], 1);
if(PlayerInfo[playerid][pAdmin] == 0)
{
format(tdstring, sizeof(tdstring), "Status: ~w~Igrac");
}
else if(PlayerInfo[playerid][pAdmin] == 1)
{
format(tdstring, sizeof(tdstring), "Status: ~w~GM");
}
else if(PlayerInfo[playerid][pAdmin] == 2)
{
format(tdstring, sizeof(tdstring), "Status: ~w~Admin");
}
else if(PlayerInfo[playerid][pAdmin] == 3)
{
format(tdstring, sizeof(tdstring), "Status: ~w~Head");
}
StatsStatus[id] = TextDrawCreate(61.000000, 270.000000, tdstring);
TextDrawBackgroundColor(StatsStatus[id], 255);
TextDrawFont(StatsStatus[id], 2);
TextDrawLetterSize(StatsStatus[id], 0.500000, 1.000000);
TextDrawColor(StatsStatus[id], -16776961);
TextDrawSetOutline(StatsStatus[id], 0);
TextDrawSetProportional(StatsStatus[id], 1);
TextDrawSetShadow(StatsStatus[id], 1);
format(tdstring, sizeof(tdstring), "Online: ~w~%d", PlayerInfo[playerid][pOnline]);
StatsOnline[id] = TextDrawCreate(61.000000, 280.000000, tdstring);
TextDrawBackgroundColor(StatsOnline[id], 255);
TextDrawFont(StatsOnline[id], 2);
TextDrawLetterSize(StatsOnline[id], 0.500000, 1.000000);
TextDrawColor(StatsOnline[id], -16776961);
TextDrawSetOutline(StatsOnline[id], 0);
TextDrawSetProportional(StatsOnline[id], 1);
TextDrawSetShadow(StatsOnline[id], 1);
format(tdstring, sizeof(tdstring), "Upozorenja: ~w~%d", PlayerInfo[playerid][pWarns]);
StatsWarns[id] = TextDrawCreate(61.000000, 290.000000, tdstring);
TextDrawBackgroundColor(StatsWarns[id], 255);
TextDrawFont(StatsWarns[id], 2);
TextDrawLetterSize(StatsWarns[id], 0.500000, 1.000000);
TextDrawColor(StatsWarns[id], -16776961);
TextDrawSetOutline(StatsWarns[id], 0);
TextDrawSetProportional(StatsWarns[id], 1);
TextDrawSetShadow(StatsWarns[id], 1);
return 1;
}
4. Now we only need to create our function for checking player keys...
So if he press F his stats will hide and destroy
pawn Code:
public CheckPlayerStatsKeys(playerid)
{
if(rBit1_Get(StatsShowing, playerid)) //if stats are showed, so variables is true...
{
new keys, ud, lr; //new variables for getting player keys, using it in GetPlayerKeys
GetPlayerKeys(playerid, keys, ud, lr); //getting player keys
if(keys == KEY_SECONDARY_ATTACK) //so if he press F...
{
TogglePlayerControllable(playerid, 1); //unfreezing player
//functions for hiding textdraws
//functions for destroying textdraws, if you don't do that, your stats will get bugged :S
}
}
return 1;
}
return 1;
}
Example:
pawn Code:
public CheckPlayerStatsKeys(playerid)
{
if(rBit1_Get(StatsShowing, playerid))
{
new keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
if(keys == KEY_SECONDARY_ATTACK)
{
TogglePlayerControllable(playerid, 1);
TextDrawHideForPlayer(playerid, StatsBox[playerid]);
TextDrawHideForPlayer(playerid, StatsName[playerid]);
TextDrawHideForPlayer(playerid, StatsID[playerid]);
TextDrawHideForPlayer(playerid, StatsMoney[playerid]);
TextDrawHideForPlayer(playerid, StatsScore[playerid]);
TextDrawHideForPlayer(playerid, StatsKills[playerid]);
TextDrawHideForPlayer(playerid, StatsDeaths[playerid]);
TextDrawHideForPlayer(playerid, StatsStatus[playerid]);
TextDrawHideForPlayer(playerid, StatsOnline[playerid]);
TextDrawHideForPlayer(playerid, StatsWarns[playerid]);
TextDrawDestroy(StatsBox[playerid]);
TextDrawDestroy(StatsName[playerid]);
TextDrawDestroy(StatsID[playerid]);
TextDrawDestroy(StatsMoney[playerid]);
TextDrawDestroy(StatsScore[playerid]);
TextDrawDestroy(StatsKills[playerid]);
TextDrawDestroy(StatsDeaths[playerid]);
TextDrawDestroy(StatsStatus[playerid]);
TextDrawDestroy(StatsOnline[playerid]);
TextDrawDestroy(StatsWarns[playerid]);
}
}
return 1;
}
Tutorial & script by System32
Re: Stats in textdraws -
Nenad - 05.10.2011
you don't need this timer to hide textdraws:
Code:
SetTimerEx("CheckPlayerStatsKeys", 200, 1, "d", playerid); //setting timer for checking player keys
you can hide textdraws by using OnPlayerKeyStateChange
and this:
shoul be:
because max input and output in samp is 128
Re: Stats in textdraws -
grand.Theft.Otto - 05.10.2011
This ' tutorial ' really isn't explained well.
You can't expect people to know what YCMD is, what it does, where to put it or where to find it.
Some of the stuff in your code is in a different language ...
You could at least provide some links for the YCMD topic, and some links for some of the SA-MP functions, as you have barely explained them.
Sorry, I doubt newbies will understand this tutorial.
Re: Stats in textdraws -
Lorenc_ - 06.10.2011
"SetTimerEx("CheckPlayerStatsKeys", 200, 1, "d", playerid);"
What's wrong with OnPlayerKeyStateChange?
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_FIRE) return CloseStatsBox(playerid);
return 1;
}
Think more effectively rather than a
200 Millisecond timer..
Using one include for something rather small is frankly quite pointless.
Doing this will make a 8 bit array without any includes.
I present, the char array!
pawn Code:
new
bool: isstatsShowed [ MAX_PLAYERS char ]
;
#define StatsShowed(%1) (isStatsShowed{(%1)}=true)
if(StatsShowed(playerid)) return HideStats(playerid);
So on..
Re: Stats in textdraws -
System64 - 06.10.2011
@Nenand - Sorry my bad, it has to be 128 but I don't know why I put it 512 xD
@grand.Theft.Otto - Why I have to put link of YCMD, they can type in ****** 'YCMD samp' and find it?
How I said, you need some PAWN knowledge for this tutorial, if they can't search functions on SA:MP Wiki than they shouldn't start PAWN scripting!
@lorenc I tried that way but my textdraws doesn't close, maybe it's better in OnPlayerUpdate?
Anyway thanks for comment
Re: Stats in textdraws -
Biesmen - 06.10.2011
It's nice, but it's not really a tutorial. In a tutorial you explain what you are doing and what those functions mean.
Re: Stats in textdraws -
aRoach - 06.10.2011
It's Awsome, Great Job, S-64
+1 Rep
Re: Stats in textdraws -
System64 - 06.10.2011
@Biesmen - Maybei could explain it a bit better but okay thanks
aRoach - Thanks
Re: Stats in textdraws -
sonn51280 - 04.09.2018
good nice !
Re: Stats in textdraws -
solstice_ - 04.09.2018
Quote:
Originally Posted by sonn51280
good nice !
|
Notice that this thread is from 2011 though..