- 22
- 1
[ML] (error) AnswerCount: ...GTA Launcher\trinity_games\moonloader\BB_AnswerCount.lua:47: attempt to index field 'settings' (a nil value)
stack traceback:
...GTA Launcher\trinity_games\moonloader\BB_AnswerCount.lua:47: in function <...GTA Launcher\trinity_games\moonloader\BB_AnswerCount.lua:35>
[ML] (error) AnswerCount: Script died due to an error. (24BCAE3C)
stack traceback:
...GTA Launcher\trinity_games\moonloader\BB_AnswerCount.lua:47: in function <...GTA Launcher\trinity_games\moonloader\BB_AnswerCount.lua:35>
[ML] (error) AnswerCount: Script died due to an error. (24BCAE3C)
Код:
--###################################################################--
script_name("AnswerCount")
script_author("Богдан Макарчук - BARRY_BRADLEY - vk.com/trinity_mod")
script_version("1.0")
--###################################################################--
require "lib.sampfuncs"
require "lib.moonloader"
local sampev = require "lib.samp.events"
local inicfg = require "inicfg"
local russian_characters = {
[168] = 'Ё', [184] = 'ё', [192] = 'А', [193] = 'Б', [194] = 'В', [195] = 'Г', [196] = 'Д', [197] = 'Е', [198] = 'Ж', [199] = 'З', [200] = 'И', [201] = 'Й', [202] = 'К', [203] = 'Л', [204] = 'М', [205] = 'Н', [206] = 'О', [207] = 'П', [208] = 'Р', [209] = 'С', [210] = 'Т', [211] = 'У', [212] = 'Ф', [213] = 'Х', [214] = 'Ц', [215] = 'Ч', [216] = 'Ш', [217] = 'Щ', [218] = 'Ъ', [219] = 'Ы', [220] = 'Ь', [221] = 'Э', [222] = 'Ю', [223] = 'Я', [224] = 'а', [225] = 'б', [226] = 'в', [227] = 'г', [228] = 'д', [229] = 'е', [230] = 'ж', [231] = 'з', [232] = 'и', [233] = 'й', [234] = 'к', [235] = 'л', [236] = 'м', [237] = 'н', [238] = 'о', [239] = 'п', [240] = 'р', [241] = 'с', [242] = 'т', [243] = 'у', [244] = 'ф', [245] = 'х', [246] = 'ц', [247] = 'ч', [248] = 'ш', [249] = 'щ', [250] = 'ъ', [251] = 'ы', [252] = 'ь', [253] = 'э', [254] = 'ю', [255] = 'я',
}
local ignoreList = {} -- временный масив
local database = inicfg.load(nil, "AnswerCount")
if database == nil then
countAnswer = {
settings = {
types = "my"
},
myAnswer = {
amount = 0
},
allAnswer = {
BARRY_BRADLEY = 0,
}
}
inicfg.save(countAnswer, "AnswerCount")
database = inicfg.load(nil, "AnswerCount")
end
function onReceiveRpc(id, bs)
if id == 93 then
local color = raknetBitStreamReadInt32(bs)
local len = raknetBitStreamReadInt32(bs)
local text = raknetBitStreamReadString(bs, len)
if text:find("^Вопрос от .+ ID %d+: .+") then
local name, id, question = string.match(text, "^Вопрос от (.+) ID (%d+): (.+)")
ignoreList[name] = false
elseif text:find("^От .+ для .+: .+") then
local answ_name, name, answer = text:match("^От (.+) для (.+): (.+)")
local _, myId = sampGetPlayerIdByCharHandle(playerPed)
local myName = sampGetPlayerNickname(myId)
if database["settings"]["types"] == "my" then
if string.rlower(answ_name) == string.rlower(myName) then
if not ignoreList[name] then
lua_thread.create(checkQuestion, name)
database["myAnswer"]["amount"] = database["myAnswer"]["amount"] + 1
inicfg.save(database, "AnswerCount")
ignoreList[name] = true
end
end
elseif database["settings"]["types"] == "all" then
if database["allAnswer"][string.upper(answ_name)] == nil and string.rlower(answ_name) ~= string.rlower(myName) then
database["allAnswer"][string.upper(answ_name)] = 0
end
if not ignoreList[name] then
if string.rlower(answ_name) == string.rlower(myName) then
lua_thread.create(checkQuestion, name)
database["myAnswer"]["amount"] = database["myAnswer"]["amount"] + 1
inicfg.save(database, "AnswerCount")
ignoreList[name] = true
else
lua_thread.create(checkQuestion, name)
database["allAnswer"][string.upper(answ_name)] = database["allAnswer"][string.upper(answ_name)] + 1
inicfg.save(database, "AnswerCount")
ignoreList[name] = true
end
end
end
end
end
end
function checkQuestion(name)
wait(0)
for time = 1, 60 do
wait(1000)
if not ignoreList[name] or time == 60 then
ignoreList[name] = false
return
end
end
end
function main()
while not isSampAvailable() do
wait(0)
end
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Скрипт для подсчета ответов хелперов - активирован. Команды: {2a9c48}/answ.help", -1)
sampRegisterChatCommand(
"answ.help",
function(param)
sampAddChatMessage("{FFFFFF}------========={2a9c48}[AnswerCount]{FFFFFF}=========------", -1)
sampAddChatMessage("{2a9c48}/answ.get [my | all] {FFFFFF}- вывод кол-ва ответов", -1)
sampAddChatMessage("{2a9c48}/answ.type [my | all] {FFFFFF}- тип внесения кол-ва", -1)
sampAddChatMessage("{2a9c48}/answ.reset [my | all] {FFFFFF}- обновить кол-во ответов", -1)
end
)
sampRegisterChatCommand(
"answ.get",
function(param)
if param ~= nil and param ~= "" then
if param == "my" then
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Ваших ответов игрокам: {2a9c48}".. database["myAnswer"]["amount"], -1)
elseif param == "all" then
for name, answ in pairs(database["allAnswer"]) do
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Ответов у игрока {2a9c48}"..name.."{FFFFFF}: {2a9c48}".. answ, -1)
end
else
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Используйте: {2a9c48}/answ.get [my | all]", -1)
end
else
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Используйте: {2a9c48}/answ.get [my | all]", -1)
end
end
)
sampRegisterChatCommand(
"answ.type",
function(param)
if param ~= nil and param ~= "" then
if param == "my" then
database["settings"]["type"] = "my"
inicfg.save(database, "AnswerCount")
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Вы успешно обновили тип внесения кол-ва только для себя", -1)
elseif param == "all" then
database["settings"]["type"] = "all"
inicfg.save(database, "AnswerCount")
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Вы успешно обновили тип внесения кол-ва для всех хелперов", -1)
else
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Используйте: {2a9c48}/answ.type [my | all]", -1)
end
else
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Используйте: {2a9c48}/answ.type [my | all]", -1)
end
end
)
sampRegisterChatCommand(
"answ.reset",
function(param)
if param ~= nil and param ~= "" then
if param == "my" then
database["myAnswer"]["amount"] = 0
inicfg.save(database, "AnswerCount")
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Вы успешно обновили кол-во своих ответов /answ", -1)
elseif param == "all" then
database["allAnswer"] = {
BARRY_BRADLEY = 0
}
inicfg.save(database, "AnswerCount")
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Вы успешно обновили кол-во всех остальных хелперов в /answ", -1)
else
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Используйте: {2a9c48}/answ.reset [my | all]", -1)
end
else
sampAddChatMessage("{2a9c48}[HC]{FFFFFF}: Используйте: {2a9c48}/answ.reset [my | all]", -1)
end
end
)
end
function string.rlower(s)
s = s:lower()
local strlen = s:len()
if strlen == 0 then return s end
s = s:lower()
local output = ''
for i = 1, strlen do
local ch = s:byte(i)
if ch >= 192 and ch <= 223 then -- upper russian characters
output = output .. russian_characters[ch + 32]
elseif ch == 168 then -- Ё
output = output .. russian_characters[184]
else
output = output .. string.char(ch)
end
end
return output
end