Lua died due to an error

CeSum

Участник
Автор темы
30
0
Версия MoonLoader
.027.0-preview
Script:

function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampAddChatMessage("{FF2020}[Test] {FFF101}is successfull loaded! Use /test")
sampRegisterChatCommand("test",test)
wait(-1)
end
function test(arg)
local _, handle = sampGetCharHandleBySampPlayerId(arg)
x,y,z = getCharCoordinates(handle)
placeWaypoint(x, y, z)
end

error:

[13:45:44.567804] (system) test.lua: Loaded successfully.
[13:45:46.430924] (error) test.lua: opcode '00A0' call caused an unhandled exception
stack traceback:
[C]: in function 'getCharCoordinates'
D:\SAMP\moonloader\test.lua:12: in function <D:\SAMP\moonloader\test.lua:10>
[13:45:46.431924] (error) test.lua: Script died due to an error. (0C8E72AC)
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,765
11,213
1. это будет работать только в зоне стрима
2.
Lua:
sampGetCharHandleBySampPlayerId(tonumber(arg))
3. ты должен проверять получилось ли получить хендл игрока
Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function(arg)
        if tonumber(arg) then
            local id = tonumber(arg)
            if sampIsPlayerConnected(id) then
                local result, handle = sampGetCharHandleBySampPlayerId(id)
                if result then
                    local x, y, z = getCharCoordinates(handle)
                    placeWaypoint(x, y, z)
                    sampAddChatMessage('Метка поставлена на '..x..', '..y..', '..z, -1)
                else
                    sampAddChatMessage('ошибка, игрок вне зоны стрима', -1)
                end
            end
        else
            sampAddChatMessage('долбаеб, введи ид', -1)
        end
    end)
    wait(-1)
end
 

CeSum

Участник
Автор темы
30
0
1. это будет работать только в зоне стрима
2.
Lua:
sampGetCharHandleBySampPlayerId(tonumber(arg))
3. ты должен проверять получилось ли получить хендл игрока
Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function(arg)
        if tonumber(arg) then
            local id = tonumber(arg)
            if sampIsPlayerConnected(id) then
                local result, handle = sampGetCharHandleBySampPlayerId(id)
                if result then
                    local x, y, z = getCharCoordinates(handle)
                    placeWaypoint(x, y, z)
                    sampAddChatMessage('Метка поставлена на '..x..', '..y..', '..z, -1)
                else
                    sampAddChatMessage('ошибка, игрок вне зоны стрима', -1)
                end
            end
        else
            sampAddChatMessage('долбаеб, введи ид', -1)
        end
    end)
    wait(-1)
end

спасибо