/aduty Timer Help
#1

So i want so when an admin does "/aduty" an timer would start and after 1 hour on-duty they will recive a admin token, if they keep being on-duty the timer restarts. But when they do /aduty again to go off-duty the timer should be killed and no token should be given to the staff.
Reply
#2

Hello there,

The functions you should use are;
SetTimerEx, give an ID to the timer such as this;

pawn Код:
new dutytimer[MAX_PLAYERS];

// Your aduty command here
{
// bla bla bla
new dutytime = 60*1000*60;
dutytimer[playerid] = SetTimerEx("DutyToken",dutytime,true,"i",playerid); // Here, we set a timer which loops unless killed, with function being called as "DutyToken", dutytime calculates the time.
return 1;
}
Then;

pawn Код:
forward DutyToken(playerid);
public DutyToken(playerid)
{
SendClientMessage(playerid,-1,"{00FF00}[INFO]: {FFFFFF}You have been on aduty for 1 hour and have obtained a token.");
pInfo[playerid][DutyToken]++;// Change it to your variable.
return 1;
}
This is basically very basic and simple system from me, you can make it advanced for your needs.

Edit: When the admin goes off duty just simply type this below that code;

pawn Код:
KillTimer(dutytimer[playerid]);
Reply
#3

Hello, eh created a system which will tell you how many seconds or minutes you were on duty, I don't recommend using timers, could cause a delay in your server, I can assure you that is very optimized and that works .

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript

#define FILTERSCRIPT

#if defined FILTERSCRIPT

#include <a_samp>
#include <YSI\y_timers>
#include <YSI\y_commands>

new bool:player_duty[MAX_PLAYERS];
new time_duty[MAX_PLAYERS];


public OnFilterScriptInit()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        player_duty[i] = false;
        time_duty[i] = 0;
    }
    return true;
}

CMD:duty(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new string[144];
        if(player_duty[playerid] != true)
        {
            strdel(string, 0, 144);
            format(string, sizeof(string), "** %s has been duty.", Name(playerid));
            SendClientMessageToAll(-1, string);
            player_duty[playerid] = true;
        }
        else if(player_duty[playerid] != false)
        {
            strdel(string, 0, 144);
            if(time_duty[playerid] < 60)
            {
                format(string, sizeof(string), "** %s ah mode out of duty, total time on duty: %d seconds.", Name(playerid), time_duty[playerid]*1);
                SendClientMessageToAll(-1, string);
            }
            else if(time_duty[playerid] >= 60)
            {
                format(string, sizeof(string), "** %s ah mode out of duty, total time on duty: %d minutes.", Name(playerid), time_duty[playerid]/60*1);
                SendClientMessageToAll(-1, string);
            }
            time_duty[playerid] = 0;
            player_duty[playerid] = false;
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You are not administrator.");
    }
    return true;
}

stock Name(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, 24);
    return name;
}

task count_time_duty[1000]()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(player_duty[i] != false)
            {
                time_duty[i]++;
            }
        }
    }
    return true;
}

#endif
Reply
#4

Ty, It worked perfect, REP+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)