Post by Jimmytime on Jan 17, 2006 10:59:50 GMT -5
Hello all. First post, but I've been lurking here for a while. Feedback and critiques encouraged ^^
Aim:
Get my feet wet for lua scripting by manupulating a pre-existing script. Even if I don't do anything inovative code-wise I'll be learning the ropes without starting from absolutely nothing.
Goals:
1.) Change Nebula's airship schedule script into something with more graphics/formatting.
2.) First format it to look good on my computer's settings, then code more flexibility in.
3.) Post progress on this forum for feedback/critique.
Current Questions:
1.) Object Layer Order: I want to eventually mimic an in-game window for the background. From what I can tell from other posts, the layering of text over background images is not possible yet due to how Lunar interfaces with FFXI, but it is being worked on for future release, and seems do-able. Is that correct? If so I can at least get the background image creation started, in hopes of eventually ditching the transparent window background.
2.) # of text/image objects: A new object variable has to be created for each image/text box, correct? Meaning, I can't set up a text object with a certain font and size, print it, then re-use the object to print elsewhere on the screen. My original text would vanish. A way to eliminate redundant or repetetive code would be some sort of type definition that could be used multiple times, or a function that sets up a passed object, yes? In particular I would want this for my creation of the objects for the city, arrow, and airship icons, not to mention the two text boxes. I already intend to make a loop for the creation of the row across of icons, and one for the column down.
3.) Speed/Variable Issues: In an effort to make the code more efficient, what is the best way to treat the variables as far as local/global go, keeping in mind that the scope of this script? It seems like every time GetSchedule is run, the offsets are re-created, then destroyed at the end of the function. Is more memory/time used up if they are globals?
4.) Image Problems: During testing I start the script, check for my changes, almost immediately unload the script, and continue writing, repeating this an ungodly number of times throughout the night. I've noticed during some loads, some of the icons are loaded at full size instead of their reduced size. Are images not intended to be scaled yet, given the current capabilities of the interface? Or am I missing something in my object setup? Related question: The last row and column of pixels gets cut off on the images I'm displaying. Is this related to the above questions?
5.) If/Then Question: Since this is an adaptation of Neb's code, I kept his schedule function almost the same but call it twice since I need 2 columns instead of one. I added an If/Then and passed a variable to control it, but the lists that get output are reversed in order. I'm missing something obvious.
6.) Advanced Key Binding: I’m pretty familiar with the way Windower handles keybinds, but not Lunar. I can see how to bind/unbind and use keyboard input mostly from X-Drop’s programs, but I’m wondering if more advanced binding is possible yet, such as binding a command to key combos like alt+1, ctrl+e, leftwindows+F2, etc. Also, perhaps someone could clarify the order in which keyboard input it routed to Lunar, Windower, and FFXI. I’m interested in stopping certain key combinations from getting to FFXI so I can use them either in a lunar script or windower macro, but I have a feeling I’ll have to see the folks over at Azaril’s forum for something like that, right? I’m also interested in using the windows key like alt or ctrl is used in Windower/FFXI for macros.
Just a quick note: I’m trying to search for my own answers the best I can on this forum and on the web (when my question applies to lua scripting in general), so if there are answers to these questions on this forum that are highly visible, sorry that I have missed them :^)
Code:
Screenshot:
fbs.freewebspace.com/cgi-bin/i/Airship_Shot.jpg
There we go. Let me know what you think, and thanks in advance for looking over it.
Aim:
Get my feet wet for lua scripting by manupulating a pre-existing script. Even if I don't do anything inovative code-wise I'll be learning the ropes without starting from absolutely nothing.
Goals:
1.) Change Nebula's airship schedule script into something with more graphics/formatting.
2.) First format it to look good on my computer's settings, then code more flexibility in.
3.) Post progress on this forum for feedback/critique.
Current Questions:
1.) Object Layer Order: I want to eventually mimic an in-game window for the background. From what I can tell from other posts, the layering of text over background images is not possible yet due to how Lunar interfaces with FFXI, but it is being worked on for future release, and seems do-able. Is that correct? If so I can at least get the background image creation started, in hopes of eventually ditching the transparent window background.
2.) # of text/image objects: A new object variable has to be created for each image/text box, correct? Meaning, I can't set up a text object with a certain font and size, print it, then re-use the object to print elsewhere on the screen. My original text would vanish. A way to eliminate redundant or repetetive code would be some sort of type definition that could be used multiple times, or a function that sets up a passed object, yes? In particular I would want this for my creation of the objects for the city, arrow, and airship icons, not to mention the two text boxes. I already intend to make a loop for the creation of the row across of icons, and one for the column down.
3.) Speed/Variable Issues: In an effort to make the code more efficient, what is the best way to treat the variables as far as local/global go, keeping in mind that the scope of this script? It seems like every time GetSchedule is run, the offsets are re-created, then destroyed at the end of the function. Is more memory/time used up if they are globals?
4.) Image Problems: During testing I start the script, check for my changes, almost immediately unload the script, and continue writing, repeating this an ungodly number of times throughout the night. I've noticed during some loads, some of the icons are loaded at full size instead of their reduced size. Are images not intended to be scaled yet, given the current capabilities of the interface? Or am I missing something in my object setup? Related question: The last row and column of pixels gets cut off on the images I'm displaying. Is this related to the above questions?
5.) If/Then Question: Since this is an adaptation of Neb's code, I kept his schedule function almost the same but call it twice since I need 2 columns instead of one. I added an If/Then and passed a variable to control it, but the lists that get output are reversed in order. I'm missing something obvious.
6.) Advanced Key Binding: I’m pretty familiar with the way Windower handles keybinds, but not Lunar. I can see how to bind/unbind and use keyboard input mostly from X-Drop’s programs, but I’m wondering if more advanced binding is possible yet, such as binding a command to key combos like alt+1, ctrl+e, leftwindows+F2, etc. Also, perhaps someone could clarify the order in which keyboard input it routed to Lunar, Windower, and FFXI. I’m interested in stopping certain key combinations from getting to FFXI so I can use them either in a lunar script or windower macro, but I have a feeling I’ll have to see the folks over at Azaril’s forum for something like that, right? I’m also interested in using the windows key like alt or ctrl is used in Windower/FFXI for macros.
Just a quick note: I’m trying to search for my own answers the best I can on this forum and on the web (when my question applies to lua scripting in general), so if there are answers to these questions on this forum that are highly visible, sorry that I have missed them :^)
Code:
-- Airship.lua
-- Version: 0.5
-- 01/16/05
-- By: JimmyTime
-- Purpose: Displays the departure schedule for airships
-- Notes:
-- - Based off of Nebula's Airship.lua
-- - Borrowed heavily from X-Drop's design of AggroCheck.lua
function Initialize()
-- Initialize Variables
GMTOffset = -5
FixTime = 15*60
xOffset = 2 -- x offset from the left
yOffset = 300 -- y offset from the top
closeHotKey = "F1" -- hot key for exiting the script
BasisDate = os.time{year=2002, month=6, day=23, hour=16+GMTOffset, min=0, sec=0}
MoonDate = os.time{year=2004, month=1, day=25, hour=2+GMTOffset, min=31, sec=12}
VanaDayList = {"Earthsday", "Watersday", "Windsday", "Iceday", "Lightningday", "Lightsday", "Darksday","Firesday"}
msGameDay = (24 * 60 * 60 * 1000 / 25) -- milliseconds in a game day
msRealDay = (24 * 60 * 60 * 1000) -- milliseconds in a real day
Control.control_BindKey(CloseHotKey,true,false,false,".Lunar command Airship.lua Unload")
Text1 = Graphics.text_CreateObject()
Graphics.text_SetPosition(xOffset+11,yOffset+14,Text1)
Graphics.text_SetColor(255,255,255,255,Text1)
Graphics.text_SetFont("Courier New",9,Text1)
Graphics.text_SetBold(true,Text1)
Text2 = Graphics.text_CreateObject()
Graphics.text_SetPosition(xOffset+90,yOffset+14,Text2)
Graphics.text_SetColor(255,255,255,255,Text2)
Graphics.text_SetFont("Courier New",9,Text2)
Graphics.text_SetBold(true,Text2)
BackGround=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset,yOffset,BackGround)
Graphics.primitive_SetColor(50,0,0,0,BackGround)
Graphics.primitive_SetSize(137,137,BackGround)
JeunoPic1=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+2,yOffset+2,JeunoPic1)
Graphics.primitive_SetColor(255,255,255,255,JeunoPic1)
Graphics.primitive_SetSize(24,24,JeunoPic1)
Graphics.primitive_SetTexture("Airship/jeuno.jpg",JeunoPic1)
ArrowPic1=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+29,yOffset+2,ArrowPic1)
Graphics.primitive_SetColor(255,255,255,255,ArrowPic1)
Graphics.primitive_SetSize(24,24,ArrowPic1)
Graphics.primitive_SetTexture("Airship/arrow.jpg",ArrowPic1)
AirshipPic=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+56,yOffset+2,AirshipPic)
Graphics.primitive_SetColor(255,255,255,255,AirshipPic)
Graphics.primitive_SetSize(24,24,AirshipPic)
Graphics.primitive_SetTexture("Airship/airship.jpg",AirshipPic)
ArrowPic2=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+83,yOffset+2,ArrowPic2)
Graphics.primitive_SetColor(255,255,255,255,ArrowPic2)
Graphics.primitive_SetSize(24,24,ArrowPic2)
Graphics.primitive_SetTexture("Airship/arrow.jpg",ArrowPic2)
JeunoPic2=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+110,yOffset+2,JeunoPic2)
Graphics.primitive_SetColor(255,255,255,255,JeunoPic2)
Graphics.primitive_SetSize(24,24,JeunoPic2)
Graphics.primitive_SetTexture("Airship/jeuno.jpg",JeunoPic2)
WindyPic=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+56,yOffset+29,WindyPic)
Graphics.primitive_SetColor(255,255,255,255,WindyPic)
Graphics.primitive_SetSize(24,24,WindyPic)
Graphics.primitive_SetTexture("Airship/windy.jpg",WindyPic)
SandyPic=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+56,yOffset+56,SandyPic)
Graphics.primitive_SetColor(255,255,255,255,SandyPic)
Graphics.primitive_SetSize(24,24,SandyPic)
Graphics.primitive_SetTexture("Airship/sandy.jpg",SandyPic)
BastokPic=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+56,yOffset+83,BastokPic)
Graphics.primitive_SetColor(255,255,255,255,BastokPic)
Graphics.primitive_SetSize(24,24,BastokPic)
Graphics.primitive_SetTexture("Airship/bastok.jpg",BastokPic)
KazhamPic=Graphics.primitive_CreateObject()
Graphics.primitive_SetPosition(xOffset+56,yOffset+110,KazhamPic)
Graphics.primitive_SetColor(255,255,255,255,KazhamPic)
Graphics.primitive_SetSize(24,24,KazhamPic)
Graphics.primitive_SetTexture("Airship/kazham.jpg",KazhamPic)
end
function GetSchedule(Column)
local now = os.time()
local elapsedTime = math.mod(now * 1000 - BasisDate * 1000, msGameDay) + 144000
local vTime = ((898 * 360 + 30) * msRealDay + FixTime*1000) + (now * 1000 - BasisDate * 1000) * 25
local vDay = math.floor(math.mod(vTime, 8 * msRealDay) / msRealDay) + 1
local offset1 = ((1 * 60) + 10) * 60 * 1000 / 25 -- 1:10 B->J J->S
local offset2 = ((2 * 60) + 40) * 60 * 1000 / 25 -- 2:40 J->W K-J
local offset3 = ((4 * 60) + 10) * 60 * 1000 / 25 -- 4:10 J->B S->J
local offset4 = ((5 * 60) + 35) * 60 * 1000 / 25 -- 5:35 J->K
local offset5 = ((5 * 60) + 45) * 60 * 1000 / 25 -- 5:45 W->J
local outAir = string.format("%s","")
if Column==1 then
outAir = outAir .. ASHelper(elapsedTime, offset2, vDay)
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset1, vDay)
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset3, vDay)
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset4, vDay)
else
outAir = outAir .. ASHelper(elapsedTime, offset5, vDay)
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset3, vDay)
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset1, vDay)
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset2, vDay)
end
return outAir
end
function HotKeyCheck()
if Windower.script_GetCommandCount()>0 then
for i=1,Windower.script_GetCommandCount(),1 do
Command[i]=Windower.script_GetCommand() --ignore all extra commands
end
DynamicFunction=_G[Command[1]] --execute first command only
DynamicFunction()
end
end
function ASHelper(Elapsed, Offset, Day)
local newOffset = Offset;
local count = 0
while (newOffset < Elapsed) do
count = count + 1
newOffset = newOffset + (msGameDay / 4)
end
if (count >= 4) then Day = math.mod(Day + 1, 8) end
local arrivalTime = newOffset - Elapsed - 144000
if (arrivalTime < 0) then arrivalTime = 0 end
local s = string.format("%s\n",padstring(formatTime(newOffset-Elapsed),8))
return s
end
function padstring(s,len)
if string.len(s) > len then return s end
s = s .. string.rep(" ",len-string.len(s))
return s
end
function formatTime(t)
local hourLeft = (t / msRealDay - math.floor(t / msRealDay)) * 24
local minLeft = (hourLeft - math.floor(hourLeft)) * 60
local secLeft = (minLeft - math.floor(minLeft)) * 60
return string.format("%02d:%02d",math.floor(minLeft),secLeft)
end
function Unload()
Quit = 1
end
function CloseOut()
Control.control_UnbindKey(CloseHotKey,true,false,false)
if Windower.script_GetCommandCount()>0 then
for i=2,Windower.script_GetCommandCount(),1 do
Command[i]=Windower.script_GetCommand() --ignore all extra commands
end
end
Graphics.primitive_DeleteAll()
Graphics.text_DeleteAll()
end
-- Main --
Initialize()
while Quit==0 do
TextColumn = 1
Output = string.format("\n%s\n",GetSchedule(TextColumn))
Graphics.text_SetText(Output,Text1)
TextColumn = 2
Output = string.format("\n%s\n",GetSchedule(TextColumn))
Graphics.text_SetText(Output,Text2)
HotKeyCheck()
Windower.script_Sleep(100)
end
CloseOut()
Screenshot:
fbs.freewebspace.com/cgi-bin/i/Airship_Shot.jpg
There we go. Let me know what you think, and thanks in advance for looking over it.