-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: qbx_teleports feat: correct placement on the ground by default on teleport * fix: vehicle teleport * refactor: remove .xyz from the coordinate parameter of the created zone * refactor: unnecessary brackets Co-authored-by: Manason <[email protected]> * refactor: passage items to variables, ground detection to shared section * chore: modulo explanation --------- Co-authored-by: Manason <[email protected]>
- Loading branch information
1 parent
89717f6
commit 05ef67c
Showing
2 changed files
with
90 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,94 @@ | ||
local config = lib.loadJson('qbx_teleports.config') | ||
|
||
CreateThread(function() | ||
local sleep | ||
while true do | ||
sleep = 1000 | ||
local pedCoords = GetEntityCoords(cache.ped) | ||
|
||
for _, passage in ipairs(config.teleports) do | ||
passage[1].coords = vec4(passage[1].coords) | ||
passage[2].coords = vec4(passage[2].coords) | ||
for k, v in ipairs(passage) do | ||
local dist = #(pedCoords - v.coords.xyz) | ||
if dist < 2 then | ||
sleep = 0 | ||
DrawMarker(2, v.coords.x, v.coords.y, v.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.15, 255, 255, 255, 255, false, false, 0, true, nil, nil, false) | ||
|
||
if dist < 1 then | ||
qbx.drawText3d({ text = v.drawText, coords = v.coords}) | ||
if IsControlJustReleased(0, 51) then | ||
local i = k % 2 + 1 | ||
local dstCoords = passage[i].coords | ||
if v.allowVehicle then | ||
SetPedCoordsKeepVehicle(cache.ped, dstCoords.x, dstCoords.y, dstCoords.z) | ||
else | ||
SetEntityCoords(cache.ped, dstCoords.x, dstCoords.y, dstCoords.z, true, false, false, false) | ||
end | ||
|
||
if type(dstCoords) == 'vector4' then | ||
SetEntityHeading(cache.ped, dstCoords.w) | ||
end | ||
end | ||
end | ||
if #config.teleports == 0 then return end | ||
|
||
local zones = {} | ||
|
||
AddEventHandler('onResourceStop', function (resourceName) | ||
if GetCurrentResourceName() ~= resourceName then return end | ||
|
||
for _, zone in ipairs(zones) do | ||
zone:remove() | ||
end | ||
end) | ||
|
||
local destination | ||
|
||
CreateThread(function () | ||
for _, passage in ipairs(config.teleports) do | ||
for i = 1, #passage do | ||
local entrance = passage[i] | ||
local exit = passage[(i % 2) + 1] -- (1 % 2) -> 1 (2 % 2) -> 0 | ||
local coords = vec3(entrance.coords) | ||
zones[#zones+1] = lib.zones.sphere({ | ||
coords = coords, | ||
radius = 2, | ||
onEnter = function () | ||
lib.showTextUI(entrance.drawText) | ||
destination = { | ||
coords = vec(exit.coords), | ||
ignoreGround = exit.ignoreGround, | ||
allowVehicle = entrance.allowVehicle | ||
} | ||
end, | ||
onExit = function () | ||
lib.hideTextUI() | ||
destination = nil | ||
end | ||
end | ||
}) | ||
end | ||
|
||
Wait(sleep) | ||
end | ||
end) | ||
|
||
local keybind | ||
|
||
local function onPressed() | ||
keybind:disable(true) | ||
if destination then | ||
local coordZ = destination.coords.z | ||
|
||
if not destination.ignoreGround then | ||
local isSafe, z = GetGroundZFor_3dCoord( | ||
destination.coords.x, | ||
destination.coords.y, | ||
destination.coords.z, | ||
false | ||
) | ||
|
||
if isSafe then coordZ = z end | ||
end | ||
|
||
if destination.allowVehicle and cache.vehicle then | ||
SetPedCoordsKeepVehicle( | ||
cache.ped, | ||
destination.coords.x, | ||
destination.coords.y, | ||
coordZ | ||
) | ||
|
||
SetVehicleOnGroundProperly(cache.vehicle) | ||
else | ||
SetEntityCoords( | ||
cache.ped, | ||
destination.coords.x, | ||
destination.coords.y, | ||
coordZ, | ||
true, false, false, false | ||
) | ||
end | ||
|
||
if type(destination.coords) == 'vector4' then | ||
SetEntityHeading(cache.ped, destination.coords.w) | ||
end | ||
end | ||
keybind:disable(false) | ||
end | ||
|
||
keybind = lib.addKeybind({ | ||
name = 'passage', | ||
description = 'entry through passage', | ||
defaultKey = 'E', | ||
secondaryMapper = 'PAD_DIGITALBUTTONANY', | ||
secondaryKey = 'LRIGHT_INDEX', | ||
onPressed = onPressed | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters