help me

cenor_yt

Новичок
Автор темы
13
0
Нарушение правил раздела
Версия MoonLoader
.026-beta
нужен код, пишу к примеру
/tp 1 -- Телепортирует на координаты 446 142 -1414
/tp 2 -- Телепортирует на координаты 975 642 -654
и.т.д

думал сделать так
::
script_name("post")
script_version("1.1")

local imgui = require 'mimgui'
inicfg = require 'inicfg'
aut = '{6196ff} Andrey_Pilov'
pref = '{0d5eff}[TP Post] {ffffff}'

function main()
    sampRegisterChatCommand('cmd', function() WinState[0] = not WinState[0] end)
    wait(-1)
end

sampRegisterChatCommand("tp", function(arg)
    if arg == 1
    setCharCoordinates(PLAYER_PED, 1725, 1662, 307)
    if arg == 2
    setCharCoordinates(PLAYER_PED, 1241, 7653, 412)
end)
Но как показала практика, оно так не работает
 

XONE

Участник
7
6
Быть может твой агрумент arg является типом string, а ты его сравниваешь с типом int?

Иными словами: 1 ≠ '1'

Код:
sampRegisterChatCommand("tp", function(arg)
    if arg == '1' then
        setCharCoordinates(PLAYER_PED, 1725, 1662, 307)
    end
    if arg == '2' then
        setCharCoordinates(PLAYER_PED, 1241, 7653, 412)
    end
end)
 

qdIbp

Автор темы
Проверенный
1,390
1,146
Lua:
script_name("post")
script_version("1.0")
script_author('Andrey_Pilov')

local inicfg = require('inicfg')
local imgui = require('mimgui')

local pref = '{0d5eff}[TP Post] {ffffff}'
local tep = {
    {1725, 1662, 307},
    {1241, 7653, 412},
}

function main()
    repeat wait(0) until isSampAvailable()

    sampRegisterChatCommand('cmd', function()
        WinState[0] = not WinState[0]
    end)
  
    sampRegisterChatCommand('tp', function(arg)
        arg = tonumber(arg) or 0
        if arg > 0 and #tep >= arg then
            setCharCoordinates(PLAYER_PED, tep[arg][1], tep[arg][2], tep[arg][3])
        end
    end) 
    wait(-1)
end
 
  • Нравится
Реакции: MLycoris

cenor_yt

Новичок
Автор темы
13
0
Благодарю.
некст вопрос


1:
script_name("post")
script_version("1.1")

local imgui = require 'mimgui'
inicfg = require 'inicfg'
aut = '{6196ff} Andrey_Pilov'
pref = '{0d5eff}[TP Post] {ffffff}'

function main()
    sampRegisterChatCommand('cmd', function() WinState[0] = not WinState[0] end)
    wait(-1)
end

sampRegisterChatCommand("mpost", function(arg)
    if arg == '1' then
        setCharCoordinates(PLAYER_PED, 19.2, 33.2, 1005.8)
        wait(1500)
        sampSendChat("/tpint 5")
        wait(1500)
        sampSendChat("/tpvw 10")
        sampAddChatMessage('Телепортировали', -1)
    end
    if arg == '2' then
        setCharCoordinates(PLAYER_PED, -779.12, 527.80, 1375.65)
        wait(1500)
        sampSendChat("/tpint 1")
        wait(1500)
        sampSendChat("/tpvw 10")
        sampAddChatMessage('Телепортировали', -1)
    end
end)
Скипт крашит на wait
 
  • Bug
Реакции: MLycoris и qdIbp

XONE

Участник
7
6
wait должен вызыватся только из потока.
Нужно добавить новый поток используя пример ниже

Код:
lua_thread.create(function()

      --code

end)

Код:
script_name("post")
script_version("1.1")

local imgui = require 'mimgui'
inicfg = require 'inicfg'
aut = '{6196ff} Andrey_Pilov'
pref = '{0d5eff}[TP Post] {ffffff}'

function main()
    sampRegisterChatCommand('cmd', function() WinState[0] = not WinState[0] end)
    wait(-1)
end

sampRegisterChatCommand("mpost", function(arg)
    lua_thread.create(function()
        if arg == '1' then
                setCharCoordinates(PLAYER_PED, 19.2, 33.2, 1005.8)
                wait(1500)
                sampSendChat("/tpint 5")
                wait(1500)
                sampSendChat("/tpvw 10")
                sampAddChatMessage('Телепортировали', -1)
        end
        if arg == '2' then
                setCharCoordinates(PLAYER_PED, -779.12, 527.80, 1375.65)
                wait(1500)
                sampSendChat("/tpint 1")
                wait(1500)
                sampSendChat("/tpvw 10")
                sampAddChatMessage('Телепортировали', -1)
        end
    end)
end)
 
  • Нравится
Реакции: игрок сампа

recxvery

Участник
93
28

percheklii

Известный
749
279
в мейне все равно регать будет, так что не обязательно 2ое делать
ну да, попробуй без потока, и с ним потом)
самый просто пример

Lua:
function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand("test", function()
        --lua_thread.create(function()
            sampAddChatMessage("test", -1)
            wait(1000)
            sampAddChatMessage("test2", -1)
        --end)
    end)
    wait(-1)
end
 
  • Bug
Реакции: recxvery

recxvery

Участник
93
28
ну да, попробуй без потока, и с ним потом)
самый просто пример

Lua:
function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand("test", function()
        --lua_thread.create(function()
            sampAddChatMessage("test", -1)
            wait(1000)
            sampAddChatMessage("test2", -1)
        --end)
    end)
    wait(-1)
end
ladno, znachit ya chtoto zabil
 

СоМиК

Известный
458
314
ladno, znachit ya chtoto zabil
ты забыл то, что при регистрации команды ты указываешь одним из параметров функцию, а эта функция в свою очередь как каллбек вызывается ИЗ САМПФУНКСА, а не воспроизводится внутри окружения функции main().
 
  • Нравится
Реакции: MLycoris