From d76ec0c5a0fcdcb9cdc06e38ea260266d85c93d7 Mon Sep 17 00:00:00 2001 From: Vftdan Date: Sat, 14 Oct 2023 15:35:22 +0300 Subject: [PATCH] wallhack: showing entity look direction --- augment/modules/wh.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/augment/modules/wh.lua b/augment/modules/wh.lua index 955c072..c236d9a 100644 --- a/augment/modules/wh.lua +++ b/augment/modules/wh.lua @@ -1,20 +1,27 @@ return function() local playerLookVector = nil - local function updateLookVector() + local function getEntityLookVector(entity) -- yaw: -- 0 => positive Z -- 90 => negative X -- pitch: -- 0 => forward -- 90 => down - local yawr = math.rad(player.yaw) - local pitchr = math.rad(player.pitch) + if entity == nil or entity.yaw == nil or entity.pitch == nil then + return {0, 0, 0, x = 0, y = 0, z = 0} + end + local yawr = math.rad(entity.yaw) + local pitchr = math.rad(entity.pitch) local cosPitch = math.cos(pitchr) local x = cosPitch * -math.sin(yawr) local z = cosPitch * math.cos(yawr) local y = -math.sin(pitchr) - playerLookVector = {x, y, z, x = x, y = y, z = z} + return {x, y, z, x = x, y = y, z = z} + end + + local function updateLookVector() + playerLookVector = getEntityLookVector(player) return playerLookVector end @@ -68,18 +75,26 @@ return function() cache[id].cube.setSize(0.5, 0.5, 0.5) cache[id].frame = canvas3d.addFrame({ 0, 0, 0 }) cache[id].text = cache[id].frame.addText({ 0, 0 }, "") + cache[id].lookDot = canvas3d.addDot({ 0, 0, 0 }, 0, 2) end local entityFront = toFrontCoords(entity) + local entityLook = getEntityLookVector(entity) + local entityLookEnd = vec3Add(entityFront, entityLook) if entityFront.flipped then cache[id].cube.setColor(0x004040FF) + cache[id].lookDot.setColor(0x004040FF) else cache[id].cube.setColor(0xFFC0C0FF) + cache[id].lookDot.setColor(0xFFC0C0FF) end cache[id].cube.setAlpha(0x20) + cache[id].lookDot.setAlpha(0x10) cache[id].cube.setDepthTested(false) cache[id].frame.setDepthTested(false) + cache[id].lookDot.setDepthTested(false) cache[id].cube.setPosition(entityFront.x - 0.25, entityFront.y - 0.25, entityFront.z - 0.25) cache[id].frame.setPosition(entityFront.x, entityFront.y, entityFront.z) + cache[id].lookDot.setPosition(entityLookEnd.x, entityLookEnd.y, entityLookEnd.z) cache[id].text.setAlpha(0xFF) if player.isSneaking then cache[id].text.setText(entity.name .. "\n" .. textutils.serialize(entity))