теперь вместо ошибки в консоль, в файл пишет "вы получили null$" вместо "вы получили 178510$"
local s = require('samp.events')
local path = getGameDirectory()..'\\moonloader\\config\\txt.txt'
function s.onServerMessage(color, text)
local money = string.match(text,'Депозит в банке: %$(%d+)')
if money then
sampAddChatMessage(money,-1)
local f = io.open(path, 'w+')
f:write('Ты получил '..money..' $'):close()
end
end
Скинь фулл текст, это нужно, чтобы код работал идеально(из них ушло.(тут ненужная хуйня)..)
Текст в чате, фулл текст: "Депозит в банке: $178510 (из них ушло в бюджет семьи: $1785)"Это текст в чате, либо текст в диалоге?
Скинь фулл текст, это нужно, чтобы код работал идеально
local s = require('samp.events')
function s.onServerMessage(color, text)
if text:find('^%s*Депозит в банке') then
if text:find('из них ушло в бюджет семьи') then
local money = text:match('^%s*Депозит в банке: $(.+) %(из')
sampAddChatMessage(tostring(money), -1)
else
local money = text:match('^%s*Депозит в банке: $(.+)')
sampAddChatMessage(tostring(money), -1)
end
end
end
Ты помойму перепутал переменные require и записи в функциюLua:local s = require('samp.events') function samp.onServerMessage(color, text) if text:find('^%s*Депозит в банке') then if text:find('из них ушло в бюджет семьи') then local money = text:match('^%s*Депозит в банке: $(.+) %(из') sampAddChatMessage(tostring(money), -1) else local money = text:match('^%s*Депозит в банке: $(.+)') sampAddChatMessage(tostring(money), -1) end end end
не работает, ввожу и "Депозит в банке: $178510" и "Депозит в банке: $178510 (из них ушло в бюджет семьи: $1785)", а не выводит ничегоLua:local s = require('samp.events') function s.onServerMessage(color, text) if text:find('^%s*Депозит в банке') then if text:find('из них ушло в бюджет семьи') then local money = text:match('^%s*Депозит в банке: $(.+) %(из') sampAddChatMessage(tostring(money), -1) else local money = text:match('^%s*Депозит в банке: $(.+)') sampAddChatMessage(tostring(money), -1) end end end
Попробуйне работает, ввожу и "Депозит в банке: $178510" и "Депозит в банке: $178510 (из них ушло в бюджет семьи: $1785)", а не выводит ничего
local s = require('samp.events')
function s.onServerMessage(color, text)
local money = string.match(text,'%Lепозит в банке: $(%d+)')
if money then
sampAddChatMessage(money,-1)
end
end
почему если выводить в чат, то оно работает, а если в file:write, то пишет "attempt to concatenate global 'money' (a nil value)Попробуй
Lua:local s = require('samp.events') function s.onServerMessage(color, text) local money = string.match(text,'%Lепозит в банке: $(%d+)') if money then sampAddChatMessage(money,-1) end end
почему если выводить в чат, то оно работает, а если в file:write, то пишет "attempt to concatenate global 'money' (a nil value)
stack traceback:" ?
file:write("вы получили "..money.."$\n")Покажи как ты записываешь в текст
local s = require('samp.events')
local path = getGameDirectory()..'\\moonloader\\config\\txt.txt'
function s.onServerMessage(color, text)
local money = string.match(text,'%Lепозит в банке: $(%d+)')
if money then
sampAddChatMessage(money,-1)
local f = io.open(path, 'w+')
f:write(encodeJson(tonumber(money))):close()
end
end
Символ доллара нужно экранироватьLua:local s = require('samp.events') local path = getGameDirectory()..'\\moonloader\\config\\txt.txt' function s.onServerMessage(color, text) local money = string.match(text,'%Lепозит в банке: $(%d+)') if money then sampAddChatMessage(money,-1) local f = io.open(path, 'w+') f:write(encodeJson(tonumber(money))):close() end end
Можешь без tonumber
теперь вместо ошибки в консоль, в файл пишет "вы получили null$" вместо "вы получили 178510$"Lua:local s = require('samp.events') local path = getGameDirectory()..'\\moonloader\\config\\txt.txt' function s.onServerMessage(color, text) local money = string.match(text,'%Lепозит в банке: $(%d+)') if money then sampAddChatMessage(money,-1) local f = io.open(path, 'w+') f:write(encodeJson(tonumber(money))):close() end end
Можешь без tonumber
теперь вместо ошибки в консоль, в файл пишет "вы получили null$" вместо "вы получили 178510$"
local s = require('samp.events')
local path = getGameDirectory()..'\\moonloader\\config\\txt.txt'
function s.onServerMessage(color, text)
local money = string.match(text,'Депозит в банке: %$(%d+)')
if money then
sampAddChatMessage(money,-1)
local f = io.open(path, 'w+')
f:write('Ты получил '..money..' $'):close()
end
end
заработало, спасибоЕсли все равно скажет null То значит что то ты делаешь не так :\Lua:local s = require('samp.events') local path = getGameDirectory()..'\\moonloader\\config\\txt.txt' function s.onServerMessage(color, text) local money = string.match(text,'Депозит в банке: %$(%d+)') if money then sampAddChatMessage(money,-1) local f = io.open(path, 'w+') f:write('Ты получил '..money..' $'):close() end end