01.06.2015, 23:09
Technically, this isn't a filterscript, just because you didn't add OnFilterScriptInit() and OnFilterScriptExit(). Instead you added OnGameModeInit(), OnGameModeExit() and main(), making it a gamemode rather than a filterscript.
You are using a timer to retrieve the time a player has been online for, which can be replaced with timestamps. You are using pVars, which aren't needed at all here, while this can be reestablished with per-player variables. You have left all the default callbacks in the script, even if they are not being used, you just don't need them there if you aren't going to use them. And so on...
Anyway, here's an improved version of your filterscript:
I got to say, I kinda like the concept. Good job, bro!
You are using a timer to retrieve the time a player has been online for, which can be replaced with timestamps. You are using pVars, which aren't needed at all here, while this can be reestablished with per-player variables. You have left all the default callbacks in the script, even if they are not being used, you just don't need them there if you aren't going to use them. And so on...
Anyway, here's an improved version of your filterscript:
pawn Код:
// [ DEVELOPMENT GAMEMODE ]
// INCLUDES
#include <a_samp>
#include <zcmd>
#include <sscanf2>
// DEFINES:
// GENERAL:
#define CHECKED_IN_PATH "checked_in.ini"
// FUNCTIONS:
#define function%0(%1) forward%0(%1); public%0(%1)
#define plural_singular(%0,%1,%2) ((%0) == 1)?((#%1)):((#%2))
// COLORS:
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_ORED 0xFF0000FF
// PER-PLAYER VARAIBLES:
// STATES:
new bool:sCheckIn[MAX_PLAYERS] = false;
// TIMESTAMPS:
new tsCheckedIn[MAX_PLAYERS];
// CALLBACKS:
public OnFilterScriptInit()
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
// COMMANDS:
CMD:checkin(playerid)
{
if(IsPlayerAdmin(playerid)) return 0;
if(IsPlayerCheckIn(playerid)) return SendClientMessage(playerid, COLOR_ORED, "You are already check in, you cannot use this command.");
new string[144], hour, minute, second;
gettime(hour, minute, second);
format(string, sizeof(string), ">> %s has checked in (%02d:%02d:%02d).\r\n", PlayerName(playerid), hour, minute, second);
AddNIString(CHECKED_IN_PATH, string);
SendClientMessage(playerid, COLOR_YELLOW, "You have checked in, use /checkout when you had enough.");
sCheckIn[playerid] = true;
tsCheckedIn[playerid] = gettime();
return 1;
}
CMD:checkout(playerid, params[])
{
if(IsPlayerAdmin(playerid)) return 0;
if(!IsPlayerCheckIn(playerid)) return SendClientMessage(playerid, COLOR_ORED, "You aren't checked in, you cannot use this command.");
new string[256], reason[128];
if(sscanf(params, "s[128]", reason)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /checkout [reason].");
format(string, sizeof(string),"You have checked out (Reason: %s).", reason);
SendClientMessage(playerid, COLOR_YELLOW, string);
new second = gettime() - tsCheckedIn[playerid], minute, hour, day, week, month, year;
format(string, sizeof(string),">> %s has checked out after %s.\r\n", PlayerName(playerid), ConvertToTime(second, minute, hour, day, week, month, year));
AddNIString(CHECKED_IN_PATH, string);
return 1;
}
// FUNCTIONS:
stock IsPlayerCheckIn(playerid)
{
if(sCheckIn[playerid]) return true;
return false;
}
stock PlayerName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
return name;
}
function AddNIString(file[], string[])
{
new File:inifile;
inifile = fopen(file, io_append);
if(!inifile)
{
printf("Fatal Error: Couldn't open \"%s\"!", file);
return 0;
}
fwrite(inifile, string);
fclose(inifile);
return 0;
}
stock ConvertToTime(&second, &minute = -1, &hour = -1, &day = -1, &week = -1, &month = -1, &year = -1)
{
#define seconds_in_year 31536000
#define seconds_in_month 2628000
#define seconds_in_week 604800
#define seconds_in_day 86400
#define seconds_in_hour 3600
#define seconds_in_minute 60
#define convert_seconds(%1) %1 = second / seconds_in_%1; second %= seconds_in_%1
new string[128];
if(year != -1 && (second / seconds_in_year))
{
convert_seconds(year); convert_seconds(month); convert_seconds(week); convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, %d %s, %d %s, and %d %s", year, plural_singular(year, "year", "years"), month, plural_singular(month, "month", "months"), \
week, plural_singular(week, "week", "weeks"), day, plural_singular(day, "day", "days"), hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), \
second, plural_singular(second, "second", "seconds"));
return string;
}
if(month != -1 && (second / seconds_in_month))
{
year = 0; convert_seconds(month); convert_seconds(week); convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, %d %s, and %d %s", month, plural_singular(month, "month", "months"), week, plural_singular(week, "week", "weeks"), \
day, plural_singular(day, "day", "days"), hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
return string;
}
if(week != -1 && (second / seconds_in_week))
{
year = 0, month = 0; convert_seconds(week); convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, and %d %s", week, plural_singular(week, "week", "weeks"), day, plural_singular(day, "day", "days"), \
hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
return string;
}
if(day != -1 && (second / seconds_in_day))
{
year = 0, month = 0, week = 0; convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
format(string, sizeof(string), "%d %s, %d %s, %d %s, and %d %s", day, plural_singular(day, "day", "days"), hour, plural_singular(hour, "hour", "hours"), \
minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
return string;
}
if(hour != -1 && (second / seconds_in_hour))
{
year = 0, month = 0, week = 0, day = 0; convert_seconds(hour); convert_seconds(minute);
format(string, sizeof(string), "%d %s, %d %s, and %d %s", hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), \
second, plural_singular(second, "second", "seconds"));
return string;
}
if(minute != -1 && (second / seconds_in_minute))
{
year = 0, month = 0, week = 0, day = 0, hour = 0; convert_seconds(minute);
format(string, sizeof(string), "%d %s, and %d %s", minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
return string;
}
year = 0, month = 0, week = 0, day = 0, hour = 0, minute = 0;
format(string, sizeof(string), "%d %s", second, plural_singular(second, "second", "seconds"));
return string;
}