PDA

View Full Version : PROBLEM TIMER SYNC! CRASH


Metharon
19/05/2014, 10:57 AM
[14:17:19] [debug] Server crashed while executing ls-cp.amx
[14:17:19] [debug] AMX backtrace:
[14:17:19] [debug] #0 native SetTimer () [004714a0] from samp-server.exe
[14:17:19] [debug] #1 000343c0 in public TimeSync () from ls-cp.amx
[14:17:19] [debug] Native backtrace:
[14:17:19] [debug] #0 0047e5c1 in ?? () from samp-server.exe
[14:17:19] [debug] #1 77bceec0 in ?? ()




new synctimer;
#pragma unused synctimer
public OnGameModeInit()
{
synctimer = SetTimer("TimeSync", 60000, 1);

}



forward TimeSync();
public TimeSync()
{
new Hour, Minute;
gettime(Hour, Minute);
if(Minute == 00)
{
ActualizareVreme();
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (EsteLogat[playerid] == 1) { Payday(playerid); }
}
}
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
new actualtimeonline = OnlineTime[playerid];
OnlineTime[playerid] = actualtimeonline + 1;
}
synctimer = SetTimer("TimeSync", 60000, 1);
}
forward Payday(playerid);
public Payday(playerid)
{
if(OnlineTime[playerid] > 10)
{
if(EsteLogat[playerid] == 1)
{
new string[456];
ClearChat(playerid);
OnlineTime[playerid] = 0;
new oldbank = PlayerInfo[playerid][ValutaBancara];
new ore = PlayerInfo[playerid][OreJucate];
PlayerInfo[playerid][OreJucate] = ore + 1;
new salariul = PlayerInfo[playerid][Salariul];
// new Taxa = PlayerInfo[playerid][Amenda];
new newmoney = PlayerInfo[playerid][ValutaBancara] + GetPlayerMoney(playerid);
new oldrp = PlayerInfo[playerid][pNivel];
PlayerInfo[playerid][pNivel] = oldrp + 1;
new Hour, Minute;
gettime(Hour, Minute);
format(string, sizeof(string), " ~G~+ %d $", salariul);
PlayerTextDrawSetString(playerid, v1PaydayTD3[playerid], string);
format(string, sizeof(string), " ~R~- 50000 $"); //taxa
PlayerTextDrawSetString(playerid, v1PaydayTD5[playerid], string);
PlayerInfo[playerid][ValutaBancara] = oldbank + salariul;
format(string, sizeof(string), "~G~ 999999999 $", newmoney);
PlayerTextDrawSetString(playerid, v1PaydayTD5[playerid], string);
format(string, sizeof(string), "~y~Payday ~N~~w~paycheck~N~+%d$", salariul);
GameTextForPlayer(playerid, string, 5000, 1);
TextDrawShowForPlayer(playerid, v1PaydayTD0);
TextDrawShowForPlayer(playerid, v1PaydayTD1);
TextDrawShowForPlayer(playerid, v1PaydayTD2);
TextDrawShowForPlayer(playerid, v1PaydayTD4);
TextDrawShowForPlayer(playerid, v1PaydayTD6);
PlayerTextDrawShow(playerid, v1PaydayTD3[playerid]);
PlayerTextDrawShow(playerid, v1PaydayTD5[playerid]);
PlayerTextDrawShow(playerid, v1PaydayTD7[playerid]);
}
new string[456];
format(string, sizeof(string), "~r~Ai pierdut~N~~y~payday");
GameTextForPlayer(playerid, string, 5000, 1);


}

}
forward ActualizareVreme();
public ActualizareVreme()
{
new Hour, Minute;
gettime(Hour, Minute);
if(Hour==0)
{
SetWorldTime(0);
SetWeather(0);

}
else if(Hour==1)
{
SetWorldTime(1);
SetWeather(1);

}
else if(Hour==2)
{
SetWorldTime(2);
SetWeather(2);

}
else if(Hour==3)
{
SetWorldTime(3);
SetWeather(3);


}
else if(Hour==4)
{
SetWorldTime(4);
SetWeather(4);

}
else if(Hour==5)
{
SetWorldTime(5);
SetWeather(5);


}
else if(Hour==6)
{
SetWorldTime(6);
SetWeather(6);


}
else if(Hour==7)
{
SetWorldTime(7);
SetWeather(7);


}
else if(Hour==8)
{
SetWorldTime(8);
SetWeather(8);


}
else if(Hour==9)
{
SetWorldTime(9);
SetWeather(9);


}
else if(Hour==10)
{
SetWorldTime(10);
SetWeather(10);


}
else if(Hour==11)
{
SetWorldTime(11);
SetWeather(11);


}
else if(Hour==12)
{
SetWorldTime(12);
SetWeather(12);


}
else if(Hour==13)
{
SetWorldTime(13);
SetWeather(13);


}
else if(Hour==14)
{
SetWorldTime(14);
SetWeather(14);


}
else if(Hour==15)
{
SetWorldTime(15);
SetWeather(15);


}
else if(Hour==16)
{
SetWorldTime(16);
SetWeather(16);


}
else if(Hour==17)
{
SetWorldTime(17);
SetWeather(17);


}
else if(Hour==18)
{
SetWorldTime(18);
SetWeather(18);


}
else if(Hour==19)
{
SetWorldTime(19);
SetWeather(19);


}
else if(Hour==20)
{
SetWorldTime(20);
SetWeather(20);


}
else if(Hour==21)
{
SetWorldTime(0);
SetWeather(2);


}
else if(Hour==22)
{
SetWorldTime(0);
SetWeather(2);


}
else if(Hour==23)
{
SetWorldTime(0);
SetWeather(2);


}

return 1;
}

Konstantinos
19/05/2014, 11:11 AM
I'm not aware of what exactly caused the crash with the SetTimer function but here's few things that you shouldn't have done them in that way:

- Don't use #pragma unused synctimer because you use that variable for storing the timer's ID.
- You set the timer as repeated and whenever it gets called, you set it over and over again to repeated (basically you get more timers running with that instead of 1 you need).
- You don't have to loop twice through the players - 1 loop and in fact, using foreach is recommended.

Metharon
19/05/2014, 11:29 AM
umm ok .. i will try .. other tips to fix it ?