-
Notifications
You must be signed in to change notification settings - Fork 120
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
Conversation
There was a problem hiding this 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.
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') |
There was a problem hiding this comment.
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
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') |
There was a problem hiding this comment.
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
Yes I agree. until then we have no choice here |
Alternative solution: #507 |
Description
Checklist