taoletsgo / custom_races

A script for loading GTA:Online races in FiveM.
The Unlicense
13 stars 3 forks source link

Support for pit stop and f1 wear and tear as online #1

Closed wiruwiru closed 3 weeks ago

wiruwiru commented 1 month ago

It would be nice to be able to bring 100% openwheel mode with pits stops and wear of wheels and vehicles, so I was testing the plugin this does not bring it and would be something very new to add to the script.

wiruwiru commented 1 month ago

It would also be good to add the rebasar (rebufo in Spanish). I think in English it would say something like drafting

taoletsgo commented 1 month ago

Hey, I did some research on repair zone in json file before, but I gave up because I got stuck in the tire wear function. Here are some residual codes, maybe you can use them.

-- client-side code function SetCar(_car, positionX, positionY, positionZ, heading, engine) local carHash = carTransformed ~= "" and carTransformed or (type(_car) == "number" and _car or _car.model) local ped = PlayerPedId()

if isInOpenWheelRaceMode and GetVehicleClassFromName(carHash) == 22 then
    if not IsVehicleDriveable(lastVehicle) then
        repairCar(lastVehicle)
    end
    SetPedIntoVehicle(ped, lastVehicle, -1)
    SetEntityCoords(lastVehicle, positionX, positionY, positionZ)
    SetEntityHeading(lastVehicle, heading)
    SetGameplayCamRelativeHeading(0)
    return
end
---
-- other codes
---

end

function StartRace()

-- other codes
---
Citizen.CreateThread(function()
    while status == "racing" do
        ---
        -- other codes
        ---
        local ped = PlayerPedId()
        local vehicle = GetVehiclePedIsIn(ped, false)

        if isInOpenWheelRaceMode and GetVehicleClassFromName(GetEntityModel(vehicle)) == 22 then
            tireWear(vehicle)
            showVehicleHealthAndTireBar(vehicle)
        end

        ---
        -- other codes
        ---
        local checkPointTouched = false
        local playerCoords = GetEntityCoords(ped)
        local _playerCoords = vector3(playerCoords.x, playerCoords.y, playerCoords.z)

        if #(_playerCoords - repair_coords) <= 15 then
            if not hasRepairCar and IsPedInAnyVehicle(ped) and GetEntitySpeed(vehicle) <= 5 then
                repairCar(vehicle)
                hasRepairCar = true
            end
        else
            hasRepairCar = false
        end
        ---
        -- other codes
        ---
        Citizen.Wait(0)
    end
end)
---
-- other codes
---

end

function repairCar(vehicle) SetVehicleUndriveable(vehicle, false) SetVehicleEngineCanDegrade(vehicle, false) SetVehicleEngineHealth(vehicle, 1000.0) SetVehiclePetrolTankHealth(vehicle, 1000.0) SetVehicleEngineOn(vehicle, true, true) SetVehicleFixed(vehicle) StopEntityFire(vehicle) SetVehicleOilLevel(vehicle, 1.0) SetVehicleDirtLevel(vehicle, 0) SetVehicleDeformationFixed(vehicle) end

function tireWear(vehicle) -- Requires additional scripts to implement -- example: I got stuck here before, so I gave up end

function showVehicleHealthAndTireBar(vehicle) -- Requires additional scripts to implement -- example: https://forum.cfx.re/t/release-carhud-and-helihud-modified-and-better-looking-v-1-9-new-update/97812 end

RegisterNetEvent("custom_races:loadTrack", function(_data, _track, objects, dobjects, _weatherAndHour, _laps)

-- other codes
---
for _, zone in ipairs(track.zones) do
    if zone.type == "repair" and not DoesBlipExist(repair_blip) then -- Maybe some JSON has more than 2 repair zones?
        CreateCheckpoint(5, zone.x, zone.y, zone.z, 0, 0, 0, 15, 0, 80, 100, 50)
        repair_blip = AddBlipForCoord(zone.x, zone.y, zone.z)
        SetBlipSprite(repair_blip, 446) -- https://docs.fivem.net/docs/game-references/blips/
        isInOpenWheelRaceMode = true
        repair_coords = vector3(zone.x, zone.y, zone.z)
    end
end

end)

wiruwiru commented 1 month ago

Okey, thank you very much for your answer, it would be nice to implement it as customization options in the room, it would be a good thing for the future, thanks for the help I will try to investigate how I can make the wear of the wheels and show the state of the vehicle in the hud, I'm not really good at lua but if I find a way to do it I will not hesitate to share it.