Помогите решить проблемку

KandySr

Участник
Автор темы
10
6
Версия MoonLoader
.026-beta
Hello, такая вот проблема
Записываю в массив ник и ID и некоторую информацию, но хочу сделать так чтобы если ник уже есть в массиве то добавляло к ac_count + 1, а если нету то добавляло строку с ником и прочей информацией в массив
Но до 3 строки всё нормально, а потом начинает просто тупо добавлять строку в массив
Накидал такой вот кодик
sya:
local anticheat = {}

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
       sampRegisterChatCommand("showcheat", function()
        for k, v in ipairs(anticheat) do
            print(#anticheat)
        end
    end)

    sampRegisterChatCommand("addcheat", function(arg)
        anti_cheat(arg, 2, "CпидХак")
    end)
 
    while true do
        wait(0)
    end
end

function anti_cheat (AC_nickname, acID, ac_type)
    if #anticheat == 0 then table.insert(anticheat, {nickname = AC_nickname, text = ac_type, time = os.time(), id = acID, ac_count = 1, ac_admin = 0, ac_anick = "none"}) end
    for k, v in ipairs(anticheat) do
        if anticheat[k].nickname == AC_nickname  then
            anticheat[k].ac_count = anticheat[k].ac_count + 1
            anticheat[k].time = os.time()
            anticheat[k].text = ac_type
        elseif anticheat[k].nickname ~= AC_nickname  then
            table.insert(anticheat, {nickname = AC_nickname, text = ac_type, time = os.time(), id = acID, ac_count = 1, ac_admin = 0, ac_anick = "none"}) end
    end
end
 
Решение
Lua:
local acList = {}

local function isUserInList(name)
    for k, v in ipairs(acList) do
        if v.name == name then
            return k
        end
    end
end

local function addToAc(name, type, tag)
     local user = isUserInList(name)
     if user then
         acList[user.count] = acList[user.count] + 1
     else
         table.insert(
            acList,
            {
                name = name,
                time = os.time(),
                count = 1,
                tag = tag
            }
         )
     end
end

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,777
11,225
Lua:
local acList = {}

local function isUserInList(name)
    for k, v in ipairs(acList) do
        if v.name == name then
            return k
        end
    end
end

local function addToAc(name, type, tag)
     local user = isUserInList(name)
     if user then
         acList[user.count] = acList[user.count] + 1
     else
         table.insert(
            acList,
            {
                name = name,
                time = os.time(),
                count = 1,
                tag = tag
            }
         )
     end
end
 

KandySr

Участник
Автор темы
10
6
Lua:
local acList = {}

local function isUserInList(name)
    for k, v in ipairs(acList) do
        if v.name == name then
            return k
        end
    end
end

local function addToAc(name, type, tag)
     local user = isUserInList(name)
     if user then
         acList[user.count] = acList[user.count] + 1
     else
         table.insert(
            acList,
            {
                name = name,
                time = os.time(),
                count = 1,
                tag = tag
            }
         )
     end
end
Не чет не то

Lua:
local acList = {}

local function isUserInList(name)
    for k, v in ipairs(acList) do
        if v.name == name then
            return k
        end
    end
end

local function addToAc(name, type, tag)
     local user = isUserInList(name)
     if user then
         acList[user.count] = acList[user.count] + 1
     else
         table.insert(
            acList,
            {
                name = name,
                time = os.time(),
                count = 1,
                tag = tag
            }
         )
     end
end
А всё фигня порешал ошибочку немного в твоем коде:)
 
Последнее редактирование: