Score!
#1

Hi, I have Been Creating A TextDraw Score!

Here's My Code

PHP код:
    new string2[128];
    new 
Score GetPlayerScore(playerid);
    
format(string2sizeof(string2), "Score: %i"Score);
    
Textdraw2[playerid] = CreatePlayerTextDraw(playerid3.999998185.173278string2);
    
PlayerTextDrawLetterSize(playeridTextdraw2[playerid], 0.4499991.600000);
    
PlayerTextDrawAlignment(playeridTextdraw2[playerid], 1);
    
PlayerTextDrawColor(playeridTextdraw2[playerid], -1);
    
PlayerTextDrawSetShadow(playeridTextdraw2[playerid], 0);
    
PlayerTextDrawSetOutline(playeridTextdraw2[playerid], 2);
    
PlayerTextDrawBackgroundColor(playeridTextdraw2[playerid], 51);
    
PlayerTextDrawFont(playeridTextdraw2[playerid], 2);
    
PlayerTextDrawSetProportional(playeridTextdraw2[playerid], 1); 
When I press Tab! It Shows My Score as 1000

And The TextDraw Says Its 0. Plz Help
Reply
#2

frist you have to Create the textdraw for all players .. like in OngamemodeInit .. with a loop

then you have to update the textdraw with


https://sampwiki.blast.hk/wiki/TextDrawSetString


and use

format(string2, sizeof(string2), "Score: %i",GetPlayerScore(playerid));
Reply
#3

Din't Get It! Can U Do It For Me?
Reply
#4

@MrReBzz.
No, You should learn scripting instead asking it.

Anyway don't format the textdraw when creating.

Update it by using TextDrawSetString.
Reply
#5

I Tried It. Here's The Code

PHP код:
    Textdraw2 TextDrawCreate(3.999998185.173278"Score:");
    
TextDrawLetterSize(Textdraw20.4499991.600000);
    
TextDrawAlignment(Textdraw21);
    
TextDrawColor(Textdraw2, -1);
    
TextDrawSetShadow(Textdraw20);
    
TextDrawSetOutline(Textdraw21);
    
TextDrawBackgroundColor(Textdraw251);
    
TextDrawFont(Textdraw22);
    
TextDrawSetProportional(Textdraw21); 
PHP код:
public OnPlayerConnect(playerid)
{    
     new 
string2[41];
    
GetPlayerName(playeridstring241);
    
format(string2sizeof(string2), "Score: %i"GetPlayerScore(playerid));
    
TextDrawSetString(Textdraw2string2);
    return 
1;

And Here's What They Show

Reply
#6

You have to update it when you give them score; it doesn't automatically update. Scripts don't 'guess' how you want things to work.

Either hook SetPlayerScore or make a custom function like SetPlayerScoreEx (I'd recommend hooking SetPlayerScore).

Put this before any calls of SetPlayerScore (not every one.. once..)

pawn Код:
stock hook_SetPlayerScore(playerid, score)
{
    if(!IsPlayerConnected(playerid)) return 0;
    SetPlayerScore(playerid, score);

    // Update the TD here using TextDrawSetString
    return 1;
}
#if defined _ALS_SetPlayerScore
    #undef SetPlayerScore
#else
    #define _ALS_SetPlayerScore
#endif
#define SetPlayerScore hook_SetPlayerScore
I.e. just after main() {}

I'd also recommend player-textdraws for this kind of thing.
Reply
#7

Fixed!

Copied This Thing From On PlayerConnect To OnPLayer Update

Quote:

new string2[41];
GetPlayerName(playerid, string2, 41);
format(string2, sizeof(string2), "Score: %i", GetPlayerScore(playerid));
TextDrawSetString(Textdraw2, string2);

Reply
#8

That's a stupid idea. It's going to update it hundreds of times a minute, instead of possibly less than once a minute (when ever their score changes)..

If you have this approach towards things then your server is going to be quite laggy. OnPlayerUpdate should only be used when needed - it's called extremely often even for just one player - imagine 100..
Reply
#9

Quote:
Originally Posted by MP2
Посмотреть сообщение
That's a stupid idea. It's going to update it hundreds of times a minute, instead of possibly less than once a minute (when ever their score changes)..

If you have this approach towards things then your server is going to be quite laggy. OnPlayerUpdate should only be used when needed - it's called extremely often even for just one player - imagine 100..
i agree, so simply you can update it just when player get score for example if you kill somone update it (For DM/TDM or what ever).
Reply
#10

38,000 times per minute..if theres 10 players 380000 tiumers will run each second..too much eh?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)