Liberty Unleashed
Scripting => Script Help => Topic started by: Theremin on December 02, 2016, 08:01:06 pm
-
Using onTimeChange (http://liberty-unleashed.co.uk/LUWiki/Squirrel/Server/Events/Game/onTimeChange), how can I tell if five minutes have passed? I don't mind whether it's a multiple of five (5, 10, 15, etc.) or just each five (2, 7, 12, 17, etc.).
</noob> :-[
-
Save a time, then check every onTimeChange if 5 mins has passed with the saved time and then save the new time when 5 mins passed?
-
This is my very first time using that function. I have other methods.
But Theremin, Did someone do the wiki wrong for that page?? I did a shit load of testing on that function until I grew lazy and bored.
Hear is the real output of that function.
unless I some how fucked up
Minute <- 0;
Hour <- 0;
Second <- 0;
function onTimeChange( Min, Sec )
{
Minute = Min;
Second = Sec;
// Now lets create the Hour check
if ( Minute == 60 )
{
// Increase the hour
Hour++;
}
print("Hour: " + Hour + " Minute: " + Minute + " Second: " + Second);
return true;
}
-
Uhhhhh ...
I don't think onTimeChange measures seconds. It's only hours and minutes.
By default, the game clock increments a minute of in-game time for every second of real time. Every 60 seconds is one hour in-game, which means that 24 minutes is 24 hours in-game.
-
I could never return hours and minutes by default, This function ran this print by default as well , Do you mind running this code and watching the console :), I would love to be proven wrong.
-
That does t make any sense. Did you read my post? What we know as seconds in life are actually minutes in game
Sent from my Nexus 4 using Tapatalk
-
Do you think that it's because I am not using any-type of time-lock? I went in-game and did some checking out and my minutes are moving in seconds, and hours by minutes
-
Motley your code doesn't work, even if you change it you'll never be able to calculate real time that way, because one hour is 2.5 days in game.
Save a time, then check every onTimeChange if 5 mins has passed with the saved time and then save the new time when 5 mins passed?
Yeah, that's a way to do it, and it's exactly where i'm stuck, I'd be really grateful if anyone could provide an example, and possibly keeping it simple.
-
Could you possibly provide what you're working with so far? And or private message me the code? I'll take a look at it after work :)
-
Here goes nothing :P
function onTimeChange( hour, min )
{
if ( min *= 5 ) Message("I know this code is wrong, but it was my last attempt");
}
-
Even for all this, I would prefer a timer. 5 minutes doesn't really have a significantly heavy resource usage. I think a 300,000 millisecond interval is 5 minutes.
-
Five minutes in game which corresponds to five real seconds. I need a check each five seconds, what would you use? Do you think a timer is viable for that purpose? I'm currently sticking to a timer, unless I find a way to use onTimeChange.
-
I'm sorry as I have been really lazy :-[.
I want to also say this is a lazy example
First thing first Theremin, If you were to check if
min5 = 5 etc during the time of Five, If you use print("It's Five B)");
You will have a constant repeat of that print until five has ended, I noticed this with that function.
So you would have to run a simple check
tick_5 <- 0;
function onTimeChange( hour, min )
{
if ( min == 5 )
{
if (tick_5 == 1) print("Min 5 already completed its print");
// Do not enter if the tick of Five has already completed
if (tick_5 == 0)
{
print("It's Five);
tick_5 = 1;
}
}
if ( min != 5 )
{
if (tick_5 == 1)
{
tick_5 = 0;
print("Tick of 5 has been reset")
}
}
}
There is a lot of data usage issues and a lot you would need to work with to prevent this...
I hope this was of some help?
-
Thanks for your script Motley, anyway, It works only partly, because the check tells me only when five seconds pass, but in this case, I'd need to add it also for 10, 15, etc. which isn't really great imho :-\. Anyway fine it gave me some ideas, as for this script I decided to stick to a timer, so pretty much the problem has been solved in someway.
-
Well just try not to have many timers, Hear is a easy way of altering the time :)
Minutes <- 0;
Seconds <- 0;
Hours <- 0;
function onScriptLoad()
{
NewTimer("Loop_Seconds", 1000, 0);
}
// Our server loop
function Loop_Seconds()
{
//time durrations
if ( Seconds == 60 )
{
Seconds = 0;
Minutes++;
Loop_Minutes();
}
if ( Minutes == 60 )
{
Minutes = 0;
Hours++;
Loop_Hours();
}
Seconds++;
print("Seconds " + Seconds);
//time durrations
}
// Our minutes loop
function Loop_Minutes()
{
print("Minutes " + Minutes);
}
// Our hour loop
function Loop_Hours()
{
print("Hours " + Hours);
}
-
Well, even with cheap hosting you can get good specs so avoiding
a timer to save resources doesn't even seem reasonable any more
Sent from my Nexus 4 using Tapatalk