
Originally Posted by
Shadowmeld
does GearSwap have access to timers (not the plugin, but clock functions) in any way?
I'm looking at doing a register event for magic burst based on timers and I was wondering if I might be able to do something like this
(pseudocode)
Code:
windower.register_event('action message', function(actor_id, target_id, actor_index, target_index, message_id, param_1, param_2, param_3) end)
if message_id > 287 and message_id < 303 then -- Skill chain message ids start at 288 and go through 302
self_command("mb_start")
end
function self_command(command)
if command == 'mb_start' then
state.MagicBurst = true
mb_timer = os.clock()
send_command("wait 5; gs c mb_fin")
elseif command == 'mb_fin' then
if os.clock() - mb_timer.value > 5 then
state.MagicBurst = false
mb_timer.stop()
end
end
end
yes and no
you cant do sleep in gearswap but you can trigger another function to go off after a specific amount of time (aka start a custom thread)
Example:
--this is how i time my xp/cp ring re equip
Code:
function get_item_next_use(name)--returns time that you can use the named item again
for _,n in pairs({"inventory","wardrobe","wardrobe2"}) do
for _,v in pairs(gearswap.items[n]) do
if type(v) == "table" and v.id ~= 0 and gearswap.res.items[v.id].en == name then
return gearswap.extdata.decode(v)
end
end
end
end
function xp_cp_ring_equip(ring)--equips selected ring
if auto_ring then
enable("left_ring")
gearswap.equip_sets('xp_cp_ring_auto_equip',nil,{left_ring=ring})
disable("left_ring")
end
end
function schedule_xpcp_ring()--scheduals equip of selected ring
local ring_time = os.time(os.date("!*t", get_item_next_use(rings[rings_count]).next_use_time))-os.time()
if type(xpcpcoring) == "thread" then
coroutine.close(xpcpcoring)
end
xpcpcoring = coroutine.schedule(xp_cp_ring_equip:prepare(rings[rings_count]),(ring_time > 0 and ring_time or 1))
end
--if you just want to trigger another function (that does not require any vaiables)
Code:
thenameofyourfunction:schedule(timeinseconds)
--if you just want to trigger another function (that does require vaiables)--sometime one works but the other does not
Code:
thenameofyourfunction:schedule(timeinseconds,yourfunctionvarables)
or
coroutine.schedule(thenameofyourfunction:prepare(yourfunctionvarables),timeinseconds)
--if you want to equip something after a timer
Code:
gearswap.equip_sets:schedule(timeinseconds,'timed_equip', nil, setname)
this is how i would do your code
Code:
function end_mb()
state.MagicBurst = false
end
function action_message(actor_id, target_id, actor_index, target_index, message_id, param_1, param_2, param_3)
if message_id > 287 and message_id < 303 then -- Skill chain message ids start at 288 and go through 302
state.MagicBurst = true
end_mb:schedule(5)
end
end
windower.raw_register_event('action message', action_message)