[HELP] Time Setting in Event

02/20/2013 00:50 monoedge#1
Using "time setting" do not work in my custom event.
For example, I want to start the event at 12:00 and finish at 18:00 everyday.

I'm making like this.
Code:
function event()
	local current_time = os.date( "%H:%M:%S" )

	time_1 = '12:00:00'
	time_2 = '18:00:00'
	
	if current_time < time_1 then
		event_begin()
	elseif current_time < time_2 then
		event_end()
	end
end

function event_begin()
...///
But don't work. Whta is wrong? Please give me an advice if you know somothing about this. Thank you.
02/20/2013 01:09 ismokedrow#2
How are you triggering that there function? o_O
02/20/2013 01:30 monoedge#3
Quote:
Originally Posted by ismokedrow View Post
How are you triggering that there function? o_O
I'm making the event just for test now.
What I'm making is if its after 12:00, players can receive GM buffs from NPC in Hidden Village.

Code:
function get_module_name()
             return "NPC_Buff"
end

function event()
	local current_time = os.date( "%H:%M:%S" )

	time_1 = '12:00:00'
	time_2 = '18:00:00'
	
	if current_time < time_1 then
		event_begin()
	elseif current_time < time_2 then
		event_end()
	end
end

function event_begin()
local npc_id = get_npc_id()
if npc_id == 11225 then
	dlg_title("@90702501")
	else
	dlg_title("@90702501")
	end
	add_state(314017, 70, 360000)
	NPC_Hidden_Village_Buff()
	else
	dlg_text("@90010005")
	dlg_menu("@90010002", "")
	dlg_show()
end

function event_end()
local npc_id = get_npc_id()
if npc_id == 11225 then
	dlg_title("@90702501")
	else
	dlg_title("@90702501")
	end
	dlg_text("event is closing")
	dlg_menu("@90010002", "")
	dlg_show()
end
Just like this.
02/20/2013 01:48 ismokedrow#4
Oh I see what you did there, I'm not real positive on the whole os.time bit there. But why not go the simple route and just set the NPC to be period (is_periodic = TRUE) then you set begin/end date and the NPC will only show up between those two dates at the time specified.
02/20/2013 02:12 monoedge#5
Quote:
Originally Posted by ismokedrow View Post
Oh I see what you did there, I'm not real positive on the whole os.time bit there. But why not go the simple route and just set the NPC to be period (is_periodic = TRUE) then you set begin/end date and the NPC will only show up between those two dates at the time specified.
Thank you for your advice. I know using "is_periodic" is easy to make event but I want to open that event everyday. If I use "is_periodic", the NPC shows only that day (begin_of_period) to (end_of_period). I put only time in the table but it will change to 2013-02-20 00:00:00.000 automatically. So I use that function :(
02/20/2013 09:28 M>M#6
Quote:
Originally Posted by monoedge View Post
Using "time setting" do not work in my custom event.
For example, I want to start the event at 12:00 and finish at 18:00 everyday.

I'm making like this.
Code:
function event()
	local current_time = os.date( "%H:%M:%S" )

	time_1 = '12:00:00'
	time_2 = '18:00:00'
	
	if current_time < time_1 then
		event_begin()
	elseif current_time < time_2 then
		event_end()
	end
end

function event_begin()
...///
But don't work. Whta is wrong? Please give me an advice if you know somothing about this. Thank you.
did you try to use the %X function it is easier than the %H:%M:%S

it give you the full time "e.g.,12:52:14" the code will look like this

Code:
function event()
	local current_time = os.date( "%X" )

	time_1 = '12:00:00'
	time_2 = '18:00:00'
	
	if current_time < time_1 then
		event_begin()
	elseif current_time < time_2 then
		event_end()
	end
end

function event_begin()
...///
i didn't try it but i think it will work and take a look at this [Only registered and activated users can see links. Click Here To Register...]

hope this help you

Greets,
HawasMan
02/20/2013 13:12 ThunderNikk#7
If that does not work you could try setting it up like a daily quest, with some cool time associated with it.

That way each player can take advantage of it once per day, not mattering which time of day they do it but then will not be able to do it again for 24 hour cool down.

You could check the pet grooming functions in the Creature Farm and maybe apply some of that code that only lets a player groom a pet once a day and also only lets them get buffed once per day.
02/20/2013 13:28 haxti#8
Maybe this snippet can give you a clue. I guess it isn't from Raskim cause there are some references to xijezu in this file. Since he retired i guess it doesn't really matter. If it's from Raskim it doesn't matter either, cause he used some of my shit too ;)

