SA-MP Forums Archive
OnPlayerUpdate problem - 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)
+--- Thread: OnPlayerUpdate problem (/showthread.php?tid=567477)



OnPlayerUpdate problem - Fantje - 14.03.2015

Heey

I have a problem:

I put this in OnPlayerUpdate:

PHP код:
public OnPlayerUpdate(){
    new 
string[128], playeridFloat:ratio floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]);
    
format(stringsizeof(string), "~y~Score: ~w~%d~n~~y~Money: ~w~$%d~n~~y~Kills: ~w~%d~n~~y~Deaths: ~w~%d~n~~y~K/D Ratio: ~w~%0.2f"GetPlayerScore(playerid), GetPlayerMoney(playerid), PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], ratio);
    
TextDrawSetString(Textdraw[playerid], string);
    
TextDrawShowForPlayer(playeridTextdraw[playerid]);
return 
1;} 
That's what it looks like.

But It don't show the textdraw. When I put it in OnPlayerSpawn it shows up but then it don't update.

Yesterday it worked in OnPlayerUpdate.


Re: OnPlayerUpdate problem - CalvinC - 14.03.2015

You forgot the playerid parameter:
pawn Код:
public OnPlayerUpdate(playerid)
And then delete the "playerid"-symbol you created with "new", that method wont work at all.
Then finally, delete the TextDrawShowForPlayer and place it under OnPlayerSpawn.


Re: OnPlayerUpdate problem - Fantje - 14.03.2015

Haha you can see my sign


Re: OnPlayerUpdate problem - PrivatioBoni - 14.03.2015

Do you really want to put that on OnPlayerUpdate? That callback is called numerous times a second.
And 2% knowledge of Pawn, you say? Are you sure you didn't just pluck a random low number out the air?


Re: OnPlayerUpdate problem - Fantje - 14.03.2015

Quote:
Originally Posted by PrivatioBoni
Посмотреть сообщение
Do you really want to put that on OnPlayerUpdate? That callback is called numerous times a second.
And 2% knowledge of Pawn, you say? Are you sure you didn't just pluck a random low number out the air?
What you mean? 0%?


Re: OnPlayerUpdate problem - ReD_HunTeR - 14.03.2015

instead of using it on OnPlayerUpdate try it on this:-

pawn Код:
new UpdatingTimer[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
   UpdatingTimer[playerid] = SetTimerEx("UpdatePlayer", 1000, true, "i", playerid);
   return 1;
}

public OnPlayerDisconnect(playerid)
{
   KillTimer(UpdatingTimer[playerid]);
   return 1;
}

forward UpdatePlayer(playerid);
public UpdatePlayer(playerid);
{
   new string[128], playerid, Float:ratio = floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]);
   format(string, sizeof(string), "~y~Score: ~w~%d~n~~y~Money: ~w~$%d~n~~y~Kills: ~w~%d~n~~y~Deaths: ~w~%d~n~~y~K/D Ratio: ~w~%0.2f", GetPlayerScore(playerid), GetPlayerMoney(playerid), PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], ratio);
   TextDrawSetString(Textdraw[playerid], string);
   TextDrawShowForPlayer(playerid, Textdraw[playerid]);
   return 1;
}



Re: OnPlayerUpdate problem - Fantje - 14.03.2015

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
instead of using it on OnPlayerUpdate try it on this:-

pawn Код:
new UpdatingTimer[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
   UpdatingTimer[playerid] = SetTimerEx("UpdatePlayer", 1000, true, "i", playerid);
   return 1;
}

public OnPlayerDisconnect(playerid)
{
   KillTimer(UpdatingTimer[playerid]);
   return 1;
}

forward UpdatePlayer(playerid);
public UpdatePlayer(playerid);
{
   new string[128], playerid, Float:ratio = floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]);
   format(string, sizeof(string), "~y~Score: ~w~%d~n~~y~Money: ~w~$%d~n~~y~Kills: ~w~%d~n~~y~Deaths: ~w~%d~n~~y~K/D Ratio: ~w~%0.2f", GetPlayerScore(playerid), GetPlayerMoney(playerid), PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], ratio);
   TextDrawSetString(Textdraw[playerid], string);
   TextDrawShowForPlayer(playerid, Textdraw[playerid]);
   return 1;
}
It is already fixed


Re: OnPlayerUpdate problem - Tamer - 14.03.2015

Quote:
Originally Posted by Fantje
Посмотреть сообщение
It is already fixed
I actually can't consider that code "fixed" when it starts calling 30 times a second and you start lagging, listen to what he says and don't put it under OPU.


Re: OnPlayerUpdate problem - Vince - 14.03.2015

It doesn't even need a timer. You can just call that function whenever one of those variables updates. OnPlayerUpdate is not your one-size-fits-all general timer. Do not use timers if you can avoid them.


Re: OnPlayerUpdate problem - Pottus - 14.03.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
It doesn't even need a timer. You can just call that function whenever one of those variables updates. OnPlayerUpdate is not your one-size-fits-all general timer. Do not use timers if you can avoid them.
That is the best way just make it a function like this then call that whenever you need an update.

pawn Код:
UpdateTextDrawStats(playerid)
{
    new string[128], playerid, Float:ratio = floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]);
    format(string, sizeof(string), "~y~Score: ~w~%d~n~~y~Money: ~w~$%d~n~~y~Kills: ~w~%d~n~~y~Deaths: ~w~%d~n~~y~K/D Ratio: ~w~%0.2f", GetPlayerScore(playerid), GetPlayerMoney(playerid), PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], ratio);
    TextDrawSetString(Textdraw[playerid], string);
    TextDrawShowForPlayer(playerid, Textdraw[playerid]);
    return 1;
}