Get next rank
#1

Hello. I made a textdraw which shows current score and score needed for next rank. Ex: 20/100

How i can get how much score a player needs it for the next rank? Currently i have this:

pawn Код:
enum e_RANK
{
    rankName[35],
    rankScore,
    Float:rankHealth,
    Float:rankArmour
};
Which rankScore sets the score needed for that rank. I need something like: "You need %d score to reach next rank".

Thanks.
Reply
#2

This is basic Mathematics. You have 20, You need 100. So you need 100-20=80 more score. Store 80 in a variable and show it.
Reply
#3

Tell me how, teacher.
Reply
#4

Код:
enum e_RANK
{
	rankName[35],
	rankScore,
	Float:rankHealth,
	Float:rankArmour
};

if( GetPlayerScore(playerid) < rankScore ) {
    new scorerequired = rankScore - GetPlayerScore(playerid);
}
Reply
#5

Ok so, i created a textdraw and to update it i did this:

pawn Код:
foreach (new i : Player)
    {
    new nrs[128];
   
    if( GetPlayerScore(i) < rankScore )
    {
    new scorerequired = rankScore - GetPlayerScore(i);
    }
   
    format(nrs, sizeof(nrs), "%d / %d", GetPlayerScore(i), scorerequired);
    TextDrawSetString(NextRankTxd[i], nrs);
But im getting undefined symbol "scorerequired".
Reply
#6

Quote:
Originally Posted by Despacito
Посмотреть сообщение
Ok so, i created a textdraw and to update it i did this:

pawn Код:
foreach (new i : Player)
    {
    new nrs[128];
   
    if( GetPlayerScore(i) < rankScore )
    {
    new scorerequired = rankScore - GetPlayerScore(i);
    }
   
    format(nrs, sizeof(nrs), "%d / %d", GetPlayerScore(i), scorerequired);
    TextDrawSetString(NextRankTxd[i], nrs);
But im getting undefined symbol "scorerequired".
Код HTML:
foreach (new i : Player)
{
	new nrs[128];
	if( GetPlayerScore(i) < rankScore )
	{
	    new scorerequired = rankScore - GetPlayerScore(i);
	    format(nrs, sizeof(nrs), "%d / %d", GetPlayerScore(i), scorerequired);
	    TextDrawSetString(NextRankTxd[i], nrs);
	}
}
	
but it won't work how you want lol cuz scorerequired is set to rankScore - GetPlayerScore, like player have 50 score rank require 100 scores so scorerequired will return 50 so in textdraw will show 50/50
Reply
#7

I wanna show in textdraw the current player score and the next rank score required. Like i am Corporal and i have 50 score, to be Corporal 2 i'll need 100 score, so 50 / 100

How?
Reply
#8

Quote:
Originally Posted by Despacito
Посмотреть сообщение
I wanna show in textdraw the current player score and the next rank score required. Like i am Corporal and i have 50 score, to be Corporal 2 i'll need 100 score, so 50 / 100

How?
you need create playertextdraws(if its player scores) https://sampwiki.blast.hk/wiki/CreatePlayerTextDraw
idk why you using foreach at this situation(you showing for all server players at one time?).

Код HTML:
        new scorestring[25];
	format(scorestring, sizeof(scorestring), "%d / %d", GetPlayerScore(playerid), rankScore);
	PlayerTextDrawSetString(playerid, NextRankTxd[[playerid]], scorestring);
Reply
#9

I'm using foreach because i have a timer to update all textdraws. (Such as stats).

Ok so, do i need to create PlayerTexdraws?
Reply
#10

Quote:
Originally Posted by Despacito
Посмотреть сообщение
I'm using foreach because i have a timer to update all textdraws. (Such as stats).

Ok so, do i need to create PlayerTexdraws?
yes cuz it isnt global score...

i have made minimalistic system for you xd

Код HTML:
enum player_ranks{

	rName[30],
	rReqScore
	// other params
}
new 
	pRank[5][player_ranks], // change 5 to your number of ranks
	playerRank[MAX_PLAYERS]
; 

public OnGameModeInit(){

	pRank[0][rName] = "Default rank";
	pRank[0][rReqScore] = 0;
	return 1;
}

public OnPlayerConnect(playerid){

	playerRank[playerid] = 0;
	return 1;
}

// somewhere settimer...

forward updateRanksTD();
public updateRanksTD(){

	for(new p; p < MAX_PLAYERS; p++){
		if(!IsPlayerConnected(p)) return false;
		new scorestring[25], rID = playerRank[p];
		format(scorestring, sizeof(scorestring), "Rank : %d / %d", GetPlayerScore(p), pRank[rID+1][rReqScore]);
		PlayerTextDrawSetString(p, NextRankTxd[playerid], scorestring);
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)