Не работает скрипт

CaJlaT

Овощ
Автор темы
Модератор
2,808
2,617
Версия MoonLoader
.026-beta
В общем, я решил чуток переписать данный скрипт, но почему-то не работает..
Lua:
script_name("GetGuns | By CaJlaT")
script_authors("CaJlaT")
script_description("GetGuns v.0.1")
script_version("0.1")
script_dependencies("CLEO", "SAMP", "SAMPFUNCS")

---------------------------------------------------------------------------

require "lib.moonloader"
require "lib.sampfuncs"
local sampev = require 'lib.samp.events'
local materials = 0
local active = false
local ffi = require "ffi"
ffi.cdef[[
     void keybd_event(int keycode, int scancode, int flags, int extra);
]]


---------------------------------------------------------------------------

function EmulateKey(key, isDown)
    if not isDown then
        ffi.C.keybd_event(key, 0, 2, 0)
    else
        ffi.C.keybd_event(key, 0, 0, 0)
    end
end

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    sampRegisterChatCommand("autogg", cmd_autogg)
    sampRegisterChatCommand("ggs", cmd_ggs)

    while true do
        wait(0)
        if active then
            active_text2 = "~g~[AutoGG By CaJlaT]~w~ --> [%d] --> ~g~Working" --strings longer than 40 characters get cut off, so check to see if there's more!
            active_text = string.format(active_text2, gg)
            active_text2= 1000
            printStringNow(active_text, active_text2)
            function sampev.onServerMessage(color, text)
                final_gg = text
                var = text.find(final_gg, "доступ к складу с материалами!")
                if var then
                    final_gg =  "/get guns " .. gg
                    sampSendChat(final_gg)
                    var = false
                    active = var
                    printStringNow("~g~[AutoGG By CaJlaT]~w~ --> ~r~Disabled", 1000)
                end
            end
        end
            
    end
end

function AutoGG()
    sampSendChat("/stats")
    function sampev.onShowDialog(id,s,t,b1,b2,text)
        if id == 0 then
            local materials = text:match("Материалы:(%d+)")
            materials = string.match(text, "Материалы:\t\t\t(%d+)")
            gg = 500 - materials
            print(gg)
            EmulateKey(VK_RETURN, false)
            if gg == 3 then
                sampAddChatMessage("Вам не требуются материалы", 0x800080)
            end
        end
    end
end


function cmd_autogg()
    active = not active
    if not active then
        printStringNow("~g~[AutoGG By CaJlaT]~w~ --> ~r~Disabled", 1000)
    end
    if active then
        AutoGG()
    end
end

function cmd_ggs()
    AutoGG()
    final_gg =  "/get guns " .. gg
    sampSendChat(final_gg)
    print(final_gg)
end

/ggs
42805

/autogg
42806
Суть в том, что при /autogg всё триггерится, но не работает сама переменная + в чат не выводит (или выводит куда-то в жопу, ибо сервер даже не пишет ничего...)
P.s: Не бейте, пишу ПЕРВЫЙ раз lua скрипт!