[FilterScript] Admin Check-in system
#1

Admin Check-in by Stev
Hello guys,

Introduction
This is my first filterscript that I have posted on this fourms so here it goes. I did write this in the middle of the night so there might be mistakes I have made

About the script
This filterscript is admin check-in system where when ever a admin is in the serverand they use this command (/checkin), It prints a message into the server logs to say"Stev has checked in at (15:52:3" thats when the timer starts. It moniotors the activenessof the admins. Once the admin has finished his/her duties (/checkout). Once command is sent, it will print in the server longs the following
Код:
[31/05/2015,19.52.38] Stev has checked in (19:52:38) 
[31/05/2015,19.57.51] Stev has checkout after (00 hrs, 04 minutes, 54 secs)
Commands
/checkin - Checks the admin in
/checkout [reason] - Checks the player out with a reason

Screenshots
http://i.imgur.com/UuPwoUo.png
http://i.imgur.com/tAYt9AF.png

Bugs
Nothing as I know.

Download
http://pastebin.com/EX4fFBnZ

Installing
1) Open up the link right above this
2) Copy the text, into a blank .pwn file
3) Make sure you got the include required (zcmd, sscanf) Streamer is not needed
4) Once you got the correct plugins and includes, Compile the script and you should be in the clear!
If you get any errors feel free to ask for help on this thread.

If you have a different admin system, The way to add this into your gamemodes if to change the admin variable on top of the command like so:
Код:
if(PlayerData[playerid][Admin])
// Change it to whatever your admin system finds admin levels.
Credits
Bingo - For thinking of this idea
Reply
#2

Nice work +rep
Reply
#3

Quote:
Originally Posted by Jakwob
Посмотреть сообщение
Nice work +rep
Thank you!
Reply
#4

Tested, Works fine .

Nicely done actually, Glad.
Reply
#5

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:
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;
}
I got to say, I kinda like the concept. Good job, bro!
Reply
#6

Nice!
Reply
#7

I can see this being useful to some people, good job.
Reply
#8

Good job.
Reply
#9

Nice
Reply
#10

Nice idea
Reply
#11

What if an admin got timedout/crashed while on-duty (while check-in is enable)?
Reply
#12

Quote:
Originally Posted by Lucky™
Посмотреть сообщение
What if an admin got timedout/crashed while on-duty (while check-in is enable)?
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:sCheckedIn[MAX_PLAYERS] = false;

// TIMESTAMPS:

new tsCheckedIn[MAX_PLAYERS];

// MAIN:

main()
{
    print("Development Mode: check_in.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    ResetPlayerVariables(playerid);
    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.");

    sCheckedIn[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 ResetPlayerVariables(playerid)
{
    sCheckedIn[playerid] = false;
}

stock IsPlayerCheckIn(playerid)
{
    if(sCheckedIn[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;
}
There's no need to reset the timestamp.
Reply
#13

@ Stev you better update saving/loading with mysql, just suggestion. appreciate it!
Reply
#14

Quote:
Originally Posted by justice96
Посмотреть сообщение
@ Stev you better update saving/loading with mysql, just suggestion. appreciate it!
That's not a bad idea.
Reply
#15

Good job!
Reply
#16

Quote:
Originally Posted by Stev
Посмотреть сообщение
That's not a bad idea.
Where's my suggestion? Not implemented?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)