The online racing simulator
A very very little help please
(10 posts, started )
A very very little help please
Hello guys,

I tried to add the command "idles" minutes and seconds (while the player is idle), it works but not how I want.
And my problem is: InSim not put more than 1 minute

if (i.IsAFK == true)
{
string Minutes = "0";
string Seconds = "0";

Minutes = "" + (Conn.AFKTick / 60);
if ((Conn.AFKTick - ((Conn.AFKTick / 60) )) < 10)
{
Seconds = "0" + (Conn.AFKTick - ((Conn.AFKTick / 60) * 60));
}
else
{
Seconds = "" + (Conn.AFKTick - ((Conn.AFKTick / 60) * 60));
}
Found = true;
MsgPly("^7» Idle: " + i.PlayerName +" ^7(" + Minutes + ":" + Seconds + "^7)", MSO.UCID);

Quote from Andi1999 :And my problem is: InSim not put more than 1 minute

Could you explain what you mean exactly? Also, why are Minutes and Seconds strings? Shouldn't you make them an int?

What's the Found bool for? You always set it to true, but never seem to use it again.
I guess that is supposed to be some time-counter?
As Bose321 said for such timer one should use integer.

Your post is bit too incomplete/strange Wink
But generally I suggest to use only need one variable to keep track of time. (you seem to track minutes & seconds seperately)
That might make it a bit cleaner/easier.
So internally your script might have "seconds=185" and if you want to output to user in min:sec format you could do:

int Minutes = timerSeconds / 60;
int Seconds = timerSeconds % 60;
MsgPly("^7» Idle: " + i.PlayerName +" ^7(" + Minutes + ":" + Seconds + "^7)", MSO.UCID);

1) Make sure you know what the value of Conn.AFKTick is, maybe it means something else that you think?

2) Better way to convert seconds to minutes and seconds

int time = Conn.AFKTick;
int sec = time % 60;
int min = (time - sec) / 60;

3) Create the output string like this to avoid the string concatenation mess

string result = String.Format("Idle: {0} ({1}:{2})", PlayerName, min, sec.ToString().PadLeft(2, '0'));

@MadCatX
Between
int min = (time - sec) / 60

or
int min = time / 60

is no difference as far I see? With the result saved in int any digits behind the comma are disregared anyway.
"(time - sec) / 60" would work even if "time" were a float (with a small floating point error). On the other hand using "floor(time / 60.0)" might be a better thing to do such a case. Another thing is that the truncation of the decimal part happens only in some languages. If you do this in Ada for instance you will get a rounded value instead of truncated Smile
Yes, for floats would need some "real" rounding anyway.
For integer extra floor() is imo unneeded if one knows what/how the used language does.

I used search and found https://www.lfs.net/forum/thread/87376
Without complete code/problem it is bit like a puzzle but from that other thread:

if (Conn.AFKTick == 60 == false)
{
Conn.AFKTick += 1;

There you only increment (+1) Conn.AFKTick as long it has not reached value of 60 yet.
If Conn.AFKTick can not go over 60 then it does not "put more than 1 minute" because your timer stops ticking after 1 minute...
The code goes but it's not exactly what I want.
Let me explain: when a player I write command! "Idles" to see who is idle and for how long (minutes and seconds), but the problem is that after you reach 1 Minute, remain so (1:00) and not may numbered on.
Read what Gutholz said, AFKTick doesn't count more that 60 seconds of inactivity.
Think it might work if you just remove that line.
Change
if (Conn.AFKTick == 60 == false)
{
Conn.AFKTick += 1;
}

to
Conn.AFKTick += 1;


A very very little help please
(10 posts, started )
FGED GREDG RDFGDR GSFDG