I Hate Timers :(
#1

Hi scrpterz !

I'm stuck with this timers and i can't find solution how to solve them

My problem is following:

I have 6 timers who are repeating for every online player...
Код:
OnGameModeInIt()
{	
for(new i; i != GetMaxPlayers(); i++)
	{
		SetTimerEx("Speedometer", 100, true, "d", i);
		SetTimerEx("HPWCGLAD", 150000, true, "d", i);
		SetTimerEx("BolnicaTimerce", 1000, true, "d", i);
		//============== [ LEVEL SISTEM ] ===============//
    		SetTimerEx("exptimer", 60000, true, "d", i);
    		SetTimerEx("ExpUpdate", 100, true, "d", i);
		//============== [ LEVEL SISTEM ] ===============//
		SetTimerEx("RandomMessage", 8000, true, "d", i);
	}
}
But they are causing serious lag and they work perfect...

So i have tried something like this:
Код:
SetTimer("Speedometer", 100, true); // under OnGameModeInIt
and the code in the timer:
Код:
public Speedometer()
{
	foreach (new i : Player)
	{
		if(IsPlayerInAnyVehicle(i))
		{
			TextDrawShowForPlayer(i, Speedo0[i]);
			TextDrawShowForPlayer(i, Speedo1[i]);
			TextDrawShowForPlayer(i, Speedo2[i]);
			TextDrawShowForPlayer(i, Speedo3[i]);
			TextDrawShowForPlayer(i, Speedo4[i]);
			TextDrawShowForPlayer(i, Speedo5[i]);
			TextDrawShowForPlayer(i, Speedo6[i]);
			TextDrawShowForPlayer(i, Speedo7[i]);
			TextDrawShowForPlayer(i, Speedo8[i]);
			TextDrawShowForPlayer(i, Speedo9[i]);
			TextDrawShowForPlayer(i, Speedo10[i]);
			TextDrawShowForPlayer(i, Speedo11[i]);
			TextDrawShowForPlayer(i, Speedo12[i]);
			TextDrawShowForPlayer(i, Speedo13[i]);
		}
	}
}
The textdraw isn't showing on my server where i have 30-50 players, but on my local server it works -.- ?!?!
What is the problem ?
Reply
#2

Try replacing
Код:
foreach (new i : Player)
with this
Код:
foreach(Player, i)
And about the lag, it's because you use 100 miliseconds it would be better if you'd use 1000 like this
Код:
SetTimerEx("Speedometer", 1000, true, "d", i);
Reply
#3

Quote:
Originally Posted by RALL0
Посмотреть сообщение
Try replacing
Код:
foreach (new i : Player)
with this
Код:
foreach(Player, i)
And about the lag, it's because you use 100 miliseconds it would be better if you'd use 1000 like this
Код:
SetTimerEx("Speedometer", 1000, true, "d", i);
I dont know i downloaded the new foreach: https://sampforum.blast.hk/showthread.php?tid=92679 and i found from there that i should put foreach (new i : Player)...

I know that the speed of the timer is causing lag, but i want to make it global Timer because now its a timer per player (SetTimerEx) and it starts 50 times (my server is 50 slots), But when i make it global Timer the timer doesn't work with foreach... One timer is better than 50 timers

So my question is how to make it global timer and to work like it works now...
Reply
#4

Why do you need that timer?
Use OnPlayerStateChange like:
pawn Код:
if(newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER)
{
                        TextDrawShowForPlayer(playerid, Speedo0[playerid);
            TextDrawShowForPlayer(playerid, Speedo1[playerid]);
            TextDrawShowForPlayer(playerid, Speedo2[playerid]);
            TextDrawShowForPlayer(playerid,Speedo3[playerid]);
            TextDrawShowForPlayer(playerid, Speedo4[playerid]);
            TextDrawShowForPlayer(playerid, Speedo5[playerid]);
            TextDrawShowForPlayer(playerid, Speedo6[playerid]);
            TextDrawShowForPlayer(playerid, Speedo7[playerid]);
            TextDrawShowForPlayer(playerid, Speedo8[playerid]);
            TextDrawShowForPlayer(playerid, Speedo9[playerid]);
            TextDrawShowForPlayer(playerid, Speedo10[playerid]);
            TextDrawShowForPlayer(playerid, Speedo11[playerid]);
            TextDrawShowForPlayer(playerid, Speedo12[playerid]);
            TextDrawShowForPlayer(playerid, Speedo13[playerid]);
}
if(oldstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSANGER)
{
                        TextDrawHideForPlayer(playerid, Speedo0[playerid);
            TextDrawHideForPlayer(playerid, Speedo1[playerid]);
            TextDrawHideForPlayer(playerid, Speedo2[playerid]);
            TextDrawHideForPlayer(playerid,Speedo3[playerid]);
            TextDrawHideForPlayer(playerid, Speedo4[playerid]);
            TextDrawHideForPlayer(playerid, Speedo5[playerid]);
            TextDrawHideForPlayer(playerid, Speedo6[playerid]);
            TextDrawHideForPlayer(playerid, Speedo7[playerid]);
            TextDrawHideForPlayer(playerid, Speedo8[playerid]);
            TextDrawHideForPlayer(playerid, Speedo9[playerid]);
            TextDrawHideForPlayer(playerid, Speedo10[playerid]);
            TextDrawHideForPlayer(playerid, Speedo11[playerid]);
            TextDrawHideForPlayer(playerid, Speedo12[playerid]);
            TextDrawHideForPlayer(playerid, Speedo13[playerid]);
}
Reply
#5

Quote:
Originally Posted by Aly
Посмотреть сообщение
Why do you need that timer?
Use OnPlayerStateChange like:
pawn Код:
if(newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER)
{
                        TextDrawShowForPlayer(playerid, Speedo0[playerid);
            TextDrawShowForPlayer(playerid, Speedo1[playerid]);
            TextDrawShowForPlayer(playerid, Speedo2[playerid]);
            TextDrawShowForPlayer(playerid,Speedo3[playerid]);
            TextDrawShowForPlayer(playerid, Speedo4[playerid]);
            TextDrawShowForPlayer(playerid, Speedo5[playerid]);
            TextDrawShowForPlayer(playerid, Speedo6[playerid]);
            TextDrawShowForPlayer(playerid, Speedo7[playerid]);
            TextDrawShowForPlayer(playerid, Speedo8[playerid]);
            TextDrawShowForPlayer(playerid, Speedo9[playerid]);
            TextDrawShowForPlayer(playerid, Speedo10[playerid]);
            TextDrawShowForPlayer(playerid, Speedo11[playerid]);
            TextDrawShowForPlayer(playerid, Speedo12[playerid]);
            TextDrawShowForPlayer(playerid, Speedo13[playerid]);
}
if(oldstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSANGER)
{
                        TextDrawHideForPlayer(playerid, Speedo0[playerid);
            TextDrawHideForPlayer(playerid, Speedo1[playerid]);
            TextDrawHideForPlayer(playerid, Speedo2[playerid]);
            TextDrawHideForPlayer(playerid,Speedo3[playerid]);
            TextDrawHideForPlayer(playerid, Speedo4[playerid]);
            TextDrawHideForPlayer(playerid, Speedo5[playerid]);
            TextDrawHideForPlayer(playerid, Speedo6[playerid]);
            TextDrawHideForPlayer(playerid, Speedo7[playerid]);
            TextDrawHideForPlayer(playerid, Speedo8[playerid]);
            TextDrawHideForPlayer(playerid, Speedo9[playerid]);
            TextDrawHideForPlayer(playerid, Speedo10[playerid]);
            TextDrawHideForPlayer(playerid, Speedo11[playerid]);
            TextDrawHideForPlayer(playerid, Speedo12[playerid]);
            TextDrawHideForPlayer(playerid, Speedo13[playerid]);
}
Ok i will put the textdraws there but that is not the full code of that timer i just paste here the textdraws, under that code is more stuff...
Here is the rest of the code
Код:
public Speedometer()
{
	new Hour, Minute, Second;
	gettime(Hour, Minute, Second);
	new saat = Hour+1;
	SetWorldTime(saat);
	SetWeather(2);
	foreach (new i : Player)
	{
		if(IsPlayerInAnyVehicle(i))
		{
			TextDrawShowForPlayer(i, Speedo0[i]);
			TextDrawShowForPlayer(i, Speedo1[i]);
			TextDrawShowForPlayer(i, Speedo2[i]);
			TextDrawShowForPlayer(i, Speedo3[i]);
			TextDrawShowForPlayer(i, Speedo4[i]);
			TextDrawShowForPlayer(i, Speedo5[i]);
			TextDrawShowForPlayer(i, Speedo6[i]);
			TextDrawShowForPlayer(i, Speedo7[i]);
			TextDrawShowForPlayer(i, Speedo8[i]);
			TextDrawShowForPlayer(i, Speedo9[i]);
			TextDrawShowForPlayer(i, Speedo10[i]);
			TextDrawShowForPlayer(i, Speedo11[i]);
			TextDrawShowForPlayer(i, Speedo12[i]);
			TextDrawShowForPlayer(i, Speedo13[i]);
			new vehicleid = GetPlayerVehicleID(i);
			if(vehicleid != 0)
			{
				new brzinastring[64];
				new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(i),0));
				format(brzinastring,sizeof(brzinastring),"%i",speed);
				TextDrawSetString(Speedo1[i], brzinastring);
				new vozilostring[64];
				format(vozilostring,sizeof(vozilostring),"%s", VehNames[GetVehicleModel(vehicleid) - 400]);
				TextDrawSetString(Speedo3[i], vozilostring);
			    new Float:vh;
			    new h, jacinastring[64];
			    GetVehicleHealth(vehicleid, vh);
			    h = floatround(vh) / 10;
			 	if(h >= 75)
	 			{
	    			format(jacinastring, sizeof(jacinastring), "%d\%", h); //55 -> Orange, 30 -> Red
	    			TextDrawSetString(Speedo5[i], jacinastring);
				}
	 			if(h >= 50 && h <= 74)
	 			{
	    			format(jacinastring, sizeof(jacinastring), "~y~%d\%", h); //55 -> Orange, 30 -> Red
	    			TextDrawSetString(Speedo5[i], jacinastring);
				}
	 			if(h >= 0 && h <= 49)
	 			{
	    			format(jacinastring, sizeof(jacinastring), "~r~%d\%", h); //55 -> Orange, 30 -> Red
	    			TextDrawSetString(Speedo5[i], jacinastring);
				}
				new gorivostring[64];
			    format(gorivostring, sizeof(gorivostring), "%d litri", Gas[vehicleid]); //55 -> Orange, 30 -> Red
			    TextDrawSetString(Speedo7[i], gorivostring);
				new gpsstring[64];
				new Zona[MAX_ZONE_NAME];
				GetPlayer2DZone(i, Zona, MAX_ZONE_NAME);
			    format(gpsstring, sizeof(gpsstring), "%s", Zona); //55 -> Orange, 30 -> Red
			    TextDrawSetString(Speedo11[i], gpsstring);
				new rtext[24];
				if(Registrirano[vehicleid] == 1)
				{
				    rtext = "Da";
				}
				if(Registrirano[vehicleid] == 0)
				{
				    rtext = "~r~Ne";
				}
				new regstring[64];
 	 			format(regstring, sizeof(regstring), "%s", rtext); //55 -> Orange, 30 -> Red
	    		TextDrawSetString(Speedo9[i], regstring);
				new kmstring[64];
	    		format(kmstring, sizeof(kmstring), "%.02f", KMPominati[vehicleid] * 0.000621); //55 -> Orange, 30 -> Red
	    		TextDrawSetString(Speedo13[i], kmstring);
				if(ConvertVehIDtoDYID(vehicleid) != -1)
	 			{
	 			    new vozilo = ConvertVehIDtoDYID(vehicleid);
					GetPlayerPos(i,x2km[i],y2km[i],z2km[i]);
   					temper[i] = floatsqroot(floatpower(floatabs(floatsub(xkm[i],x2km[i])),2)+floatpower(floatabs(floatsub(ykm[i],y2km[i])),2)+floatpower(floatabs(floatsub(zkm[i],z2km[i])),2));
   					MyVehicle[vozilo][MyVehKM] += temper[i];
					KMPominati[vehicleid] = MyVehicle[vozilo][MyVehKM];
   					xkm[i] = x2km[i];
   					ykm[i] = y2km[i];
   					zkm[i] = z2km[i];
   					UpdateMyVehSystem(vozilo);
					return 1;
				}
				GetPlayerPos(i,x2km[i],y2km[i],z2km[i]);
   				temper[i] = floatsqroot(floatpower(floatabs(floatsub(xkm[i],x2km[i])),2)+floatpower(floatabs(floatsub(ykm[i],y2km[i])),2)+floatpower(floatabs(floatsub(zkm[i],z2km[i])),2));
   				KMPominati[vehicleid] += temper[i];
   				xkm[i] = x2km[i];
   				ykm[i] = y2km[i];
   				zkm[i] = z2km[i];
			}
		}
		else
		{
		    if(RentaMotor[i] == 1)
		    {
		    	KillTimer(RentanjeTimer[i]);
		    	KillTimer(RentanjeTimer1[i]);
		    	RentaMotor[i] = 0;
		    }
		}
 	}
 	return 1;
}
At the other timers which i have mentioned on the top i have codes in them to update the textdraws, but when i make them global timers they don't update...
Reply
#6

As far as I know you don't need a new local variable, you can try it it works fine with me.
Reply
#7

Put the textdraws as I said and increase the timer to 1000 ms.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)