new payDAY[ MAX_PLAYERS ] = {-1, ...};
forward public Pay_Player( playerid );
#define PAY_EVERY_MINS 5 // pay every 5 minutes
public OnPlayerConnect( playerid )
{
payDAY[ playerid ] = SetTimerEx( "Pay_Player", PAY_EVERY_MINS * 60, 1, "d", playerid );
return 1;
}
public OnPlayerDisconnect( playerid, reason )
{
KillTimer( payDAY[ playerid ] );
return 1;
}
public Pay_Player( playerid )
{
switch( GetPlayerLevel( playerid ) )
{
case 1: GivePlayerMoney( playerid, 500 ), SendClientMessage( playerid, -1, "Received paycheck." );
case 2: ... ;
}
return 1;
}
#define PAYDAY_TIME 3600 // 3600 sec ( 1 hour )
#define PAYDAY_MONEY 1000
forward PayDay();
public PayDay()
{
foreach(Player, i)
{
if(IsPlayerLogged(i))
{
playersData[i][pConnectSec]++;
if(playersData[i][pConnectSec] == PAYDAY_TIME)
{
new money = playersData[i][pLevel] * PAYDAY_MONEY;
GivePlayerMoney(i, money);
playersData[i][pConnectSec] = 0;
SendClientMessage(i, -1, "[SERVER] Payday");
}
}
}
}
public OnGameModeInit()
{
SetTimer("PayDay", 1000, true);
return 1;
}
foreach(Player, i)
{
if(IsPlayerLogged(i))
{
#include <timerfix> // https://sampforum.blast.hk/showthread.php?tid=289675
#include <YSI\y_hooks>
static PayDayTime[MAX_PLAYERS];
// Called when it's a players payday
forward OnPlayerPayDay(playerid);
// Start payday update
hook OnGameModeInit()
{
SetTimer("PayDayUpdate", 60000, true);
return 1;
}
// Reset players payday time when they connect
hook OnPlayerConnect(playerid)
{
PayDayTime[playerid] = gettime();
return 1;
}
// Check for paydays once a minute is good
forward PayDayUpdate();
public PayDayUpdate()
{
foreach(new i : Player)
{
// It's payday!
if(gettime() - PayDayTime[i] >= 3600)
{
PayDayTime[i] = gettime();
CallLocalFunction("OnPlayerPayDay", "i", i);
}
}
return 1;
}
// Set the players payday time (Called from inside gamemode/other includes)
forward SetPayDayTime(playerid);
public SetPayDayTime(playerid) { PayDayTime[playerid] = gettime(); }
// Get the players payday time (Called from inside gamemode/other includes)
forward GetPayDayTime(playerid);
public GetPayDayTime(playerid) { return PayDayTime[playerid]; }
// Used when a player logs in we can restore their payday time
forward UpdatePayDayTime(playerid, seconds);
public UpdatePayDayTime(playerid, seconds) { PayDayTime[playerid] = gettime() - seconds; }
there's a better get_time() technique, but this should work too!
|
if(IsPlayerLogged(i))
@above:
pawn Код:
|
@above:
pawn Код:
|