Timer doesn't work
#1

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")
Reply
#2

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

Of course again like your other post this code won't work, you need to delete/recreate objektas each time you update SetObjectMaterialText().
Reply
#4

Ok, now it works, but creates a lot of objects and keeps flashing and it cause lag.. If i destroyobject sign just show 0.
Reply
#5

Any ideas?
Reply
#6

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)