gettime function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: gettime function (
/showthread.php?tid=491599)
gettime function -
Kyance - 31.01.2014
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?
Re: gettime function -
Konstantinos - 31.01.2014
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.
Re: gettime function -
Kyance - 31.01.2014
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
Re: gettime function -
Richie© - 31.01.2014
pawn Код:
gettime() - ConnectTime[playerid] / 60
gettime() is seconds, divide by 60 to get minutes.
Re: gettime function -
Kyance - 01.02.2014
Eh, when i tried the "gettime() - ConnectTime[playerid] / 60", i got this;
Код:
Online for: 1368063994 minutes::..
Re: gettime function -
Konstantinos - 01.02.2014
The subtraction should be in parentheses otherwise it will do the division first.
pawn Код:
(gettime() - ConnectTime[playerid]) / 60
Re: gettime function -
Kyance - 01.02.2014
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