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=408561)
OnPlayerUpdate Problem. -
shady001 - 18.01.2013
So i use OnPlayerUpdate() to update a speedometer and a fuel indicator. But after some time it just stop working , The TextDraw just disapear and won't show again until i restart my server.
This is what i have on OnPlayerUpdate();
PHP код:
new Float:fPos[3],Float:Pos[4][2],Float:fSpeed;
new vehicle = GetPlayerVehicleID(playerid);
new string2[64];
if(IsPlayerInAnyVehicle(playerid))
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
format(string2,sizeof(string2),"F:%d",CarFuel[vehicle]);
TextDrawSetString(FuelTextDraw[playerid], string2);
new distance = GetDistance1(x, y, z, PlayerPos[0][playerid], PlayerPos[1][playerid], PlayerPos[2][playerid]);
PlayerPos[0][playerid] = x;
PlayerPos[1][playerid] = y;
PlayerPos[2][playerid] = z;
PlayerTotalDistance[playerid] += distance;
if (PlayerTotalDistance[playerid] > DISTANCE) {
CarFuel[vehicle] -= FUEL_INCREMENT;
PlayerTotalDistance[playerid] = 0;
}
if (CarFuel[vehicle] < 0) {
SendClientMessage(playerid, -1, "You have been forced out your vehicle because you have no gas!");
RemovePlayerFromVehicle(playerid);
}
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
GetVehicleVelocity(GetPlayerVehicleID(playerid), fPos[0], fPos[1], fPos[2]);
fSpeed = floatsqroot(floatpower(fPos[0], 2) + floatpower(fPos[1], 2) +
floatpower(fPos[2], 2)) * 200;
new Float:alpha = 320 - fSpeed;
if(alpha < 60)
alpha = 60;
for(new i; i < 4; i++)
{
TextDrawHideForPlayer(playerid, TextDrawsd[playerid][i]);
TextDrawDestroy(TextDrawsd[playerid][i]);
GetDotXY(548, 401, Pos[i][0], Pos[i][1], alpha, (i + 1) * 8);
TextDrawsd[playerid][i] = TextDrawCreate(Pos[i][0], Pos[i][1], "~b~.");
TextDrawLetterSize(TextDrawsd[playerid][i], 0.73, -2.60);
TextDrawSetOutline(TextDrawsd[playerid][i], 0);
TextDrawSetShadow(TextDrawsd[playerid][i], 1);
TextDrawShowForPlayer(playerid, TextDrawsd[playerid][i]);
}
}
return 1;
Re: OnPlayerUpdate Problem. -
mineralo - 18.01.2013
don't destroy and create every time but use TextDrawSetString
https://sampwiki.blast.hk/wiki/TextDrawSetString
Re: OnPlayerUpdate Problem. -
shady001 - 18.01.2013
Ok, i'l try this , but on fuel i don't destroy it .. and still disapear ... this usualy happends after like an hour after the server starts ..
Edit: and that "." i need to destroy it and create it again because i need it to be on another position .. i don't know how else to do this. Whit SetString it only modify the string but not the position.
Re: OnPlayerUpdate Problem. -
shady001 - 20.01.2013
Can someone help? everything i put in onplayerupdate stop working after a few hours ... i tried making another speedometer and that stop working to . Please some help.