Timer doesn't work - 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: Timer doesn't work (
/showthread.php?tid=448004)
Timer doesn't work -
Louris - 02.07.2013
Sign shows current vehicle speed, but it doesn't update just keeps flashing every second, why?
Код:
public OnGameModeInit()
{
SetTimer("speed", 1000, true);
}
Код:
forward speed();
public speed()
{
new stri[128];
for(new i = 0; i < MAX_PLAYERS; i++)
format(stri,128,"Jusu greitis\n%d",GetPlayerSpeed(i,true));
SetObjectMaterialText(objektas,stri, 0, OBJECT_MATERIAL_SIZE_256x128,\
"Arial", 55, 0, 0xB8860BAA, 0xFF000000, OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
}
How sign looks like :
http://www.part.lt/perziura/de3f992c...04854a7967.png
(It means "Your speed")
Re: Timer doesn't work -
shadowdog - 02.07.2013
This gets the speed of EVERY player in the server, even ones that are not connected.
You should use something that finds the closest player to your sign.
and replace this with your 'i'.
Re: Timer doesn't work -
Pottus - 02.07.2013
Of course again like your other post this code won't work, you need to delete/recreate objektas each time you update SetObjectMaterialText().
Re: Timer doesn't work -
Louris - 03.07.2013
Ok, now it works, but creates a lot of objects and keeps flashing and it cause lag.. If i destroyobject sign just show 0.
Re: Timer doesn't work -
Louris - 03.07.2013
Any ideas?
Re: Timer doesn't work -
Cjgogo - 03.07.2013
Just make a timer for each player, and that's it:
pawn Код:
new uSpeed[MAX_PLAYERS];
forward Speed(playerid);
public OnPlayerConnect(playerid)
{
uSpeed[playerid]=SetTimerEx("Speed",1000,true,"i",playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(uSpeed[playerid]);
return 1;
}
public Speed(playerid)
{
new string[128];
format(string,128,"Jusu greitis\n%d",GetPlayerSpeed(playerid));
SetObjectMaterialText(objektas,stri, 0, OBJECT_MATERIAL_SIZE_256x128,\"Arial", 55, 0, 0xB8860BAA, 0xFF000000, OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
return 1;
}
Re: Timer doesn't work -
Louris - 03.07.2013
Quote:
Originally Posted by Cjgogo
Just make a timer for each player, and that's it:
pawn Код:
new uSpeed[MAX_PLAYERS]; forward Speed(playerid); public OnPlayerConnect(playerid) { uSpeed[playerid]=SetTimerEx("Speed",1000,true,"i",playerid); return 1; }
public OnPlayerDisconnect(playerid, reason) { KillTimer(uSpeed[playerid]); return 1; }
public Speed(playerid) { new string[128]; format(string,128,"Jusu greitis\n%d",GetPlayerSpeed(playerid)); SetObjectMaterialText(objektas,stri, 0, OBJECT_MATERIAL_SIZE_256x128,\"Arial", 55, 0, 0xB8860BAA, 0xFF000000, OBJECT_MATERIAL_TEXT_ALIGN_CENTER); return 1; }
|
Always shows 0