gettime function
#1

I've made a topic about this, but i still didn't understand stuff..
I want to try to make an command, which shows for how long the player has been online.
But i never got to understand how gettime works.

I'm thinking about this kind of stuff:

pawn Код:
CMD:onlinetime(playerid, params[]) {
    new string[64], Minutes;
    Minutes = gettime(minute);
    format(string, sizeof(string), "[NOTE] - You've been online for %d minutes!", Minutes);
    SendClientMessage(playerid, COLOR_YELLOW, string);
    return 1;
}
And of-course this is just a random example command..
Would something like that work, or no?
Reply
#2

pawn Код:
// global:
new ConnectTime[MAX_PLAYERS];

// OnPlayerConnect:
ConnectTime[playerid] = gettime();

// command /onlinetime:
...
format(string, sizeof(string), "[NOTE] - You've been online for %d minutes!", gettime() - ConnectTime[playerid]);
...
It will show you how many seconds you've been online. There are many posts/threads about converting to hours/minutes etc, search.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
// global:
new ConnectTime[MAX_PLAYERS];

// OnPlayerConnect:
ConnectTime[playerid] = gettime();

// command /onlinetime:
...
format(string, sizeof(string), "[NOTE] - You've been online for %d minutes!", gettime() - ConnectTime[playerid]);
...
It will show you how many seconds you've been online. There are many posts/threads about converting to hours/minutes etc, search.
Ah.. thanks :d
Reply
#4

pawn Код:
gettime() - ConnectTime[playerid] / 60
gettime() is seconds, divide by 60 to get minutes.
Reply
#5

Eh, when i tried the "gettime() - ConnectTime[playerid] / 60", i got this;
Код:
Online for: 1368063994 minutes::..
Reply
#6

The subtraction should be in parentheses otherwise it will do the division first.

pawn Код:
(gettime() - ConnectTime[playerid]) / 60
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The subtraction should be in parentheses otherwise it will do the division first.

pawn Код:
(gettime() - ConnectTime[playerid]) / 60
Eh, here's the string/format i have:

pawn Код:
format(string, sizeof(string), "|   ..:: Score: %d | Money: %d$ | Kills: %d | Deaths: %d |  K/D Ratio: %0.2f  |  Online for: %d minutes ::..   |", GetPlayerScore(id), GetPlayerMoney(id), PlayerInfo[id][pKills], PlayerInfo[id][pDeaths],  Float:PlayerInfo[id][pKills]/Float:PlayerInfo[id][pDeaths], gettime() - ConnectTime[id]);
Do i add it:
pawn Код:
format(string, sizeof(string), "|   ..:: Score: %d | Money: %d$ | Kills: %d | Deaths: %d |  K/D Ratio: %0.2f  |  Online for: %d minutes ::..   |", GetPlayerScore(id), GetPlayerMoney(id), PlayerInfo[id][pKills], PlayerInfo[id][pDeaths],  Float:PlayerInfo[id][pKills]/Float:PlayerInfo[id][pDeaths], gettime() - ConnectTime[id]) /*Here?*/;
xd
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)