OnPlayerUpdate problem
#1

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.
Reply
#2

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.
Reply
#3

Haha you can see my sign
Reply
#4

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?
Reply
#5

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%?
Reply
#6

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;
}
Reply
#7

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
Reply
#8

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.
Reply
#9

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.
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)