Post by tyreafus on Nov 15, 2005 17:02:40 GMT -5
Just finished my new script, and unlike my last one, this one is fully functional. I call it timers.lua. What it does is allows up to 6 countdown timers to be displayed on the screen, for use with Windower script macros or whatever other use for them.
Commands:
-Start <timerslot> <length> <label>
Starts a timer
<timer#> - designates which timer to use, 1-6. The timers go accross the top of the screen, with 1 at far left and 6 at far right.
<length> - amount in seconds to countdown
<label> - Label for the timer.
-Off <timer#>
stops <timer#>
I should also add that the arguments cannot contain spaces. Maybe for the next version I'll change this.
So the basic usage of this is with windower scripts, for example:
bind ^1 input "/ja Provoke <t>"; .Lunar command timers.lua start 1 30 Voke; wait 30; input "/echo Voke Ready!!!";
bind ^2 input "ja Boost <t>"; .Lunar command timers.lua start 2 15 Boost; wait 15; input "/echo Boost Ready!!!"';
The countdowns are slightly skippy, and I'm not sure why, but they certainly serve their purpose.
In the next version I will probably make commands to change the positions on the timers.
Here's the code for the current one:
Sample Macros:
fire.txt:
water.txt:
healing.txt:
Commands:
-Start <timerslot> <length> <label>
Starts a timer
<timer#> - designates which timer to use, 1-6. The timers go accross the top of the screen, with 1 at far left and 6 at far right.
<length> - amount in seconds to countdown
<label> - Label for the timer.
-Off <timer#>
stops <timer#>
I should also add that the arguments cannot contain spaces. Maybe for the next version I'll change this.
So the basic usage of this is with windower scripts, for example:
bind ^1 input "/ja Provoke <t>"; .Lunar command timers.lua start 1 30 Voke; wait 30; input "/echo Voke Ready!!!";
bind ^2 input "ja Boost <t>"; .Lunar command timers.lua start 2 15 Boost; wait 15; input "/echo Boost Ready!!!"';
The countdowns are slightly skippy, and I'm not sure why, but they certainly serve their purpose.
In the next version I will probably make commands to change the positions on the timers.
Here's the code for the current one:
--Global variable initialization, creation of text objects--
a=true
b=0
commandstring=""
init1 = 0
init2 = 0
init3 = 0
init4 = 0
init5 = 0
init6 = 0
on1=false
on2 = false
on3 = false
on4 = false
on5 = false
on6 = false
label1 = ""
label2 = ""
label3 = ""
label4 = ""
label5 = ""
label6 = ""
time1 = 0
time2 = 0
time3 = 0
time4 = 0
time5 = 0
time6 = 0
t1 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t1)
Graphics.text_SetPosition(20, 35, t1)
Graphics.text_SetBold(true, t1)
t2 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t2)
Graphics.text_SetPosition(100, 35, t2)
Graphics.text_SetBold(true, t2)
t3 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t3)
Graphics.text_SetPosition(180, 35, t3)
Graphics.text_SetBold(true, t3)
t4 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t4)
Graphics.text_SetPosition(260, 35, t4)
Graphics.text_SetBold(true, t4)
t5 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t5)
Graphics.text_SetPosition(340, 35, t5)
Graphics.text_SetBold(true, t5)
t6 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t6)
Graphics.text_SetPosition(420, 35, t6)
Graphics.text_SetBold(true, t6)
t7 = Graphics.text_CreateObject()
Graphics.text_SetColor(255, 0, 255, 255, t7)
Graphics.text_SetPosition(20, 90, t7)
--functions-------
function start(timernum, t, label)
if timernum == "1" then
on1 = true
label1 = label
time1 = tonumber(t)
init1 = os.clock()
Graphics.text_SetText(label1 .. ": " .. time1, t1)
elseif timernum == "2" then
on2 = true
label2 = label
time2 = tonumber(t)
init2 = os.clock()
Graphics.text_SetText(label2 .. ": " .. time2, t2)
elseif timernum == "3" then
on3 = true
label3 = label
time3 = tonumber(t)
init3 = os.clock()
Graphics.text_SetText(label3 .. ": " .. time3, t3)
elseif timernum == "4" then
on4 = true
label4 = label
time4 = tonumber(t)
init4 = os.clock()
Graphics.text_SetText(label4 .. ": " .. time4, t4)
elseif timernum == "5" then
on5 = true
label5 = label
time5 = tonumber(t)
init5 = os.clock()
Graphics.text_SetText(label5 .. ": " .. time5, t5)
elseif timernum == "6" then
on6 = true
label6 = label
time6 = tonumber(t)
init6 = os.clock()
Graphics.text_SetText(label6 .. ": " .. time6, t6)
else
Graphics.text_SetText("Timer.Start: Error: invalid timer#", t7)
end
return 0
end
function off(tnum)
tnum = tonumber(tnum)
if tnum == 1 then
on1 = false
Graphics.text_SetText("", t1)
elseif tnum == 2 then
on2 = false
Graphics.text_SetText("", t2)
elseif tnum == 3 then
on3 = false
Graphics.text_SetText("", t3)
elseif tnum == 4 then
on4 = false
Graphics.text_SetText("", t4)
elseif tnum == 5 then
on5 = false
Graphics.text_SetText("", t5)
elseif tnum == 6 then
on6 = false
Graphics.text_SetText("", t6)
else
Graphics.text_SetText("Timer.Off: Error: invalid timer#", t7)
end
return 0
end
function commandcheck()
if Windower.script_GetCommandCount() > 0 then
while Windower.script_GetCommandCount() > 0 do
commandstring=Windower.script_GetCommand()
if commandstring == "start" then
arg1 = Windower.script_GetCommand()
arg2 = Windower.script_GetCommand()
arg3 = Windower.script_GetCommand()
start(arg1, arg2, arg3)
elseif commandstring == "off" then
arg1 = Windower.script_GetCommand()
off(arg1)
else
Control.control_SendString("/echo Timer command invalid.")
end
end
end
return 0
end
function roundnum(n)
local basenum = math.floor(n)
if n - basenum > .5 then
return math.ceil(n)
else
return math.floor(n)
end
end
--While loop for countdown/update------------------------
while a == true do
commandcheck()
if on1 then
elapsed = os.clock() - init1
ctime = time1 - elapsed
if ctime < 0 then ctime = 0 end
Graphics.text_SetText(label1 .. ": " .. roundnum(ctime), t1)
end
if on2 then
elapsed = os.clock() - init2
ctime = time2 - elapsed
if ctime < 0 then ctime = 0 end
Graphics.text_SetText(label2 .. ": " .. roundnum(ctime), t2)
end
if on3 then
elapsed = os.clock() - init3
ctime = time3 - elapsed
if ctime < 0 then ctime = 0 end
Graphics.text_SetText(label3 .. ": " .. roundnum(ctime), t3)
end
if on4 then
elapsed = os.clock() - init4
ctime = time4 - elapsed
if ctime < 0 then ctime = 0 end
Graphics.text_SetText(label4 .. ": " .. roundnum(ctime), t4)
end
if on5 then
elapsed = os.clock() - init5
ctime = time5 - elapsed
if ctime < 0 then ctime = 0 end
Graphics.text_SetText(label5 .. ": " .. roundnum(ctime), t5)
end
if on6 then
elapsed = os.clock() - init6
ctime = time6 - elapsed
if ctime < 0 then ctime = 0 end
Graphics.text_SetText(label6 .. ": " .. roundnum(ctime), t6)
end
end
Sample Macros:
fire.txt:
keyboard_sendstring /ma Fire <t>;
keyboard_sendstring /p Fire -> <t>;
.Lunar command timers.lua start 1 10 Fire;
wait 10.25;
keyboard_sendstring /echo Fire ready!!!;
water.txt:
keyboard_sendstring /ma Water <t>;
keyboard_sendstring /p Water -> <t>;
.Lunar command timers.lua start 2 8 Water;
wait 7.75;
keyboard_sendstring /echo Water ready!!!;
healing.txt:
input "/heal";
.Lunar command timer.lua start 6 20 NxtHealTick;
wait 20;
.Lunar command timer.lua start 6 10 NxtHealTick;
wait 20;
.Lunar command timer.lua start 6 10 NxtHealTick;
wait 20;
.Lunar command timer.lua start 6 10 NxtHealTick;
wait 20;
.Lunar command timer.lua start 6 10 NxtHealTick;
//etc...