o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Untitled conversation
- Userlua
- Assistant
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local window = imgui.ImBool(false)
local checkboxValue = imgui.ImBool(false)
local checkboxBlipValue = imgui.ImBool(false)
local checkboxMarkerValue = imgui.ImBool(false)
local checkboxInCar = imgui.ImBool(false)
local enableInCarText = "Disabled"
local enableText = "Disabled"
local enableBlipText = "Disabled"
local enableMarkerText = "Disabled"
local pos = {x = imgui.ImBuffer(128), y = imgui.ImBuffer(128), z = imgui.ImBuffer(128)}
local stepDistance = imgui.ImInt(5)
local stepDelay = imgui.ImInt(1000)
local markerDistance = imgui.ImInt(100)
local visotaGovnovoz = imgui.ImInt(100)
function main()
while not isSampAvailable() do
wait(200)
end
imgui.Process = false
window.v = false
sampRegisterChatCommand("otp", toggleInterface)
sampRegisterChatCommand("otpr", function()
local posX, posY, posZ = tonumber(pos.x.v) or 0.0, tonumber(pos.y.v) or 0.0, tonumber(pos.z.v) or 0.0
if posX and posY and posZ then
if checkboxValue.v then
teleportPlayerStepByStep(PLAYER_PED, posX, posY, posZ)
else
setCharCoordinates(PLAYER_PED, posX, posY, posZ)
end
else
print("Debug")
end
end)
while true do
wait(0)
imgui.Process = window.v
end
end
function toggleInterface()
window.v = not window.v
end
function SearchMarker(posX, posY, posZ, radius, isRace)
local ret_posX = 0.0
local ret_posY = 0.0
local ret_posZ = 0.0
local isFind = false
for id = 0, 31 do
local MarkerStruct = 0
if isRace then
MarkerStruct = 0xC7F168 + id * 56
else
MarkerStruct = 0xC7DD88 + id * 160
end
local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
ret_posX = MarkerPosX
ret_posY = MarkerPosY
ret_posZ = MarkerPosZ
isFind = true
radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
end
end
end
return isFind, ret_posX, ret_posY, ret_posZ
end
function getTargetBlipCoordinatesFixed()
local bool, x, y, z = getTargetBlipCoordinates(); if not bool then return false end
requestCollision(x, y); loadScene(x, y, z)
local bool, x, y, z = getTargetBlipCoordinates()
return bool, x, y, z
end
function samp_create_sync_data(sync_type, copy_from_player)
local ffi = require 'ffi'
local sampfuncs = require 'sampfuncs'
-- from SAMP.Lua
local raknet = require 'samp.raknet'
require 'samp.synchronization'
copy_from_player = copy_from_player or true
local sync_traits = {
player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
}
local sync_info = sync_traits[sync_type]
local data_type = 'struct ' .. sync_info[1]
local data = ffi.new(data_type, {})
local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
-- copy player's sync data to the allocated memory
if copy_from_player then
local copy_func = sync_info[3]
if copy_func then
local _, player_id
if copy_from_player == true then
_, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
else
player_id = tonumber(copy_from_player)
end
copy_func(player_id, raw_data_ptr)
end
end
-- function to send packet
local func_send = function()
local bs = raknetNewBitStream()
raknetBitStreamWriteInt8(bs, sync_info[2])
raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
raknetDeleteBitStream(bs)
end
-- metatable to access sync data and 'send' function
local mt = {
__index = function(t, index)
return data[index]
end,
__newindex = function(t, index, value)
data[index] = value
end
}
return setmetatable({send = func_send}, mt)
end
function teleportPlayerStepByStep(playerPed, posX, posY, posZ)
lua_thread.create(function()
local playerX, playerY, playerZ = getCharCoordinates(playerPed)
local groundZ = getGroundZFor3dCoord(posX, posY, posZ)
local stepX = (posX - playerX) / stepDistance.v
local stepY = (posY - playerY) / stepDistance.v
local stepZ = (groundZ - playerZ) / stepDistance.v
if math.abs(posX - playerX) > stepDistance.v or
math.abs(posY - playerY) > stepDistance.v or
math.abs(posZ - playerZ) > stepDistance.v then
for i = 1, stepDistance.v do
playerX = playerX + stepX
playerY = playerY + stepY
playerZ = playerZ + stepZ
local data = samp_create_sync_data('player')
data.moveSpeed.x = math.random(100, 1000)
data.moveSpeed.y = math.random(100, 1000)
data.moveSpeed.y = math.random(100, 1000)
data.send()
sampForceOnfootSync()
setCharCoordinates(playerPed, playerX, playerY, playerZ)
wait(stepDelay.v)
end
end
end)
end
function imgui.OnDrawFrame()
if window.v then
imgui.SetNextWindowPos(imgui.ImVec2(350.0, 250.0), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(550, 450), imgui.Cond.FirstUseEver)
imgui.Begin('OTP By Tectrex', window)
if isCharInAnyCar(PLAYER_PED) then
if checkboxInCar.v then
local car = getCarCharIsUsing(PLAYER_PED)
local posX, posY, posZ = tonumber(pos.x.v) or 0.0, tonumber(pos.y.v) or 0.0, tonumber(pos.z.v) or 0.0
local carX, carY, carZ = getCarCoordinates(car)
local h = getHeadingFromVector2d(posX - carX, posY - carY)
setCarCoordinates(car, carX, carY, visotaGovnovoz.v)
setCarForwardSpeed(car, 100)
setCarHeading(car, h)
setCharCanBeKnockedOffBike(PLAYER_PED, true)
else
freezeCarPosition(getCarCharIsUsing(PLAYER_PED), false)
setCharCanBeKnockedOffBike(PLAYER_PED, false)
end
imgui.Text("Player incar")
else
imgui.Text("Player not incar")
end
if imgui.Checkbox("Enable Govnovoz", checkboxInCar) then
enableInCarText = checkboxInCar.v and "Enabled" or "Disabled"
end
imgui.SetCursorPosX(100)
imgui.SameLine()
imgui.Text("Govnovoz: " .. enableInCarText)
if imgui.Checkbox("Enable Coord-Master", checkboxValue) then
enableText = checkboxValue.v and "Enabled" or "Disabled"
end
imgui.SameLine()
imgui.Text("Coord-Master: " .. enableText)
if imgui.Checkbox("Enable Blip Finder", checkboxBlipValue) then
enableBlipText = checkboxBlipValue.v and "Enabled" or "Disabled"
end
imgui.SameLine()
imgui.Text("Blip Finder: " .. enableBlipText)
if checkboxBlipValue.v then
local bool, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
if bool then
pos.x.v, pos.y.v, pos.z.v = tostring(blipX), tostring(blipY), tostring(blipZ)
else
printStringNow("No blip found", 1000)
end
end
if imgui.Checkbox("Enable Marker Finder", checkboxMarkerValue) then
enableMarkerText = checkboxMarkerValue.v and "Enabled" or "Disabled"
end
imgui.SameLine()
imgui.Text("Marker Finder: " .. enableMarkerText)
if checkboxMarkerValue.v then
local posX, posY, posZ = getCharCoordinates(PLAYER_PED)
local isFind, markerX, markerY, markerZ = SearchMarker(posX, posY, posZ, markerDistance.v, false)
if isFind then
pos.x.v, pos.y.v, pos.z.v = tostring(markerX), tostring(markerY), tostring(markerZ)
else
printStringNow("No marker found trying again.", 1000)
local isFind2, markerX, markerY, markerZ = SearchMarker(posX, posY, posZ, markerDistance.v, true)
if isFind2 then
pos.x.v, pos.y.v, pos.z.v = tostring(markerX), tostring(markerY), tostring(markerZ)
end
end
end
for _, v in pairs({"X", "Y", "Z"}) do
if imgui.InputText(v, pos[v:lower()]) then
print("Debug")
end
end
if imgui.Button("Get PLAYER_PED Coordinates") then
local x, y, z = getCharCoordinates(PLAYER_PED)
pos.x.v, pos.y.v, pos.z.v = tostring(x), tostring(y), tostring(z)
end
if imgui.Button("Get Marker Coordinates") then
local posX, posY, posZ = getCharCoordinates(PLAYER_PED)
local isFind, markerX, markerY, markerZ = SearchMarker(posX, posY, posZ, markerDistance.v, false)
if isFind then
pos.x.v, pos.y.v, pos.z.v = tostring(markerX), tostring(markerY), tostring(markerZ)
else
printStringNow("No marker found trying again.", 1000)
local isFind2, markerX, markerY, markerZ = SearchMarker(posX, posY, posZ, markerDistance.v, true)
if isFind2 then
pos.x.v, pos.y.v, pos.z.v = tostring(markerX), tostring(markerY), tostring(markerZ)
end
end
end
if imgui.Button("Get Blip Coordinates") then
local bool, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
if bool then
pos.x.v, pos.y.v, pos.z.v = tostring(blipX), tostring(blipY), tostring(blipZ)
else
printStringNow("No blip found", 1000)
end
end
imgui.Separator()
if imgui.SliderInt("Visota", visotaGovnovoz, 1, 500) then
printStringNow("Visota: " .. visotaGovnovoz.v, 1000)
end
imgui.SameLine()
imgui.TextDisabled("(Высота говновоза)")
imgui.Separator()
if imgui.SliderInt("Step", stepDistance, 1, 500) then
printStringNow("Step: " .. stepDistance.v, 1000)
end
imgui.SameLine()
imgui.TextDisabled("(Кол-во шагов на тп)")
imgui.Separator()
if imgui.SliderInt("Step Delay (ms)", stepDelay, 0, 1000) then
printStringNow("Step Delay: " .. stepDelay.v .. "ms", 1000)
end
imgui.SameLine()
imgui.TextDisabled("(Задержка)")
imgui.Separator()
if imgui.SliderInt("MD", markerDistance, 1, 10000) then
printStringNow("Distance: " .. markerDistance.v, 1000)
end
imgui.SameLine()
imgui.TextDisabled("(Радиус поиска маркера)")
imgui.Separator()
if imgui.Button("Teleport") then
local posX, posY, posZ = tonumber(pos.x.v) or 0.0, tonumber(pos.y.v) or 0.0, tonumber(pos.z.v) or 0.0
if posX and posY and posZ then
if checkboxValue.v then
teleportPlayerStepByStep(PLAYER_PED, posX, posY, posZ)
else
setCharCoordinates(PLAYER_PED, posX, posY, posZ)
end
else
print("Debug")
end
end
imgui.End()
end
end
Оптимизируй код, структурируй код, улучши код, улучши алгоритмы, улучши код, следуй принципам KISS, YAGNI, DRY, Закон Деметры, S.O.L.I.D
Certainly! Let's optimize and restructure your Lua script by adhering to the KISS, YAGNI, DRY, Law of Demeter, and SOLID principles. Below are the key improvements made:
Here's the optimized and restructured version of your script:
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
-- Configuration Tables
local Config = {
window = imgui.ImBool(false),
checkboxes = {
coordMaster = imgui.ImBool(false),
blipFinder = imgui.ImBool(false),
markerFinder = imgui.ImBool(false),
govnovoz = imgui.ImBool(false),
inCar = imgui.ImBool(false),
},
texts = {
coordMaster = "Disabled",
blipFinder = "Disabled",
markerFinder = "Disabled",
govnovoz = "Disabled",
inCar = "Disabled",
},
position = {
x = imgui.ImBuffer(128),
y = imgui.ImBuffer(128),
z = imgui.ImBuffer(128)
},
sliders = {
stepDistance = imgui.ImInt(5),
stepDelay = imgui.ImInt(1000),
markerDistance = imgui.ImInt(100),
visotaGovnovoz = imgui.ImInt(100)
}
}
-- Utility Functions
local function toggleInterface()
Config.window.v = not Config.window.v
end
local function updateText(checkbox, textKey)
Config.texts[textKey] = checkbox.v and "Enabled" or "Disabled"
end
local function getNumericPosition()
return tonumber(Config.position.x.v) or 0.0,
tonumber(Config.position.y.v) or 0.0,
tonumber(Config.position.z.v) or 0.0
end
local function setPlayerCoordinates(x, y, z)
setCharCoordinates(PLAYER_PED, x, y, z)
end
local function printDebug()
print("Debug")
end
-- Teleportation Functions
local function teleportPlayer(playerPed, targetX, targetY, targetZ, stepDistance, stepDelay)
lua_thread.create(function()
local currentX, currentY, currentZ = getCharCoordinates(playerPed)
local groundZ = getGroundZFor3dCoord(targetX, targetY, targetZ)
local deltaX = (targetX - currentX) / stepDistance
local deltaY = (targetY - currentY) / stepDistance
local deltaZ = (groundZ - currentZ) / stepDistance
for i = 1, stepDistance do
currentX = currentX + deltaX
currentY = currentY + deltaY
currentZ = currentZ + deltaZ
local syncData = samp_create_sync_data('player')
syncData.moveSpeed.x = math.random(100, 1000)
syncData.moveSpeed.y = math.random(100, 1000)
syncData.moveSpeed.z = math.random(100, 1000)
syncData.send()
sampForceOnfootSync()
setPlayerCoordinates(playerPed, currentX, currentY, currentZ)
wait(stepDelay)
end
end)
end
-- Marker and Blip Functions
local function searchMarkers(posX, posY, posZ, radius, isRace)
local baseAddress = isRace and 0xC7F168 or 0xC7DD88
local markerStructSize = isRace and 56 or 160
local closest = {distance = radius, x = 0.0, y = 0.0, z = 0.0}
for id = 0, 31 do
local markerAddress = baseAddress + id * markerStructSize
local markerX = representIntAsFloat(readMemory(markerAddress, 4, false))
local markerY = representIntAsFloat(readMemory(markerAddress + 4, 4, false))
local markerZ = representIntAsFloat(readMemory(markerAddress + 8, 4, false))
if markerX ~= 0.0 or markerY ~= 0.0 or markerZ ~= 0.0 then
local distance = getDistanceBetweenCoords3d(markerX, markerY, markerZ, posX, posY, posZ)
if distance < closest.distance then
closest = {distance = distance, x = markerX, y = markerY, z = markerZ}
end
end
end
if closest.distance < radius then
return true, closest.x, closest.y, closest.z
end
return false, 0.0, 0.0, 0.0
end
local function getBlipCoordinates()
local success, x, y, z = getTargetBlipCoordinates()
if not success then return false end
requestCollision(x, y)
loadScene(x, y, z)
success, x, y, z = getTargetBlipCoordinates()
return success, x, y, z
end
-- Synchronization Function
local function createSyncData(sync_type, copy_from_player)
local ffi = require 'ffi'
local sampfuncs = require 'sampfuncs'
local raknet = require 'samp.raknet'
require 'samp.synchronization'
copy_from_player = copy_from_player ~= false -- Default to true
local sync_traits = {
player = { "PlayerSyncData", raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData },
vehicle = { "VehicleSyncData", raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData },
passenger = { "PassengerSyncData", raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData },
aim = { "AimSyncData", raknet.PACKET.AIM_SYNC, sampStorePlayerAimData },
trailer = { "TrailerSyncData", raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData },
unoccupied = { "UnoccupiedSyncData", raknet.PACKET.UNOCCUPIED_SYNC, nil },
bullet = { "BulletSyncData", raknet.PACKET.BULLET_SYNC, nil },
spectator = { "SpectatorSyncData", raknet.PACKET.SPECTATOR_SYNC, nil }
}
local trait = sync_traits[sync_type]
if not trait then error("Invalid sync type: " .. tostring(sync_type)) end
local dataType = 'struct ' .. trait[1]
local data = ffi.new(dataType)
local rawDataPtr = tonumber(ffi.cast('uintptr_t', ffi.new(dataType .. '*', data)))
if copy_from_player then
local copyFunc = trait[3]
if copyFunc then
local player_id = (copy_from_player == true) and sampGetPlayerIdByCharHandle(PLAYER_PED) or tonumber(copy_from_player)
copyFunc(player_id, rawDataPtr)
end
end
local function sendPacket()
local bs = raknetNewBitStream()
raknetBitStreamWriteInt8(bs, trait[2])
raknetBitStreamWriteBuffer(bs, rawDataPtr, ffi.sizeof(data))
raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
raknetDeleteBitStream(bs)
end
return setmetatable({ send = sendPacket }, {
__index = function(t, key) return data[key] end,
__newindex = function(t, key, value) data[key] = value end
})
end
-- GUI Rendering Functions
local function renderCheckbox(label, checkbox, textKey)
if imgui.Checkbox(label, checkbox) then
updateText(checkbox, textKey)
end
imgui.SameLine()
imgui.Text(string.format("%s: %s", label, Config.texts[textKey]))
end
local function renderButton(label, onClick)
if imgui.Button(label) then
onClick()
end
end
local function renderSlider(label, slider, min, max, tooltip)
if imgui.SliderInt(label, slider, min, max) then
printStringNow(string.format("%s: %d", label, slider.v), 1000)
end
imgui.SameLine()
imgui.TextDisabled(tooltip)
end
local function renderPositionInputs()
for _, axis in ipairs({"X", "Y", "Z"}) do
if imgui.InputText(axis, Config.position[axis:lower()].v) then
-- Optional: Add validation or additional actions here
end
end
end
-- Main Drawing Function
function imgui.OnDrawFrame()
if not Config.window.v then return end
imgui.SetNextWindowPos(imgui.ImVec2(350.0, 250.0), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(550, 450), imgui.Cond.FirstUseEver)
if imgui.Begin('OTP By Tectrex', Config.window) then
-- Player In Car Status
if isCharInAnyCar(PLAYER_PED) then
imgui.Text("Player in car")
if Config.checkboxes.govnovoz.v then
local car = getCarCharIsUsing(PLAYER_PED)
local posX, posY, posZ = getNumericPosition()
local carX, carY, carZ = getCarCoordinates(car)
local heading = getHeadingFromVector2d(posX - carX, posY - carY)
setCarCoordinates(car, carX, carY, Config.sliders.visotaGovnovoz.v)
setCarForwardSpeed(car, 100)
setCarHeading(car, heading)
setCharCanBeKnockedOffBike(PLAYER_PED, true)
else
local car = getCarCharIsUsing(PLAYER_PED)
freezeCarPosition(car, false)
setCharCanBeKnockedOffBike(PLAYER_PED, false)
end
else
imgui.Text("Player not in car")
end
imgui.Separator()
-- Checkboxes with Labels and States
renderCheckbox("Enable Govnovoz", Config.checkboxes.govnovoz, "govnovoz")
renderCheckbox("Enable Coord-Master", Config.checkboxes.coordMaster, "coordMaster")
renderCheckbox("Enable Blip Finder", Config.checkboxes.blipFinder, "blipFinder")
renderCheckbox("Enable Marker Finder", Config.checkboxes.markerFinder, "markerFinder")
-- Automatic Position Updates
if Config.checkboxes.blipFinder.v then
local success, x, y, z = getBlipCoordinates()
if success then
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(x), tostring(y), tostring(z)
else
printStringNow("No blip found", 1000)
end
end
if Config.checkboxes.markerFinder.v then
local posX, posY, posZ = getCharCoordinates(PLAYER_PED)
local found, markerX, markerY, markerZ = searchMarkers(posX, posY, posZ, Config.sliders.markerDistance.v, false)
if found then
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(markerX), tostring(markerY), tostring(markerZ)
else
printStringNow("No marker found, attempting race markers.", 1000)
local foundRace, raceX, raceY, raceZ = searchMarkers(posX, posY, posZ, Config.sliders.markerDistance.v, true)
if foundRace then
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(raceX), tostring(raceY), tostring(raceZ)
end
end
end
imgui.Separator()
-- Position Inputs
renderPositionInputs()
-- Action Buttons
renderButton("Get PLAYER_PED Coordinates", function()
local x, y, z = getCharCoordinates(PLAYER_PED)
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(x), tostring(y), tostring(z)
end)
renderButton("Get Marker Coordinates", function()
local posX, posY, posZ = getCharCoordinates(PLAYER_PED)
local found, markerX, markerY, markerZ = searchMarkers(posX, posY, posZ, Config.sliders.markerDistance.v, false)
if found then
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(markerX), tostring(markerY), tostring(markerZ)
else
printStringNow("No marker found, attempting race markers.", 1000)
local foundRace, raceX, raceY, raceZ = searchMarkers(posX, posY, posZ, Config.sliders.markerDistance.v, true)
if foundRace then
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(raceX), tostring(raceY), tostring(raceZ)
end
end
end)
renderButton("Get Blip Coordinates", function()
local success, x, y, z = getBlipCoordinates()
if success then
Config.position.x.v, Config.position.y.v, Config.position.z.v = tostring(x), tostring(y), tostring(z)
else
printStringNow("No blip found", 1000)
end
end)
imgui.Separator()
-- Sliders
renderSlider("Visota", Config.sliders.visotaGovnovoz, 1, 500, "(Высота говновоза)")
renderSlider("Step", Config.sliders.stepDistance, 1, 500, "(Кол-во шагов на тп)")
renderSlider("Step Delay (ms)", Config.sliders.stepDelay, 0, 1000, "(Задержка)")
renderSlider("MD", Config.sliders.markerDistance, 1, 10000, "(Радиус поиска маркера)")
imgui.Separator()
-- Teleport Button
renderButton("Teleport", function()
local x, y, z = getNumericPosition()
if x and y and z then
if Config.checkboxes.coordMaster.v then
teleportPlayer(PLAYER_PED, x, y, z, Config.sliders.stepDistance.v, Config.sliders.stepDelay.v)
else
setPlayerCoordinates(x, y, z)
end
else
printDebug()
end
end)
end
imgui.End()
end
-- Main Function
function main()
while not isSampAvailable() do
wait(200)
end
imgui.Process = false
Config.window.v = false
-- Register Chat Commands
sampRegisterChatCommand("otp", toggleInterface)
sampRegisterChatCommand("otpr", function()
local x, y, z = getNumericPosition()
if x and y and z then
if Config.checkboxes.coordMaster.v then
teleportPlayer(PLAYER_PED, x, y, z, Config.sliders.stepDistance.v, Config.sliders.stepDelay.v)
else
setPlayerCoordinates(x, y, z)
end
else
printDebug()
end
end)
-- Main Loop
while true do
wait(0)
imgui.Process = Config.window.v
end
end
-- Start the Script
main()
Configuration Tables:
Config: Grouped all related configurations (window state, checkboxes, texts, positions, sliders) into a single table for organized management.Utility Functions:
toggleInterface: Simplified function to toggle the GUI window.updateText: Updates the status text based on checkbox state.getNumericPosition: Retrieves and parses the position inputs, defaulting to 0.0 if invalid.setPlayerCoordinates and printDebug: Simplified helper functions.Teleportation Logic:
teleportPlayer: Refactored teleportation to handle step-by-step movement with teleportPlayerStepByStep logic encapsulated in a dedicated function.Marker and Blip Handling:
searchMarkers: Optimized search by storing the closest marker found within the radius and returning early when a closer marker is found.getBlipCoordinates: Streamlined function to fetch and validate blip coordinates.Synchronization:
createSyncData: Made more robust by handling invalid sync types and defaulting copy_from_player appropriately.GUI Rendering:
renderCheckbox, renderButton, renderSlider, renderPositionInputs: Created reusable functions to render GUI components, adhering to the DRY principle.imgui.OnDrawFrame: Cleaned up the main drawing function by utilizing the helper rendering functions for better readability and maintainability.Main Function:
main: Organized the initialization process, command registration, and main loop for clarity.Feel free to further customize and expand upon this structure based on your specific requirements!
Not yet included in a published release.