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 function getBoatAttachmentOffset(trailer)
local model = GetEntityModel(trailer) local model = GetEntityModel(trailer)
if model == `boattrailer6` then 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 else
return vector3(0.0, -1.02, 0.3) -- Original boattrailer values return vector3(0.0, -1.02, 0.3) -- Original boattrailer values
end end
@ -532,18 +532,23 @@ local function attachBoatToTrailer()
boatOnTrailer = true boatOnTrailer = true
end end
-- Replace the existing winch control thread with this improved version
CreateThread(function() CreateThread(function()
while true do while true do
Wait(createdRope and controlRope and 0 or 1000) Wait(0)
if createdRope and controlRope then if createdRope and controlRope then
if ropeLength == 1.0 then -- Display help text for winch controls
attachBoatToTrailer() BeginTextCommandDisplayHelp("STRING")
ropeLength = 10.0 AddTextComponentSubstringPlayerName("~INPUT_FRONTEND_UP~ Extend winch | ~INPUT_FRONTEND_DOWN~ Retract winch | ~INPUT_FRONTEND_RRIGHT~ Cancel")
end 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 if IsControlPressed(0, 172) then
ropeLength = ropeLength + lengthTick ropeLength = ropeLength + lengthTick * 2 -- Doubled speed for better responsiveness
if ropeLength > Config.MaxRopeLength then if ropeLength > Config.MaxRopeLength then
ropeLength = Config.MaxRopeLength ropeLength = Config.MaxRopeLength
@ -552,51 +557,87 @@ CreateThread(function()
StopRopeWinding(createdRope) StopRopeWinding(createdRope)
StartRopeUnwindingFront(createdRope) StartRopeUnwindingFront(createdRope)
RopeForceLength(createdRope, ropeLength) RopeForceLength(createdRope, ropeLength)
-- Add visual feedback
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
elseif IsControlJustReleased(0, 172) then elseif IsControlJustReleased(0, 172) then
StopRopeUnwindingFront(createdRope) StopRopeUnwindingFront(createdRope)
StopRopeWinding(createdRope) StopRopeWinding(createdRope)
RopeConvertToSimple(createdRope) RopeConvertToSimple(createdRope)
-- Retract rope (Arrow Down)
elseif IsControlPressed(0, 173) then elseif IsControlPressed(0, 173) then
ropeLength = ropeLength - lengthTick ropeLength = ropeLength - lengthTick * 2 -- Doubled speed for better responsiveness
if ropeLength < minRopeLength then if ropeLength < minRopeLength then
ropeLength = minRopeLength ropeLength = minRopeLength
-- Auto-attach boat when fully retracted
if hookedToBoat then
attachBoatToTrailer()
notify("Boot erfolgreich auf den Anhänger gezogen")
end
end end
StopRopeUnwindingFront(createdRope) StopRopeUnwindingFront(createdRope)
StartRopeWinding(createdRope) StartRopeWinding(createdRope)
RopeForceLength(createdRope, ropeLength) RopeForceLength(createdRope, ropeLength)
-- Add visual feedback
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
elseif IsControlJustReleased(0, 173) then elseif IsControlJustReleased(0, 173) then
StopRopeUnwindingFront(createdRope) StopRopeUnwindingFront(createdRope)
StopRopeWinding(createdRope) StopRopeWinding(createdRope)
RopeConvertToSimple(createdRope) RopeConvertToSimple(createdRope)
end
end
if createdRope and hasTakenRope then -- Cancel winch control (Backspace)
local playerPed = PlayerPedId() elseif IsControlJustPressed(0, 194) then
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
controlRope = false controlRope = false
colObj = nil notify("Windensteuerung beendet")
boatOnTrailer = false
end 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 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