Wrathe
Curiosity Kills!
Can someone please tell me how to os.clock works and what servers it works on?
Does it get your time on your computer?
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.
-- Server Save
serverSaveHour = 3
shutdownAtServerSave = "no"
cleanMapAtServerSave = "yes"
if os.clock > 30 then
selfSay('Thank you and goodbye')
if os.clock == (60 * 60 * 2) then
selfSay(/'B If anyone needs help then message GM Wrathe')
end
if msgcontains(msg, "story") then
selfsay("FIRST_HALF_OF_STORY_HERE")
[B]say_next = os.clock[/B]
function OnThink()
if [B](os.clock() - say_next)[/B] >= 30 then
selfsay("SECOND_HALF_OF_STORY_HERE")
[U]say_next = 0[/U]
end
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:
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:if msgcontains(msg, "story") then selfsay("FIRST_HALF_OF_STORY_HERE") [B]say_next = os.clock[/B]
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().Code:function OnThink() if [B](os.clock() - say_next)[/B] >= 30 then selfsay("SECOND_HALF_OF_STORY_HERE") [U]say_next = 0[/U] end
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 .
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
if ((os.clock() - login_time) == (60 * 60 * 5) or (os.clock() - login_time) == (60 * 60 * 10)) then