Page 1 of 1

How to check game time?

Posted: Fri Feb 01, 2013 10:19 am
by Jamnyk
Hi. I'd like to write addon which call "Chest event!" at 11 am and 7 pm. I tested

Code: Select all

sendMacro("GetTime()");
and

Code: Select all

sendMacro("GetGameTime()");
but that commands don't work :(

--all code from .lua file is

Code: Select all

function Chest_OnLoad(this)
	DEFAULT_CHAT_FRAME:AddMessage("Chest addon loaded.", 0.67, 0, 0.85)
end


function Chest_onEvent(this, event)
	player:update()
	sendMacro("GetTime()");
		if GameTime == 10.59 then
			DEFAULT_CHAT_FRAME:AddMessage("Chest event!", 0.67, 0, 0.85)
		end
		if  GameTime == 18.59 then
			DEFAULT_CHAT_FRAME:AddMessage("Chest event!", 0.67, 0, 0.85)
		end
	end


Are there any other commands like "GetTime()" ?

Re: How to check game time?

Posted: Fri Feb 01, 2013 11:36 am
by lisa
you could probably use the operating system time if using bot, not sure it would work as an addon.
Do a search for d303fix, that is an addon which attempts to get the current server time by looking at sales in the item shop.

This would probably be the best function to use with bot.
http://www.lua.org/manual/5.1/manual.html#pdf-os.date

Re: How to check game time?

Posted: Fri Feb 01, 2013 1:04 pm
by rock5
If you want the real time why not just use the bot's time.

Code: Select all

Command> print(os.date())
02/02/13 04:58:22
That prints a formated string which is not that much use but you can have it return a table of values

Code: Select all

Command> table.print(os.date("*t"))
table: 0646A0B0
day:    2
isdst:  true
year:   2013
month:  2
yday:   33
min:    0
wday:   7
sec:    16
hour:   5
So you could do something like

Code: Select all

checktime = os.date("*t")
if checktime.hour == 7 or checktime.hour == 11 then

Re: How to check game time?

Posted: Sat Feb 02, 2013 7:49 am
by Jamnyk
Yeah, I can do it with bot, but it's a bit uncomfortable to use it with bot :)
Thank you for help, I give up :) Mayby later

Re: How to check game time?

Posted: Sat Feb 02, 2013 8:25 am
by rock5
Sorry I missed that you wanted an addon. Well with d303Fix installed you should still be able to use os.date("*t")

Re: How to check game time?

Posted: Sat Feb 02, 2013 1:33 pm
by Jamnyk
So, I must rewrite d303fix addon or can i just rewrite my addon?

Re: How to check game time?

Posted: Sat Feb 02, 2013 1:36 pm
by rock5
With d303fix installed you can use the 'os' functions in your addon.

Re: How to check game time?

Posted: Sat Feb 02, 2013 1:51 pm
by Jamnyk
Ok thanks, i'll test it tonight :)

Re: How to check game time?

Posted: Sat Feb 02, 2013 3:41 pm
by Jamnyk

Code: Select all

function Chest_OnEvent(this, event)
	os.date ([!format [, time]])
	checktime = os.date("*t")
	if checktime.hour == 11 or checktime.hour == 19 then
	SlashCommand("/say Chest event!)
	end
end
-- not work... how to do that? :D

Re: How to check game time?

Posted: Sat Feb 02, 2013 7:16 pm
by lisa
try not to confuse bot code with in game code.

Code: Select all

function Chest_OnEvent(this, event)
that tells me you have put this as an addon code.

Code: Select all

SlashCommand("/say Chest event!)
that is bot code.

Try using

Code: Select all

SendSystemChat("Chest event!")
or

Code: Select all

SendChatMessage("Chest event!", "SAY")

Re: How to check game time?

Posted: Sun Feb 03, 2013 12:26 am
by rock5
I thought he was trying to create an addon.
Jamnyk wrote:Yeah, I can do it with bot, but it's a bit uncomfortable to use it with bot
I'm suspecting, Jamnyk, that you just don't know how to create an addon. It's very different to creating a userfunction. It's easy enough to add some functions to the game but if you want something automatically triggered by the update event for example then you need to create a frame in an xml file for your addon and register the event you want to use as a trigger.

Re: How to check game time?

Posted: Sun Feb 03, 2013 12:12 pm
by Jamnyk
Yes, it's my first addon :)
__
My expectations for this addon are :
-check time
-if time = 11 [am] or 7 [pm] then do [say] "Chest event!" then wait 1[hour] then do check time
-if time > 11 [am] or < 11 [am] then wait 30[seconds] then do check time
-if time > 7 [pm] or < 7 [pm] then wait 30[seconds] then do check time
__
You said it's more difficult than i think...

Code: Select all

<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">

	<Script file="Chest.lua"/>

	<Frame name="ChestFrame" parent="UIParent" hidden="true">

		<Scripts>

			<OnLoad>
				Chest_OnLoad(this);
			</OnLoad>

			<OnEvent>
				Chest_OnEvent(this, event);
			</OnEvent>


		</Scripts>

	</Frame>

</Ui>
__
It's my .xml file
__

Code: Select all

WarRegister.xml
__
and it's my .toc file ;D
Do you know any addons similar to the one that I want to create? Maybe I could be inspired on it?

Re: How to check game time?

Posted: Sun Feb 03, 2013 6:57 pm
by lisa

Re: How to check game time?

Posted: Mon Feb 04, 2013 12:04 am
by Jamnyk
Thanks ^^