05.10.2011, 15:14
Hi all!
Today I'm gonna show you how to make stats in textdraws (Player stats)!
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);
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;
}
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;
}
pawn Code:
public ShowStats(playerid, id)
{
//here put functions for textdraws etc. just look at the example
return 1;
}
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;
}
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;
}
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;
}