Help | "TAB" key
#1

Hello, i did some mod, but when i press "tab"
on the score like there is the score XD
but i want it to show me the money that the player have

how can i do that?

Reply
#2

OnGameModeInit:
SetTimer("CashScoreUpdate",1000,true);

below main:
public CashScoreUpdate()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
new CashScore = GetPlayerMoney(i);
SetPlayerScore(i, CashScore);
}
return true;
}

above main:
forward CashScoreUpdate();
Reply
#3

Deathly force, this will cause HUGE lags because every second you run a loop of 1 to 200.

Try this instead:
On top of the script under #include <a_samp>:
pawn Код:
forward CashUpdate(playerid);
new bool:IsUpdated[MAX_PLAYERS];
OnPlayerConnect:
pawn Код:
if(!IsUpdated[playerid]) { SetTimerEx("CashUpdate",1500,True,"i",playerid); IsUpdated[playerid] = True; }

In the bottom of the mode:
pawn Код:
public CashUpdate(playerid) { if(IsPlayerConnected(playerid)) return SetPlayerScore(playerid, GetPlayerMoney(playerid)); }

This one will run a timer for every ID that connects that will update the score only for him, every second and a half. if the player disconnects the timer keeps running and will keep working for another player gets the id so no needed to run more timers for the same ID

Reply
#4

Quote:
Originally Posted by OmeRinG
Deathly force, this will cause HUGE lags because every second you run a loop of 1 to 200.
Lol you think a pc canot do more than 200 operations each seconds? It will not create any lag, but your code will, many timers is really bad.
Reply
#5

thank for both of you
Reply
#6

Looping 200 people a second in many cases is unavoidable, but running as many timers as you have players every second is worse.
Reply
#7

when you don't have 200 playerslots you can use for MAX_PLAYERS your amount of Player Slots. And you can set the Timer to 5000ms or higher
Reply
#8

Not easier is:
pawn Код:
for(new xD = 0, xP = GetMaxPlayers(); xD < xP; xD++)
{
  if(!IsPlayerConnected(xD)) continue;
}
?
Reply
#9

wtf i am confused
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)