Timer delay according to gettime()
#5

Quote:
Originally Posted by DOL4N
Посмотреть сообщение
I see. Can you suggest how to execute this properly? The interest income and +score every hour?
i use this way to reward players playing for 1 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
	}
}
you can try it
Reply


Messages In This Thread
Timer delay according to gettime() - by DOL4N - 02.03.2016, 20:19
Re: Timer delay according to gettime() - by Vince - 02.03.2016, 20:41
Re: Timer delay according to gettime() - by DOL4N - 02.03.2016, 20:56
Re: Timer delay according to gettime() - by xEF - 02.03.2016, 21:00
Re: Timer delay according to gettime() - by MeCom - 02.03.2016, 21:01
Re: Timer delay according to gettime() - by DOL4N - 02.03.2016, 21:34
Re: Timer delay according to gettime() - by NaS - 02.03.2016, 22:00

Forum Jump:


Users browsing this thread: 1 Guest(s)