Here's code to port to the chest/skyshard nearest to the camera focus (by radians apart):
Code:
elseif FrameworkTools.TeleportKeyPressed then
local groundPosition = Game.GetGroundTargetLocation();
if groundPosition then
Hacks.Teleport(groundPosition);
end
FrameworkTools.TeleportKeyPressed = false;
elseif FrameworkTools.GUI_CheckboxTrackChests.checked and Keyboard.IsKeyDown(0x21) then
-- Set the key as pressed
FrameworkTools.ChestKeyPressed = true;
local groundPosition = Game.GetGroundTargetLocation();
if groundPosition then
-- Get camera vector
local deltaX = groundPosition.x - localPlayer.position.x;
local deltaY = groundPosition.y - localPlayer.position.y;
local camAngle = math.atan2(deltaY, deltaX);
-- Get the chest/skyshard closest to what we're aiming at.
for unit in Game.GetUnits() do
if unit.name == "Chest" or unit.name == "Skyshard" then
deltaX = unit.position.x - localPlayer.position.x;
deltaY = unit.position.y - localPlayer.position.y;
local poiAngle = math.atan2(deltaY, deltaX);
local thisVector = math.abs(smod(camAngle, 2*math.pi) - smod(poiAngle, 2*math.pi));
FrameworkTools.poiTable[thisVector] = unit;
if FrameworkTools.poiMin == nil or thisVector < FrameworkTools.poiMin then
FrameworkTools.poiMin = thisVector;
end
end
end
end
-- Check if it's up, and was pressed before (ie: released)
elseif FrameworkTools.ChestKeyPressed and FrameworkTools.poiMin then
local thisItem = FrameworkTools.poiTable[FrameworkTools.poiMin];
Hacks.Teleport(thisItem.position);
FrameworkTools.ChestKeyPressed = false;
FrameworkTools.poiTable = {};
FrameworkTools.poiMin = nil;
end
of course you have to init the following variables up top in the script:
Code:
FrameworkTools.poiTable = {};
FrameworkTools.poiMin = nil;
and last but not least, our symmetric modulo function:
Code:
function smod(x, m)
return x-((math.floor(x/m + 0.5))*m);
end
Yeah that's awesome, you're welcome.
PS: God, there has to be a better way to determine where the camera is pointing >.<
<playerVar>.heading returns which way the player model is facing which is useless.
I added player detection code to this personally but I want yall to get banned...less competition...so...
...just joking (mostly). I'll have a viable teleport block function within a day or so...it currently checks for players within 10 meters of an object, and further checks for any players within 40 meters who have a heading towards the target object, +/- 0.5 rad. May adjust these numbers as I see fit before release.
Anyway whatever.
Also I'd like to request the following functions:
Utils.print
...and all it's friends
to print to chat.
Utils.read, write, open, close
...to read and write to files in the script dir. The built-in lua file commands need to be DISABLED DISABLED DISABLED because they dump into the game binary directory and are a HUGE security risk. We need a 'sandbox' so users aren't (as)at risk from cleverly designed scripts.
Game.unit.mapId
...return target unit's map ID. Because the function that zenimax gives us is dependent on the current map you have open.