new FizuIdo; // timer
new fizump[MAX_PLAYERS]; // seconds
forward FizuTimer(playerid);
public FizuTimer(playerid)
{
fizump[playerid]++;
if(fizump[playerid] >= 3600) // 1 hour --
{
new time = gettime() - gPlayerJoin[playerid];
new score = GetPlayerScore(playerid);
new string[128], kamat[128], ora, egyenleg;
ora = (PlayerInfo[playerid][pJatszottIdo]+time)/3600;
egyenleg = PlayerInfo[playerid][pBank];
fizump[playerid] = 0;
...
}
return 1;
}
public OnPlayerSpawn(playerid)
{
gPlayerJoin[playerid] = gettime();
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
fizump[playerid] = PlayerInfo[playerid][pFizetesOra]; // load saved seconds
FizuIdo = SetTimer("FizuTimer", 1000, 1); // paycheck timer start again
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(FizuIdo); // shall this be after saving timer seconds? (line above return 1)
new time = gettime() - gPlayerJoin[playerid];
new jOra = (PlayerInfo[playerid][pJatszottIdo]+time)/3600;
new jPerc = (PlayerInfo[playerid][pJatszottIdo]+time)/60;
new jMp = PlayerInfo[playerid][pJatszottIdo]+time-(60*jPerc);
...
INI_WriteInt(File, "Уra", jOra);
INI_WriteInt(File, "Perc", jPerc);
INI_WriteInt(File, "Mбsodperc", jMp);
INI_WriteInt(File, "JбtszottIdő", PlayerInfo[playerid][pJatszottIdo] + time);
INI_WriteInt(File, "FizetйsУra", fizump[playerid]); // SAVING TIMER SECONDS
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == dialog_register)
{
...
INI_WriteInt(File, "JбtszottIdő", 0); // saving played seconds
INI_WriteInt(File, "FizetйsУra", 0); // saving timer seconds
}
if(dialogid == dialog_login)
{
fizump[playerid] = PlayerInfo[playerid][pFizetesOra]; // loading timer seconds
}
return 1;
}
|
I see. Can you suggest how to execute this properly? The interest income and +score every hour?
|
enum pInfo
{
pSecs,
pMins,
pHours
}
new PlayerInfo[MAX_PLAYERS][pInfo];
public OnGameModeInit()
{
SetTimer("PlayedHours", 1000, 1); //sets timer to call every 1 second
return 1;
}
//saving
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Mins",PlayerInfo[playerid][pMins]);
INI_WriteInt(File,"Hours",PlayerInfo[playerid][pHours]);
INI_WriteInt(File,"Secs",PlayerInfo[playerid][pSecs]);
INI_Close(File);
return 1;
}
//loading
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Mins",PlayerInfo[playerid][pMins]);
INI_Int("Hours",PlayerInfo[playerid][pHours]);
INI_Int("Secs",PlayerInfo[playerid][pSecs]);
return 1;
}
forward PlayedHours(playerid);
public PlayedHours(playerid)
{
PlayerInfo[playerid][pSecs] ++; // +1 second evertime timer "playedhours" calls
if(PlayerInfo[playerid][pSecs]>=60)//untill reaches 60
{
PlayerInfo[playerid][pSecs]=0; //resets seconds to 0
PlayerInfo[playerid][pMins]++; // +1 min
}
if(PlayerInfo[playerid][pMins]>=60) //untill reaches 60
{
PlayerInfo[playerid][pMins]=0; //resets minutes to 0
PlayerInfo[playerid][pHours]++; // +1 hour
//reward the player for completeing 1 hour
}
}
#define REWARD_TIME 3600000 // ms, one hour new tPlayerLogin[MAX_PLAYERS];
tPlayerLogin[playerid] = GetTickCount();
forward PlayedTimer();
public PlayedTimer()
{
new curTick = GetTickCount();
for(new playerid = 0; playerid < GetMaxPlayers(); playerid ++) // Could be replaced by foreach
{
if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid)) continue;
new timedif = curTick - tPlayerLogin[playerid];
if(timedif > REWARD_TIME)
{
tPlayerLogin[playerid] += REWARD_TIME;
// Code to do when he played another hour
}
}
}