public OnPlayerSpawn(playerid)
{
KillTimer(TIMER[playerid]);
TIMER[playerid] = SetTimerEx("UpdateHud", 1000, true, "i", playerid);
return 1;
}
////////////////
UpdateHud(playerid)
{
new str[64];
format(str, sizeof str, "$%d", PLAYER_MONEY[playerid]); //MONEY
PlayerTextDrawSetString(playerid, TD_HUD[playerid][0], str);
format(str, sizeof str, "- %d -", PLAYER_LEVEL[playerid]); //LEVEL
PlayerTextDrawSetString(playerid, TD_HUD[playerid][1], str);
format(str, sizeof str, "- %.3f -", PLAYER_EXP[playerid]); //EXP
PlayerTextDrawSetString(playerid, TD_HUD[playerid][2], str);
format(str, sizeof str, "- %s -", PLAYER_CLAN[playerid]); //CLAN
PlayerTextDrawSetString(playerid, TD_HUD[playerid][3], str);
return 1;
}
KillTimer(TIMER[playerid]); TIMER[playerid] = SetTimerEx("UpdateHud", 1000, true, "i", playerid);
public OnPlayerSpawn(playerid)
{
ShowHud(playerid)
return 1;
}
ShowHud(playerid)
{
PlayerTextDrawShow(playerid, TD_HUD[playerid][0]);
PlayerTextDrawShow(playerid, TD_HUD[playerid][1]);
PlayerTextDrawShow(playerid, TD_HUD[playerid][2]);
PlayerTextDrawShow(playerid, TD_HUD[playerid][3]);
KillTimer(TIMER[playerid]);
TIMER[playerid] = SetTimerEx("UpdateHud", 1000, true, "i", playerid);
return 1;
}
UpdateHud(playerid)
{
if(PLAYER_EXP[playerid] >= PLAYER_LEVEL[playerid] * 12)
{
PLAYER_LEVEL[playerid] ++;
PLAYER_EXP[playerid] = 1;
new Query[256];
format(Query, sizeof Query, "UPDATE PLAYERS SET LEVEL = '%d', EXP = '%d' WHERE PLAYER_ID = '%d';", PLAYER_LEVEL[playerid], PLAYER_EXP[playerid], PLAYER_ID[playerid]);
db_query(DT_DB, Query);
}
new str[64];
format(str, sizeof str, "$%d", PLAYER_MONEY[playerid]); //MONEY
PlayerTextDrawSetString(playerid, TD_HUD[playerid][0], str);
format(str, sizeof str, "- %d -", PLAYER_LEVEL[playerid]); //LEVEL
PlayerTextDrawSetString(playerid, TD_HUD[playerid][1], str);
format(str, sizeof str, "- %.3f -", PLAYER_EXP[playerid]); //EXP
PlayerTextDrawSetString(playerid, TD_HUD[playerid][2], str);
format(str, sizeof str, "- %s -", PLAYER_CLAN[playerid]); //CLAN
PlayerTextDrawSetString(playerid, TD_HUD[playerid][3], str);
return 1;
}
#define UPDATE_TYPE_MONEY 0 #define UPDATE_TYPE_LEVEL 1 #define UPDATE_TYPE_EXP 2 #define UPDATE_TYPE_CLAN 3 UpdateHud(playerid, type) { new str[64]; switch(type) { case UPDATE_TYPE_MONEY: { format(str, sizeof str, "$%d", PLAYER_MONEY[playerid]); //jn+ PlayerTextDrawSetString(playerid, TD_HUD[playerid][0], str); } case UPDATE_TYPE_LEVEL: { format(str, sizeof str, "- %d -", PLAYER_LEVEL[playerid]); //LEVEL PlayerTextDrawSetString(playerid, TD_HUD[playerid][1], str); } case UPDATE_TYPE_EXP: { format(str, sizeof str, "- %.3f -", PLAYER_EXP[playerid]); //EXP PlayerTextDrawSetString(playerid, TD_HUD[playerid][2], str); } case UPDATE_TYPE_CLAN: { format(str, sizeof str, "- %s -", PLAYER_CLAN[playerid]); //CLAN PlayerTextDrawSetString(playerid, TD_HUD[playerid][3], str); } } return 1; }
//OnPlayerDeath
PLAYER_MONEY[killerid] += 50;
PLAYER_EXP[killerid] ++;
UpdateHud(killerid);
//Command give / set money
PLAYER_MONEY[params[0]] += params[1];
UpdateHud(params[0]);
//etc...
Just use y_timers with 1 second update. No need to worry about CPU and related things.
|
You have absolutely no idea what you are doing! Just don't respond. Ignore him N3mesiS.
I told you what to do..... forget about timers here! They don't exist! Gone! Forgotten! What is a timer? Get it? Got it? Hope so! |
No, I meant do this:
Code:
AddToMoneyStat(playerid, amount) { PLAYER_MONEY[playerid] += amount; UpdateHud(playerid); } |