[SAMemory] Ошибка при получении "nVehicleClass"

sVor

Активный
Автор темы
187
100
Версия MoonLoader
.026-beta
Приветствую, я получаю "nVehicleClass" через "SAMemory", но во время использования иногда получаю ошибку "cannot resume non-suspended coroutine". Какую можно поставить проверку, дабы предотвратить её возникновение? Через проверку на нахождение в авто оно тоже проходит
code:
local samem = require 'SAMemory'
local player_vehicle = samem.cast('CVehicle **', samem.player_vehicle)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
   
    while true do
        wait(0)
        veh = player_vehicle[0]
        sampAddChatMessage("nVehicleClass = "..veh.nVehicleClass, -1) -- проблемная строка
    end
end
 
Решение
Вот так должно работать
Lua:
local samem = require('SAMemory')
samem.require 'CVehicle'
local player_vehicle = samem.cast('CVehicle **', samem.player_vehicle)

function main()
    while not isSampAvailable() do wait(100) end
 
    while true do wait(0)
        if isCharInAnyCar(playerPed) then
            veh = samem.player_vehicle[0]
            if veh ~= samem.nullptr then
            sampAddChatMessage("nVehicleClass = "..veh.nVehicleClass, -1)
            end
        end
    end
end

qdIbp

Автор темы
Проверенный
1,451
1,193
Вот так должно работать
Lua:
local samem = require('SAMemory')
samem.require 'CVehicle'
local player_vehicle = samem.cast('CVehicle **', samem.player_vehicle)

function main()
    while not isSampAvailable() do wait(100) end
 
    while true do wait(0)
        if isCharInAnyCar(playerPed) then
            veh = samem.player_vehicle[0]
            if veh ~= samem.nullptr then
            sampAddChatMessage("nVehicleClass = "..veh.nVehicleClass, -1)
            end
        end
    end
end
 
Последнее редактирование:
  • Нравится
Реакции: sVor и YarikVL

sVor

Активный
Автор темы
187
100
Вот так должно работать
Lua:
local samem = require('SAMemory')
samem.require 'CVehicle'
local player_vehicle = samem.cast('CVehicle **', samem.player_vehicle)

function main()
    while not isSampAvailable() do wait(100) end
 
    while true do wait(0)
        if isCharInAnyCar(playerPed) then
            veh = samem.player_vehicle[0]
            sampAddChatMessage("nVehicleClass = "..veh.nVehicleClass, -1) -- проблемная строка
        end
    end
end
attempt to index global 'veh' (a number value)
Если просто проверять нахождение в авто:
cannot resume non-suspended coroutine - При нахождении в авто
cannot resume non-suspended coroutine:
if isCharInAnyCar(playerPed) then
    veh = player_vehicle[0]
    sampAddChatMessage("nVehicleClass ="..veh.nVehicleClass, -1)
end
 

qdIbp

Автор темы
Проверенный
1,451
1,193
Вот так должно работать
Lua:
local samem = require('SAMemory')
samem.require 'CVehicle'
local player_vehicle = samem.cast('CVehicle **', samem.player_vehicle)

function main()
    while not isSampAvailable() do wait(100) end
 
    while true do wait(0)
        if isCharInAnyCar(playerPed) then
            veh = samem.player_vehicle[0]
            if veh ~= samem.nullptr then
            sampAddChatMessage("nVehicleClass = "..veh.nVehicleClass, -1)
            end
        end
    end
end
Upd
 

Похожие темы

    • Закреплено
    Ответы
    24
    Просмотры
    47K