1
0
Fork 0
forked from Simnation/Main

Update main.lua

This commit is contained in:
Nordi98 2025-07-02 06:59:46 +02:00
parent 3c3b623d20
commit 8fab0a4bcf

View file

@ -23,7 +23,7 @@ end
local function getBoatAttachmentOffset(trailer)
local model = GetEntityModel(trailer)
if model == `boattrailer6` then
return vector3(0.0, -1.0, 0.25) -- Adjusted values for boattrailer6
return vector3(0.0, -1.0, 0.75) -- Adjusted values for boattrailer6
else
return vector3(0.0, -1.02, 0.3) -- Original boattrailer values
end
@ -532,18 +532,23 @@ local function attachBoatToTrailer()
boatOnTrailer = true
end
-- Replace the existing winch control thread with this improved version
CreateThread(function()
while true do
Wait(createdRope and controlRope and 0 or 1000)
Wait(0)
if createdRope and controlRope then
if ropeLength == 1.0 then
attachBoatToTrailer()
ropeLength = 10.0
end
-- Display help text for winch controls
BeginTextCommandDisplayHelp("STRING")
AddTextComponentSubstringPlayerName("~INPUT_FRONTEND_UP~ Extend winch | ~INPUT_FRONTEND_DOWN~ Retract winch | ~INPUT_FRONTEND_RRIGHT~ Cancel")
EndTextCommandDisplayHelp(0, false, true, -1)
-- Show current rope length
DrawTextOnScreen("Rope Length: " .. string.format("%.1f", ropeLength) .. "m", 0.5, 0.05, 0.4, {r=255, g=255, b=255, a=200})
-- Extend rope (Arrow Up)
if IsControlPressed(0, 172) then
ropeLength = ropeLength + lengthTick
ropeLength = ropeLength + lengthTick * 2 -- Doubled speed for better responsiveness
if ropeLength > Config.MaxRopeLength then
ropeLength = Config.MaxRopeLength
@ -552,51 +557,87 @@ CreateThread(function()
StopRopeWinding(createdRope)
StartRopeUnwindingFront(createdRope)
RopeForceLength(createdRope, ropeLength)
-- Add visual feedback
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
elseif IsControlJustReleased(0, 172) then
StopRopeUnwindingFront(createdRope)
StopRopeWinding(createdRope)
RopeConvertToSimple(createdRope)
-- Retract rope (Arrow Down)
elseif IsControlPressed(0, 173) then
ropeLength = ropeLength - lengthTick
ropeLength = ropeLength - lengthTick * 2 -- Doubled speed for better responsiveness
if ropeLength < minRopeLength then
ropeLength = minRopeLength
-- Auto-attach boat when fully retracted
if hookedToBoat then
attachBoatToTrailer()
notify("Boot erfolgreich auf den Anhänger gezogen")
end
end
StopRopeUnwindingFront(createdRope)
StartRopeWinding(createdRope)
RopeForceLength(createdRope, ropeLength)
-- Add visual feedback
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
elseif IsControlJustReleased(0, 173) then
StopRopeUnwindingFront(createdRope)
StopRopeWinding(createdRope)
RopeConvertToSimple(createdRope)
end
end
if createdRope and hasTakenRope then
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local trailerOffset = getTrailerOffset(closestTrailer)
local trailerCoords = GetOffsetFromEntityInWorldCoords(closestTrailer, trailerOffset.x, trailerOffset.y, trailerOffset.z)
local coordsDiff = #(trailerCoords - playerCoords)
if coordsDiff > Config.MaxRopeLength then
notify("Du bist zu weit vom Anhänger weg")
DeleteRope(createdRope)
DeleteEntity(colObj)
FreezeEntityPosition(closestTrailer, false)
SetEntityInvincible(closestTrailer, false)
SetEntityInvincible(closestBoat, false)
closestTrailer = nil
closestBoat = nil
hasTakenRope = false
hookedToBoat = false
-- Cancel winch control (Backspace)
elseif IsControlJustPressed(0, 194) then
controlRope = false
colObj = nil
boatOnTrailer = false
notify("Windensteuerung beendet")
end
-- Visual indicator for rope tension
local tensionColor = {r=255, g=255, b=255, a=200}
if ropeLength < 3.0 then
-- High tension (red)
tensionColor = {r=255, g=0, b=0, a=200}
elseif ropeLength < 6.0 then
-- Medium tension (yellow)
tensionColor = {r=255, g=255, b=0, a=200}
end
DrawTextOnScreen("Tension: " .. GetTensionText(ropeLength), 0.5, 0.08, 0.4, tensionColor)
else
Wait(1000) -- Wait longer if not controlling the winch
end
end
end)
-- Helper function to draw text on screen
function DrawTextOnScreen(text, x, y, scale, color)
SetTextFont(4)
SetTextProportional(true)
SetTextScale(scale, scale)
SetTextColour(color.r, color.g, color.b, color.a)
SetTextDropShadow(0, 0, 0, 0, 255)
SetTextEdge(2, 0, 0, 0, 150)
SetTextDropShadow()
SetTextOutline()
SetTextCentre(true)
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x, y)
end
-- Helper function to get tension text based on rope length
function GetTensionText(length)
if length < 3.0 then
return "HIGH"
elseif length < 6.0 then
return "MEDIUM"
else
return "LOW"
end
end