10-16-2013, 09:47 PM
Code:
Teleport = { }
Teleport.coordspath = GetStartupPath() .. [[\LuaMods\Teleport\Coords\]];
Teleport.CoordsProfile = {}
Teleport.lastticks = 0
Teleport.running = false
Teleport.curTask = nil
Teleport.CoordsFiles = {}
Teleport.UIRefreshPending = false
Teleport.UIRefreshTmr = 0
-------------------------------------------------
-- Made by Breckdareck --
-- Will try to add more soon --
--Just now learning how to code lua and its fun--
--Thanks to MMOMinion for the code and allowing--
-- the use of add on scripts! --
-- --
-- I hope maybe i could work for you!! --
-------------------------------------------------
function Teleport.teleport()
if (Settings.FFXIVMINION.clickteleactive == nil) then
Settings.FFXIVMINION.clickteleactive = "0"
end
if (Settings.FFXIVMINION.coordsname == nil) then
Settings.FFXIVMINION.coordsname = "None"
end
GUI_NewWindow("Teleport",400,100,250,430)
-- Navigation functions
GUI_NewField("Teleport","X: ","tb_xPos","Teleport Coords")
GUI_NewField("Teleport","Y: ","tb_yPos","Teleport Coords")
GUI_NewField("Teleport","Z: ","tb_zPos","Teleport Coords")
--Target Coords
GUI_NewField("Teleport","Name","TargetName","TargetInfo")
GUI_NewField("Teleport","X:","TargetPosX","TargetInfo")
GUI_NewField("Teleport","Y:","TargetPosY","TargetInfo")
GUI_NewField("Teleport","Z:","TargetPosZ","TargetInfo")
--Save Coords
GUI_NewField("Teleport","Coords name: ","coordsnewname","Coords Save")
GUI_NewButton("Teleport","SaveCoords","SaveCoord","Coords Save")
RegisterEventHandler("SaveCoord", Teleport.Save)
--Saved Coords
GUI_NewComboBox("Teleport","Coords Name: ","coordsname","Saved Coords","")
GUI_NewField("Teleport","X:","SavedX","Saved Coords")
GUI_NewField("Teleport","Y:","SavedY","Saved Coords")
GUI_NewField("Teleport","Z:","SavedZ","Saved Coords")
--Get Coords Button
GUI_NewButton("Teleport","GetCurrentPos","Teleport.playerPosition")
RegisterEventHandler("Teleport.playerPosition", Teleport.Move)
--Teleport to Saved Coords Button
GUI_NewButton("Teleport","Tele2SavedCoords","Teleport.saved")
RegisterEventHandler("Teleport.saved", Teleport.Move4)
--Teleport to Target Button
GUI_NewButton("Teleport","Tele2Target","Teleport.target")
RegisterEventHandler("Teleport.target", Teleport.Move2)
--Teleport Button
GUI_NewButton("Teleport","Teleport","Teleport.teleport")
RegisterEventHandler("Teleport.teleport", Teleport.Move)
tb_nPoints = 0
--Show Targets Coords
GUI_NewButton("Teleport","ShowCoords","Teleport.Test2","TargetInfo")
--Turn on/off Click2Tele
GUI_NewCheckbox("Teleport","Activated","clickteleactive","ClickTele")
clickteleactive = Settings.FFXIVMINION.clickteleactive
coordsnewname = ""
Teleport.CoordsProfile = {}
Teleport.UpdateCoords()
Teleport.UpdateCoordsData()
TLE_XCOORD = 0
TLE_YCOORD = 0
TLE_ZCOORD = 0
TLE_IDK = 0
GUI_UnFoldGroup("Teleport","Teleport Coords")
GUI_UnFoldGroup("Teleport","TargetInfo")
GUI_UnFoldGroup("Teleport","Coords Save")
GUI_UnFoldGroup("Teleport","Saved Coords")
GUI_WindowVisible("Teleport",true)
GUI_SizeWindow("Teleport",250,425)
end
function Teleport.Move( dir )
if ( dir == "Teleport.playerPosition") then
local p = Player.pos
tb_xPos = tostring(p.x)
tb_yPos = tostring(p.y)
tb_zPos = tostring(p.z)
elseif( dir == "Teleport.teleport") then
GameHacks:TeleportToXYZ(tonumber(tb_xPos),tonumber(tb_yPos),tonumber(tb_zPos))
end
end
function Teleport.Move2( dir )
if ( dir == "Teleport.playerPosition") then
local p = Player.pos
TargetPosX = tostring(p.x)
TargetPosY = tostring(p.y)
TargetPosZ = tostring(p.z)
elseif( dir == "Teleport.target") then
GameHacks:TeleportToXYZ(tonumber(TargetPosX),tonumber(TargetPosY),tonumber(TargetPosZ))
end
end
function Teleport.Move3(event,tickcount)
if ( MeshManager:IsKeyPressed(160) ) then
GameHacks:TeleportToCursorPosition()
end
end
function Teleport.Move4( dir )
if ( dir == "Teleport.playerPosition") then
elseif( dir == "Teleport.saved") then
GameHacks:TeleportToXYZ(tonumber(SavedX),tonumber(SavedY),tonumber(SavedZ))
end
end
function Teleport.Update()
mytarget = Player:GetTarget()
if (mytarget ~= nil) then
TargetName = mytarget.name
TargetPosX = (math.floor(mytarget.pos.x * 10) / 10)
TargetPosY = (math.floor(mytarget.pos.y * 10) / 10)
TargetPosZ = (math.floor(mytarget.pos.z * 10) / 10)
end
end
function Teleport.Test2()
Teleport.running = not Teleport.running
if ( not Teleport.running) then Teleport.curTask = nil end
d(Teleport.running)
end
function Teleport.DoTask()
if (Teleport.curTask) then
Teleport.curTask()
end
end
--Updates everything
function Teleport.GUIVarUpdate(Event, NewVals, OldVals)
for k,v in pairs(NewVals) do
--d(tostring(k).." = "..tostring(v))
if ( k == "clickteleactive" ) then
Settings.FFXIVMINION[tostring(k)] = v
elseif ( k == "coordsname" )then
Teleport.CoordsProfile = {}
Teleport.UpdateCoordsData()
Settings.FFXIVMINION.coordsname = tostring(v)
elseif ( k == "TLE_XCOORD") then Teleport.CoordsProfile.XCOord = v
elseif ( k == "TLE_YCOORD") then Teleport.CoordsProfile.YCOord = v
elseif ( k == "TLE_ZCOORD") then Teleport.CoordsProfile.ZCOord = v
elseif ( k == "TLE_IDK") then Teleport.CoordsProfile.idk = v
end
end
end
function Teleport.OnUpdateHandler( Event, ticks )
if ( ticks - Teleport.lastticks > 500 ) then
Teleport.lastticks = ticks
if ( Teleport.running ) then
Teleport.Update()
elseif ( clickteleactive == "1") then
Teleport.Move3()
end
end
-- Needed because the UI cant handle clearing + rebuilding of all stuff in the same frame
if ( Teleport.UIRefreshPending ) then
if ( Teleport.UIRefreshTmr == 0 ) then
Teleport.UIRefreshTmr = tick
elseif( tick - Teleport.UIRefreshTmr > 250 ) then
Teleport.UIRefreshTmr = 0
Teleport.RefreshSkillList()
Teleport.UIRefreshPending = false
end
end
end
--Grasb all Profiles and enlist them in the dropdown field
function Teleport.UpdateCoords()
local coordsprofiles = "None"
local found = "None"
local coordsprofilelist = dirlist(Teleport.coordspath,".*lua")
if ( TableSize(coordsprofilelist) > 0) then
local i,coordsprofile = next ( coordsprofilelist)
while i and coordsprofile do
coordsprofile = string.gsub(coordsprofile, ".lua", "")
coordsprofiles = coordsprofiles..","..coordsprofile
if ( Settings.FFXIVMINION.coordsname ~= nil and Settings.FFXIVMINION.coordsname == coordsprofile ) then
d("Last Profile found : "..coordsprofile)
found = coordsprofile
end
i,coordsprofile = next ( coordsprofilelist,i)
end
end
coordsname_listitems = coordsprofiles
coordsname = found
end
--Save under new file
function Teleport.Save()
local xCoord = tonumber(tb_xPos)
local yCoord = tonumber(tb_yPos)
local zCoord = tonumber(tb_zPos)
local filename = ""
local isnew = false
if ( coordsnewname ~= "" ) then
filename = coordsnewname
coordsnewname = ""
isnew = true
elseif (coordsprofile ~= nil and coordsprofile ~= "None" and coordsprofile ~= "") then
filename = coordsname
coordsnewname = ""
end
if ( filename ~= "" ) then
local string2write = "TLE_Version_1=1\n"
local name,coords = next (Teleport.CoordsProfile)
while name and coords do
d("Saving Profile Data into File: "..filename)
string2write = string2write.."TLE_XCOORD="..xCoord.."\n"
string2write = string2write.."TLE_YCOORD="..yCoord.."\n"
string2write = string2write.."TLE_ZCOORD="..zCoord.."\n"
string2write = string2write.."TLE_IDK="..coords.idk.."\n"
string2write = string2write.."TLE_END=0\n"
name,coords = next (Teleport.CoordsProfile,name)
end
d(filewrite(Teleport.coordspath ..filename..".lua",string2write))
if ( isnew ) then
coordsname_listitems = coordsname_listitems..","..filename
coordsname = filename
Settings.FFXIVMINION.coordsname = filename
end
end
end
function Teleport.UpdateCoordsData()
if ( coordsname ~= nil and coordsname ~= "" and coordsname ~= "None" ) then
local profile = fileread(Teleport.coordspath..coordsname..".lua")
if ( TableSize(profile) > 0) then
local unsortedCoordsList = {}
local newcoords = {}
local i, line = next (profile)
if ( line ) then
local version
-- Check for backwards compatib
local _, key, id, value = string.match(line, "(%w+)_(%w+)_(%d+)=(.*)")
if ( tostring(key) == "Version" and tostring(id) == "1") then
version = 1
end
while i and line do
local key, value
if ( version == 1 ) then
_, key, value = string.match(line, "(%w+)_(%w+)=(.*)")
end
--d("key: "..tostring(key).." value:"..tostring(value))
if (key and value ) then
value = string.gsub(value, "\r", "")
if ( key == "End" )then
table.insert(unsortedCoordsList,tonumber(newcoords.idk),newcoords)
newcoords = {}
elseif ( key == "XCOORD") then newcoords.XCOord = tonumber(value)
elseif ( key == "YCOORD") then newcoords.YCOord = tonumber(value)
elseif ( key == "ZCOORD") then newcoords.ZCOord = tonumber(value)
elseif ( key == "IDK") then newcoords.idk = tonumber(value)
end
else
d("Error loading inputline: Key: "..(tostring(key)).." value:"..tostring(value))
end
i, line = next (profile,i)
end
end
end
end
end
RegisterEventHandler("Module.Initalize",Teleport.teleport)
RegisterEventHandler("Gameloop.Update", Teleport.OnUpdateHandler)
RegisterEventHandler("Teleport.Test2", Teleport.Test2)
RegisterEventHandler("GUI.Update",Teleport.GUIVarUpdate)
Everything is Practically done now, all i need is to grab the data from the files and put them into the new Field i have.