SA-MP Forums Archive
Help | "TAB" key - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help | "TAB" key (/showthread.php?tid=72860)



Help | "TAB" key - borisblat - 11.04.2009

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?




Re: Help | "TAB" key - GanG$Ta - 11.04.2009

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();



Re: Help | "TAB" key - OmeRinG - 11.04.2009

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




Re: Help | "TAB" key - Nubotron - 11.04.2009

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.


Re: Help | "TAB" key - borisblat - 11.04.2009

thank for both of you


Re: Help | "TAB" key - Weirdosport - 11.04.2009

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


Re: Help | "TAB" key - Flo_White - 11.04.2009

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


Re: Help | "TAB" key - Fire Dragon - 11.04.2009

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


Re: Help | "TAB" key - borisblat - 11.04.2009

wtf i am confused