Code:
function lucky_raskim_contact_event()

local flag = tonumber( get_flag("lucky_raskim") ) -- get the timespan of the last recieve
  if flag == nil then -- if not exists
   flag = 0 -- set flag to 0
   set_flag( "lucky_raskim", "0" )
end
if flag+1 < os.time(t) then -- if last-recieve-time + 1 hour is smaller than current time
dlg_title("Lucky Raskim")
dlg_text("Hey, ich bin Raskim. Ich verteile Geschenke an alle Meister Klassen, jedoch nur alle 10 Stunden.")
dlg_menu("Was sind die Regeln?","lucky_npc_rules()")
dlg_menu("Ich möchte das geschenk erhalten","lucky_npc_recieve_gift()")
dlg_menu("TestFunktion","lua_to_sql_test()")
dlg_menu("Auf wiedersehen","")
dlg_show()
else
whisper(gv("name"),os.date ("<b>Du kannst das naechste Geschenk am %d.%m.%Y um %H:%M abholen. Wir sehen uns.", flag+36000))
end
end
ofc there is another part with
Code:
set_flag("lucky_raskim", os.time(t))
after recieving the specific item to save the datetime
02/20/2013 19:53 monoedge#9
Quote:
Originally Posted by M>M View Post
did you try to use the %X function it is easier than the %H:%M:%S

it give you the full time "e.g.,12:52:14" the code will look like this

Code:
function event()
	local current_time = os.date( "%X" )

	time_1 = '12:00:00'
	time_2 = '18:00:00'
	
	if current_time < time_1 then
		event_begin()
	elseif current_time < time_2 then
		event_end()
	end
end

function event_begin()
...///
i didn't try it but i think it will work and take a look at this [Only registered and activated users can see links. Click Here To Register...]

hope this help you

Greets,
HawasMan
Thank you for your advice. But %X still seems not work. I'll try another ways. Probably something is wrong in my code. Maybe I should try to fix them first and then I'll use %X.

Quote:
Originally Posted by thndr View Post
If that does not work you could try setting it up like a daily quest, with some cool time associated with it.

That way each player can take advantage of it once per day, not mattering which time of day they do it but then will not be able to do it again for 24 hour cool down.

You could check the pet grooming functions in the Creature Farm and maybe apply some of that code that only lets a player groom a pet once a day and also only lets them get buffed once per day.
Mmm. I think using cool time is better idea than mine. I guess the code which haxti gave me is also like cool time so I'll try to use it.
Anyway thank you for your advice.

Quote:
Originally Posted by haxti View Post
Maybe this snippet can give you a clue. I guess it isn't from Raskim cause there are some references to xijezu in this file. Since he retired i guess it doesn't really matter. If it's from Raskim it doesn't matter either, cause he used some of my shit too ;)

Code:
function lucky_raskim_contact_event()

local flag = tonumber( get_flag("lucky_raskim") ) -- get the timespan of the last recieve
  if flag == nil then -- if not exists
   flag = 0 -- set flag to 0
   set_flag( "lucky_raskim", "0" )
end
if flag+1 < os.time(t) then -- if last-recieve-time + 1 hour is smaller than current time
dlg_title("Lucky Raskim")
dlg_text("Hey, ich bin Raskim. Ich verteile Geschenke an alle Meister Klassen, jedoch nur alle 10 Stunden.")
dlg_menu("Was sind die Regeln?","lucky_npc_rules()")
dlg_menu("Ich möchte das geschenk erhalten","lucky_npc_recieve_gift()")
dlg_menu("TestFunktion","lua_to_sql_test()")
dlg_menu("Auf wiedersehen","")
dlg_show()
else
whisper(gv("name"),os.date ("<b>Du kannst das naechste Geschenk am %d.%m.%Y um %H:%M abholen. Wir sehen uns.", flag+36000))
end
end
ofc there is another part with
Code:
set_flag("lucky_raskim", os.time(t))
after recieving the specific item to save the datetime
This code must be nice help for me if it works fine. So I'm gonna test it. I think the code which I made is something wrong cuz your time setting (%d.%m.%Y %H:%M) works well in your code.

