Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced lib.waitFor with while, in qbx.spawnVehicle #506

Closed
wants to merge 1 commit into from

Conversation

abdel1touimi
Copy link

Description

Checklist

  • I have personally loaded this code into an updated Qbox project and checked all of its functionality.
  • My pull request fits the contribution guidelines & code conventions.

Copy link
Member

@solareon solareon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be improved by an extension to the lib.waitFor that provides the ability to return to a different callback, in this case to delete the entity rather than erroring.

Comment on lines +270 to 288
local foundOwner = false
local timeout = 5000
while not foundOwner and timeout > 0 do
local owner = NetworkGetEntityOwner(veh)
if ped then
--- the owner should be transferred to the driver
if owner == NetworkGetEntityOwner(ped) then return true end
if owner == NetworkGetEntityOwner(ped) then
foundOwner = true
end
else
if owner ~= -1 then return true end
if owner ~= -1 then
foundOwner = true
end
end
end, 'client never set as owner', 5000)

timeout -= 10
Wait(10)
end
if not foundOwner then
DeleteEntity(veh)
error('Deleting vehicle which timed out finding an owner')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can replace this with something like this (untested)

local timeout = 5000
local targetOwner = ped and NetworkGetEntityOwner(ped) or false
while timeout >= 0 do
    local owner = NetworkGetEntityOwner(veh)
    if (targetOwner and owner == targetOwner) or (not targetOwner and owner ~= -1) then
        break
    end
    timeout -= 10
    if timeout <= 0 then
        DeleteEntity(veh)
        error('Deleting vehicle which timed out finding an owner')
    end
    Wait(10)
end

Comment on lines 294 to 307
if props and type(props) == 'table' and props.plate then
state:set('setVehicleProperties', props, true)
local success = lib.waitFor(function()
timeout = 5000
local success = false
while not success and timeout > 0 do
if qbx.string.trim(GetVehicleNumberPlateText(veh)) == qbx.string.trim(props.plate) then
return true
success = true
end
end, 'Failed to set vehicle properties within 5 seconds', 5000)
timeout -= 10
Wait(10)
end
if not success then
DeleteEntity(veh)
error('Deleting vehicle which timed out setting vehicle properties')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar fix for this section also untested

if props and type(props) == 'table' and props.plate then
    state:set('setVehicleProperties', props, true)
    timeout = 5000
    while timeout > 0 do
        if qbx.string.trim(GetVehicleNumberPlateText(veh)) == qbx.string.trim(props.plate) then
            break
        end
        timeout -= 10
        if timeout <= 0 then
            DeleteEntity(veh)
            error('Deleting vehicle which timed out setting vehicle properties')
        end
        Wait(10)
    end
end

@abdel1touimi
Copy link
Author

This could also be improved by an extension to the lib.waitFor that provides the ability to return to a different callback, in this case to delete the entity rather than erroring.

Yes I agree. until then we have no choice here

@Manason
Copy link
Member

Manason commented Jul 5, 2024

Alternative solution: #507

@KostaZx KostaZx closed this Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants