how to make a command which...
#1

can someone show a tutorial off how to make a command which shows how long the server have been on and since when for my irc system?
like: Server has been up for <mins> minutes and <hours> hours since /day/month/year/hours:minutes and during that...
Times has been joined to the server:
New players registered:
Total Message Has Been Sent:
Total Objects in the server:
Total Players Registered:
Total Admins:
Total Banned Players From The Server:



i have been looking around and i didnt find anything..

Rep+ to everyone who tries to help

EDIT:
I want it to be a command for my irc system, like:

IRCCMD:uptime(botid, channel[], user[], host[], params[])
{
Reply
#2

-- How long has it been up for -- https://sampwiki.blast.hk/wiki/Gettime
-- Since when -- https://sampwiki.blast.hk/wiki/Getdate

You could store the references returned by those functions when the server starts and calculate what you need, comparing the current date-time to the initial values. You might want to look at some database systems to save those references, I wouldn't go for something so complex, a few lines in a file should do.
Reply
#3

pawn Код:
enum data
{
    PlayersConnected,
    PlayersRegistered,
    TotalMessages
}

new sData [] [data];
new SERV;

public OnPlayerConnect(playerid)
{
    sData[SERV][PlayersConneted]++;
}

stock  GetTotalPlayerRegistered()
{
    new Reg;
    for(new i = -1, i < MAX_PLAYERS; i++)
    if(/*ur player registervariable*/ == /*ur check*/)
    {
        return i;
    }
}

// below OnPlayerText:
    sData[SERV][otalMessages]++;
havent checked, only get 3 things.
Reply
#4

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
pawn Код:
enum data
{
    PlayersConnected,
    PlayersRegistered,
    TotalMessages
}

new sData [] [data];
new SERV;

public OnPlayerConnect(playerid)
{
    sData[SERV][PlayersConneted]++;
}

stock  GetTotalPlayerRegistered()
{
    new Reg;
    for(new i = -1, i < MAX_PLAYERS; i++)
    if(/*ur player registervariable*/ == /*ur check*/)
    {
        return i;
    }
}

// below OnPlayerText:
    sData[SERV][otalMessages]++;
havent checked, only get 3 things.
I want a tutorial off how to make an irc command which shows how long the server has been on and since when...
Reply
#5

Quote:
Originally Posted by Miguel
Посмотреть сообщение
-- How long has it been up for -- https://sampwiki.blast.hk/wiki/Gettime
-- Since when -- https://sampwiki.blast.hk/wiki/Getdate

You could store the references returned by those functions when the server starts and calculate what you need, comparing the current date-time to the initial values. You might want to look at some database systems to save those references, I wouldn't go for something so complex, a few lines in a file should do.
I have tried to do it many times and when i use the !uptime command it says

Server has been up for 1388150620 Since 00/00/0/00:00
Reply
#6

Use 1388150620 as a reference. Get a new reference everytime you want to know the uptime and compare it to the very first one you got (just substract). If you want your uptime in hours and minutes, you would have to do the math with that substraction, there are a few tutorials that cover how to do that.

This is an example:
pawn Код:
enum eDateTimeInfo
{
    day, month, year, hours, minutes, seconds
};

new gVeryFirstTimestamp = 0; // This will be a reference.
new gWhenDidItStart[eDateTimeInfo]; // This will be an actual date-time.

public OnGameModeInit()
{
    gVeryFirstTimestamp = gettime();
    getdate(gWhenDidItStart[year], gWhenDidItStart[month], gWhenDidItStart[day]);
    gettime(gWhenDidItStart[hours], gWhenDidItStart[minutes], gWhenDidItStart[seconds]);
    // You could store these variables in a file and just load it everytime the server starts
    return 1;
}

// Your IRC command:
new string[128];
new uptime = gettime() - gVeryFirstTimestamp;

format(string, sizeof(string), "The server has been up for %i seconds.", uptime);
// IRC message.

format(string, sizeof(string), "It's been up since %02i/%02i/%i at %02i:%02i", gWhenDidItStart[day], gWhenDidItStart[month], gWhenDidItStart[year],
gWhenDidItStart[hours], gWhenDidItStart[minutes]);
// IRC message.
P.D: gettime returns an unix timestamp... https://sampwiki.blast.hk/wiki/gettime
Reply
#7

Quote:
Originally Posted by Miguel
Посмотреть сообщение
Use 1388150620 as a reference. Get a new reference everytime you want to know the uptime and compare it to the very first one you got (just substract). If you want your uptime in hours and minutes, you would have to do the math with that substraction, there are a few tutorials that cover how to do that.

This is an example:
pawn Код:
enum eDateTimeInfo
{
    day, month, year, hours, minutes, seconds
};

new gVeryFirstTimestamp = 0; // This will be a reference.
new gWhenDidItStart[eDateTimeInfo]; // This will be an actual date-time.

public OnGameModeInit()
{
    gVeryFirstTimestamp = gettime();
    getdate(gWhenDidItStart[year], gWhenDidItStart[month], gWhenDidItStart[day]);
    gettime(gWhenDidItStart[hours], gWhenDidItStart[minutes], gWhenDidItStart[seconds]);
    // You could store these variables in a file and just load it everytime the server starts
    return 1;
}

// Your IRC command:
new string[128];
new uptime = gettime() - gVeryFirstTimestamp;

format(string, sizeof(string), "The server has been up for %i seconds.", uptime);
// IRC message.

format(string, sizeof(string), "It's been up since %02i/%02i/%i at %02i:%02i", gWhenDidItStart[day], gWhenDidItStart[month], gWhenDidItStart[year],
gWhenDidItStart[hours], gWhenDidItStart[minutes]);
// IRC message.
P.D: gettime returns an unix timestamp... https://sampwiki.blast.hk/wiki/gettime
thanks, but how can i make so it says how many hours it has been online
and what about this?

Times has been joined to the server:
New players registered:
Total Message Has Been Sent:
Total Objects in the server:
Total Players Registered:
Total Admins:
Total Banned Players From The Server:
since the last restart...
Reply
#8

Quote:
Originally Posted by SRB
Посмотреть сообщение
thanks, but how can i make so it says how many hours it has been online
https://sampforum.blast.hk/showthread.php?tid=357832

Quote:
Originally Posted by SRB
Посмотреть сообщение
and what about this?

Times has been joined to the server:
New players registered:
Total Message Has Been Sent:
Total Objects in the server:
Total Players Registered:
Total Admins:
Total Banned Players From The Server:
since the last restart...
Use some global vars, increment everytime one of those events happens. Something like:

pawn Код:
new gNewPlayersReg = 0; // Global
new gMessagesSent = 0;

// When a new player signs up...
gNewPlayersReg = gNewPlayersReg + 1;

// When message is sent

public OnPlayerText(playerid, text[])
{
    gMessagesSent = gMessagesSent + 1;
    return 1;
}
And then show those global variables in an IRC message.
Reply
#9

hmm, im confused...
where do i need to put all this?

Код:
new totaltime = 34000; // this is your initial value, here for reference
new remaining; // temporary storage

remaining = totaltime % 3600; // remaining seconds after subtracting hours

new hours = (totaltime - remaining) / 3600;
new seconds = remaining % 60;
new minutes = (remaining - seconds) / 60;

// will give: 9 hours, 26 minutes, 40 seconds
Код:
new gNewPlayersReg = 0; // Global
new gMessagesSent = 0;

// When a new player signs up...
gNewPlayersReg = gNewPlayersReg + 1;

// When message is sent

public OnPlayerText(playerid, text[])
{
    gMessagesSent = gMessagesSent + 1;
    return 1;
}
and tell me what to replace it with... if you know what i mean.
Reply
#10

I would like to get the answer A$AP
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)