20.09.2011, 16:12
hello i have two qwestion
how can i save player played timer?
and how can i load it?
I Using Y_INI
how can i save player played timer?
and how can i load it?
I Using Y_INI
new PlayingTime[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
PlayingTime[playerid] = GetTickCount(); //To store when the player connected
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
PlayingTime[playerid] = GetTickCount() - PlayingTime[playerid]; // Here we get the difference between when the player joined the game and left the game
return 1;
}
//firs Start a timer that runs every 1 seconds then ito the callback
//start the timer
SetTimerEx("TimeOnServer", 1000, 1, "i", playerid);
forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
PlayerInfo[playerid][Sec] ++;
if(PlayerInfo[playerid][Sec]>=60)
{
PlayerInfo[playerid][Min]++;
PlayerInfo[playerid][Sec]=0;
}
if(PlayerInfo[playerid][Min]>=60)
{
PlayerInfo[playerid][Min]=0;
PlayerInfo[playerid][Hour]++;
}
}
//and that's all you need to have a timer with [hours,mins,sec]
//This is to save it
INI_WriteInt(Acc,"Min",PlayerInfo[playerid][Min]);
INI_WriteInt(Acc,"Hour",PlayerInfo[playerid][Hour]);
INI_WriteInt(Acc,"Sec",PlayerInfo[playerid][Sec]);
//To load it
PlayerInfo[playerid][Min] = GetPVarInt(playerid, "Min");
PlayerInfo[playerid][Hour] = GetPVarInt(playerid, "Hour");
PlayerInfo[playerid][Sec] = GetPVarInt(playerid, "Sec");
SetTimerEx("TimeOnServer", 1000, 1, "i", playerid); |