Help registry command error

Tuzas

Active member
Joined
Nov 1, 2019
Messages
120
Reaction score
67
Location
null
fixed thanks brother
I couldn't ignore how terrible that code was :D

Heres the same code, but revisioned


JavaScript:
-- AutoCap Script
-- Author: Dallaz
-- Load necessary module
require "lib.sampfuncs"

local sampev = require "lib.samp.events"

local captog = false

function main()
    -- Wait for SA-MP to become available
    while not isSampAvailable() do
        wait(100)
    end

    -- Display instructions to the user
    sampAddChatMessage("{0000FF}~~~~~~ [LUA] AutoCapture ~~~~~~ {FFFFFF}/tcap to start spam and /stopcap to stop", -1)
    -- Register commands
    sampRegisterChatCommand("tcap", toggleCapture)
    -- Main loop
    while true do
        wait(0)
        -- Check if capture toggle is active
        if captog then
            -- Spam capture command while toggle is active
            sampSendChat("/captureturf")
            wait(2500)

        end
    end
end

-- Function to toggle capture spam
function toggleCapture()
    captog = not captog
    sampAddChatMessage(captog and "{FFFF00}Starting capture spam..." or "{FFFF00}Stopping capture spam...", -1)

end

-- Event handler for server messages
function sampev.onServerMessage(color, text)
    if text:find("The time is now") then
        lua_thread.create(function()
            wait(100) -- introduced a delay, to prevent timing issues
            sampSendChat("/captureturf")
            wait(100)-- introduced a delay, to prevent timing issues
            sampSendChat("/capture")
        end)
    end
end
 

affar

Member
Joined
Feb 21, 2023
Messages
9
Reaction score
0
I couldn't ignore how terrible that code was :D

Heres the same code, but revisioned


JavaScript:
-- AutoCap Script
-- Author: Dallaz
-- Load necessary module
require "lib.sampfuncs"

local sampev = require "lib.samp.events"

local captog = false

function main()
    -- Wait for SA-MP to become available
    while not isSampAvailable() do
        wait(100)
    end

    -- Display instructions to the user
    sampAddChatMessage("{0000FF}~~~~~~ [LUA] AutoCapture ~~~~~~ {FFFFFF}/tcap to start spam and /stopcap to stop", -1)
    -- Register commands
    sampRegisterChatCommand("tcap", toggleCapture)
    -- Main loop
    while true do
        wait(0)
        -- Check if capture toggle is active
        if captog then
            -- Spam capture command while toggle is active
            sampSendChat("/captureturf")
            wait(2500)

        end
    end
end

-- Function to toggle capture spam
function toggleCapture()
    captog = not captog
    sampAddChatMessage(captog and "{FFFF00}Starting capture spam..." or "{FFFF00}Stopping capture spam...", -1)

end

-- Event handler for server messages
function sampev.onServerMessage(color, text)
    if text:find("The time is now") then
        lua_thread.create(function()
            wait(100) -- introduced a delay, to prevent timing issues
            sampSendChat("/captureturf")
            wait(100)-- introduced a delay, to prevent timing issues
            sampSendChat("/capture")
        end)
    end
end
ty
 
Top