скриптик

slappy tap

Новичок
Автор темы
12
0
всем привет, хотел написать скрипт, суть которого заключается в следующем: скрипт ищет сообщение "тп на цр" и прописывает команду /tpplayer ID 1.
Может что-то не так сделал, только недавно начал писать на lua
code:
require('lib.moonloader')

function main()

if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do
        wait(0)
    end   
    if text:find("%(.*)[%d+%] тп на цр") then
        nick, id = text:match("%(.*)[%d+%] тп на цр")
        sampSendChat("/tpplayer "..id.." 1")
    end
end


moonloader\test.lua:10: attempt to index global 'text' (a nil value)
stack traceback:
 

EKPAHHNY_HAGN6ATOP

Тот самый
291
99
require('lib.moonloader')
function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
while not isSampAvailable() do
wait(0)
end
local chat = sampGetCurrentChatInput(false)
if chat:find("%(.*)[%d+%] тп на цр") then
local nick, id = chat:match("%(.*)[%d+%] тп на цр")
sampSendChat("/tpplayer "..id.." 1")
end
end
 
  • Клоун
  • Bug
Реакции: FreX и minxty

slappy tap

Новичок
Автор темы
12
0
require('lib.moonloader')
function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
while not isSampAvailable() do
wait(0)
end
local chat = sampGetCurrentChatInput(false)
if chat:find("%(.*)[%d+%] тп на цр") then
local nick, id = chat:match("%(.*)[%d+%] тп на цр")
sampSendChat("/tpplayer "..id.." 1")
end
end
не ворк

Lua:
require('lib.samp.events').onServerMessage = function(clr, text)
    if text:find(твоя регулярка) then
        -- твое действие
    end
end
так?

code:
require('lib.samp.events').onServerMessage = function(clr, text)
    if text:find("%(.*)[%d+%] тп на цр") then
        nick, id = text:match("%(.*)[%d+%] тп на цр")
        sampSendChat("/tpplayer "..id.." 1")
    end
end
 

Notepad++

Известный
289
166
Конечно, не моё дело. Но лучше сделать так:
Lua:
local sampev = require('lib.samp.events')

function sampev.onServerMessage(color, text)
    if text:find("(.*)[%d+%] тп на цр") then
        nick, id = text:match("%(.*)[%d+%] тп на цр")
        sampSendChat("/tpplayer "..id.." 1")
    end
end
 
Последнее редактирование:
  • Эм
Реакции: minxty

slappy tap

Новичок
Автор темы
12
0
Конечно, не моё дело. Но лучше сделать так:
Lua:
local sampev = require('lib.samp.events')

function sampev.onServerMessage(color, text)
    if text:find("%(.*)[%d+%] тп на цр") then
        nick, id = text:match("%(.*)[%d+%] тп на цр")
        sampSendChat("/tpplayer "..id.." 1")
    end
end
error:
[ML] (error) test.lua: ...x86)\Arizona Games Launcher\bin\arizona\moonloader\test.lua:4: invalid pattern capture
stack traceback:
    [C]: in function 'find'
    ...x86)\Arizona Games Launcher\bin\arizona\moonloader\test.lua:4: in function 'callback'
    ...Launcher\bin\arizona\moonloader\lib\samp\events\core.lua:79: in function <...Launcher\bin\arizona\moonloader\lib\samp\events\core.lua:53>
[ML] (error) test.lua: Script died due to an error. (1D01E564)
 

minxty

Известный
1,205
1,076
error:
[ML] (error) test.lua: ...x86)\Arizona Games Launcher\bin\arizona\moonloader\test.lua:4: invalid pattern capture
stack traceback:
    [C]: in function 'find'
    ...x86)\Arizona Games Launcher\bin\arizona\moonloader\test.lua:4: in function 'callback'
    ...Launcher\bin\arizona\moonloader\lib\samp\events\core.lua:79: in function <...Launcher\bin\arizona\moonloader\lib\samp\events\core.lua:53>
[ML] (error) test.lua: Script died due to an error. (1D01E564)
У тебя регулярка неправильная, и ещё, делай проверку на id (if id then) и после того выполняй отправку сообщения в чат, так будет лучше
 

Notepad++

Известный
289
166
Ты квадратные скобки не экранировал
Lua:
local sampev = require('lib.samp.events')

function sampev.onServerMessage(color, text)
    if text:find("(.*)%[(%d+)%] тп на цр") then
        nick, id = text:match("%(.*)%[(%d+)%] тп на цр")
        sampSendChat("/tpplayer "..id.." 1")
    end
end
 
Последнее редактирование:

slappy tap

Новичок
Автор темы
12
0
Вроде работает
Lua:
local sampev = require 'lib.samp.events'

function sampev.onServerMessage(color, text)
    if text:find('(%w+_%w+)%[(%d+)%] говорит: тп на цр') then
        local nick, id = text:match('(%w+_%w+)%[(%d+)%] говорит: тп на цр')
        sampSendChat('/tpplayer '..id..' 1')
    end
end
тоже самое, ничего не происходит