• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Help] os.clock

Wrathe

Curiosity Kills!
Joined
Sep 28, 2007
Messages
131
Reaction score
1
Location
SA, Australia
Can someone please tell me how to os.clock works and what servers it works on?
Does it get your time on your computer?
 
I don't know how to use that. Can you please explain?
I want to make a NPC say /shutdown 5 after 24 hours.

If you are using The Forgotten Server you dont need an npc for it just look in config.lua you will find this


Code:
	-- Server Save
	serverSaveHour = 3
	shutdownAtServerSave = "no"
	cleanMapAtServerSave = "yes"
 
So if I do something like
Code:
if os.clock == (60 * 60 * 2) then
selfSay(/'B If anyone needs help then message GM Wrathe')
end
That will broadcast that message every 2 hours? Can you please test?
 
Usually when use in an NPC its to delay a message or something, like if the NPC is telling a really long story he might say half the story in one go then wait 10 seconds so the player can read it then say the second half.

In the script it would look like this:
Code:
if msgcontains(msg, "story") then
selfsay("FIRST_HALF_OF_STORY_HERE")
[B]say_next = os.clock[/B]
Now I'm not to sure on the technicals of how it works but I am guessing it saves the time that say_next was saved so you can use it to calculate how long ago the value was saved. It will make sense when you look at this (hopefully):
Code:
function OnThink()
if [B](os.clock() - say_next)[/B] >= 30 then
    selfsay("SECOND_HALF_OF_STORY_HERE")
    [U]say_next = 0[/U]
end
Notice how you check for os.clock values is different. Again don't ask me why but it is. Also notice you set the say_next value back to 0 so it doesnt keep repeating itself and we use >= instead of == just incase it wasn't exactly 30 seconds when the NPC called its onThink().

I hope you have a better understanding of os.clock now and how to use it. If I am wrong in any of this please someone point it out as I am a self tought scripter through trial and error and this is just what I have come up with how it works :).
 
Usually when use in an NPC its to delay a message or something, like if the NPC is telling a really long story he might say half the story in one go then wait 10 seconds so the player can read it then say the second half.

In the script it would look like this:
Code:
if msgcontains(msg, "story") then
selfsay("FIRST_HALF_OF_STORY_HERE")
[B]say_next = os.clock[/B]
Now I'm not to sure on the technicals of how it works but I am guessing it saves the time that say_next was saved so you can use it to calculate how long ago the value was saved. It will make sense when you look at this (hopefully):
Code:
function OnThink()
if [B](os.clock() - say_next)[/B] >= 30 then
    selfsay("SECOND_HALF_OF_STORY_HERE")
    [U]say_next = 0[/U]
end
Notice how you check for os.clock values is different. Again don't ask me why but it is. Also notice you set the say_next value back to 0 so it doesnt keep repeating itself and we use >= instead of == just incase it wasn't exactly 30 seconds when the NPC called its onThink().

I hope you have a better understanding of os.clock now and how to use it. If I am wrong in any of this please someone point it out as I am a self tought scripter through trial and error and this is just what I have come up with how it works :).

Yea but are u sure the os.clock function is included in the Npc function system?
 
It helped a little bit.
So...
Code:
function onThink
login_time = os.clock
if (os.clock() - login_time) == (60 * 60 * 5) or (60 * 60 * 10) then
selfSay(/'B If anyone needs help then message GM Wrathe.')
end
end
Okay how about this? It will broadcast a message at 5 hours and 10 hours after the server starts?
 
I would put login_time = os.clock up with focus = 0 and all that right up the top of the script (unless you are using jiddo's system). Also I'm not sure if you can have to or's after the "==". If you can that I have been wasting alot of time copying and pasting in past scripts lol. But I think you have to do it like this:
Code:
if ((os.clock() - login_time) == (60 * 60 * 5) or (os.clock() - login_time) == (60 * 60 * 10)) then
 
Back
Top