- Версия MoonLoader
- .027.0-preview
How do I fix this error in this script?
(error) closestVehicle.lua: opcode '09B3' call caused an unhandled exception
stack traceback:
[C]: in function 'getCarDoorLockStatus'
... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:27: in function <... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:5>
(error) closestVehicle.lua: opcode '00AA' call caused an unhandled exception
stack traceback:
[C]: in function 'getCarCoordinates'
... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:31: in function <... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:5>
(error) closestVehicle.lua: opcode '09B3' call caused an unhandled exception
stack traceback:
[C]: in function 'getCarDoorLockStatus'
... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:27: in function <... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:5>
(error) closestVehicle.lua: opcode '00AA' call caused an unhandled exception
stack traceback:
[C]: in function 'getCarCoordinates'
... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:31: in function <... st\Otomoos\GTA San Andreas\moonloader\closestVehicle.lua:5>
Lua:
script_description("This script finds and marks the nearest unoccupied car that the player can approach.")
function main()
while not isSampAvailable() do
wait(200)
end
-- Register the chat command "/nc"
sampRegisterChatCommand("nc", function()
local ped = PLAYER_PED
-- damn it if the player is inside the vehicle
if isCharInAnyBoat(ped) or isCharInAnyCar(ped) or isCharInAnyHeli(ped)
or isCharInAnyPlane(ped) or isCharOnAnyBike(ped) then
sampAddChatMessage("You can't use this command while inside the vehicle.", -1347440726)
return
end
-- Check if the player is indoors
if getActiveInterior() ~= 0 then
sampAddChatMessage("You can't use this command here.", -1347440726)
return
end
local nearestVehicle = nil
local vehicle, _ = storeClosestEntities(ped)
local isOccupied = false
-- Go through all the players to check if the nearest vehicle is occupied.
for PlayerID = 0, sampGetMaxPlayerId(false) do
local result, playerped = sampGetCharHandleBySampPlayerId(PlayerID)
if result then
-- Check if the player is inside the nearest vehicle
if isCharInCar(playerped, vehicle) then
isOccupied = true
break
end
end
end
-- Check if the nearest car is empty and if its doors are unlocked.
if not isOccupied and getCarDoorLockStatus(vehicle) == 0 then
nearestVehicle = vehicle
end
-- If a nearby unoccupied vehicle is found, mark it.
if nearestVehicle then
local vehicleX, vehicleY, vehicleZ = getCarCoordinates(nearestVehicle)
-- Remove existing flash (if any)
removeBlip(checkpoint)
-- Create a new tag for the nearest car
checkpoint = addBlipForCar(nearestVehicle)
changeBlipColour(checkpoint, 0x355E3BFF)
-- Create a flow to wait for the player to get close to the vehicle.
lua_thread.create(function()
repeat
wait(0)
local playerX, playerY, playerZ = getCharCoordinates(ped)
until getDistanceBetweenCoords3d(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ) < 3.0 or not doesBlipExist(checkpoint)
-- Remove the mark as soon as it is reached and play the sound.
removeBlip(checkpoint)
addOneOffSound(0, 0, 0, 1149)
end)
-- Instruct the player to follow the checkpoint to the nearest vehicle.
sampAddChatMessage("Follow from the checkpoint to the nearest car.", 0xFFFFFF)
end
end)
while true do
wait(0)
end
end