Thank you very much.
02/20/2013 20:33 TheOnlyOneRaskim#10
Quote:
Originally Posted by haxti View Post
Maybe this snippet can give you a clue. I guess it isn't from Raskim cause there are some references to xijezu in this file. Since he retired i guess it doesn't really matter. If it's from Raskim it doesn't matter either, cause he used some of my shit too ;)

Code:
function lucky_raskim_contact_event()

local flag = tonumber( get_flag("lucky_raskim") ) -- get the timespan of the last recieve
  if flag == nil then -- if not exists
   flag = 0 -- set flag to 0
   set_flag( "lucky_raskim", "0" )
end
if flag+36000 < os.time(t) then
dlg_title("Lucky Raskim")
dlg_text("Hey, ich bin Raskim. Ich verteile Geschenke an alle Meister Klassen, jedoch nur alle 10 Stunden.")
dlg_menu("Was sind die Regeln?","lucky_npc_rules()")
dlg_menu("Ich möchte das geschenk erhalten","lucky_npc_recieve_gift()")
[B]dlg_menu("TestFunktion","lua_to_sql_test()")[/B] --shit D
dlg_menu("Auf wiedersehen","")
dlg_show()
else
whisper(gv("name"),os.date ("<b>Du kannst das naechste Geschenk am %d.%m.%Y um %H:%M abholen. Wir sehen uns.", flag+36000))
end
end
ofc there is another part with
Code:
set_flag("lucky_raskim", os.time(t))
after recieving the specific item to save the datetime
[Only registered and activated users can see links. Click Here To Register...]

Oh and next time use the right snippet ;)
02/20/2013 21:23 monoedge#11
I edited the code but I can receive item anytime although its within 10 hrs. I added flag after receiving item like the code below but no work whisper.
Sorry again but where am I wrong? lucky_raskim:1361388956 added in the flag_list anyway.

I believe this code means players can receive item every 10 hrs, right?

Code:
function lucky_raskim_contact_event()
local flag = tonumber( get_flag("lucky_raskim") ) -- get the timespan of the last recieve
  if flag == nil then -- if not exists
   flag = 0 -- set flag to 0
   set_flag( "lucky_raskim", "0" )
end
if flag+1 < os.time(t) then -- if last-recieve-time + 1 hour is smaller than current time
		dlg_title("Lucky Raskim")
		dlg_text("Hey, ich bin Raskim. Ich verteile Geschenke an alle Meister Klassen, jedoch nur alle 10 Stunden.")
		dlg_menu("Ich möchte das geschenk erhalten","lucky_npc_recieve_gift()")
		dlg_menu("Auf wiedersehen","")
		dlg_show()
else
whisper(gv("name"),os.date ("<b>Du kannst das naechste Geschenk am %d.%m.%Y um %H:%M abholen. Wir sehen uns.", flag+36000))
end
end

function lucky_npc_recieve_gift()
	insert_item( 3600289, 1 )
	set_flag("lucky_raskim", os.time(t))
	dlg_text("Hey, ich bin Raskim. Ich verteile Geschenke an alle Meister Klassen, jedoch nur alle 10 Stunden.")
	dlg_menu( "@90010001", " " )
end
02/20/2013 23:14 TheOnlyOneRaskim#12
If youre using the 8.1 GS, dont wonder, it changed.

YOu cant use this way with the 8.1 GS any longer. ;)
02/21/2013 03:13 haxti#13
Quote:
Originally Posted by TheOnlyOneRaskim View Post
[Only registered and activated users can see links. Click Here To Register...]

Oh and next time use the right snippet ;)
Oh you should prolly shut up 'bout failed dreams man :D And it is the right snippet. It's about handling datetime format and time addition.
And I won't start about the 100 copy paste lines in this file ;)