Auto Accept Vest (LUA version)

sounwav

Новичок
Автор темы
5
0
Hello. I am trying to make a LUA version of auto accept vest if the vest is equal to 35 or less than. I have my code here but I cannot make it work and I am stuck on it. I'd appreciate some help, I am new to coding LUA so I am kind of limited on the knowledge too .

What I am trying to do with this is that if you do /av it enabled/disables the mod. Only accept vest if it is $200 and if you have 35 armor or less than 35 armor.


auto accept vest (lua):
require "lib.sampfuncs"

function main()
    sampAddChatMessage("{FFFFFF}AutoAccept - {0085ff}[Credit: Y2K]", -1)
    local isModActive = true -- Script is active by default
    
    while true do
        wait(0)
        
        if isModActive then
            for i = 98, 99 do
                local text, prefix, color, prefixColor = sampGetChatString(i)
                if text:find("wants to protect you for $200, type /accept bodyguard to accept.") then -- If the message is found
                    sampSendChat("/accept bodyguard")
                    wait(1000) -- Waits for a second
                end
            end
        end
    end
end

function toggleMod() -- Function to toggle mod on/off
    isModActive = not isModActive -- Toggles the boolean value of isModActive
    if isModActive then
        sampAddChatMessage("~y~Auto AcceptVest: ~g~on", -1) -- Displays message when mod is activated
    else
        sampAddChatMessage("~y~Auto AcceptVest: ~r~off", -1) -- Displays message when mod is deactivated
    end
end

sampRegisterChatCommand("av", toggleMod) -- Registers "/av" command to toggle mod on/off

bump

bump
 
Последнее редактирование:

YarikVL

Известный
Проверенный
4,796
1,813
Hello. I am trying to make a LUA version of auto accept vest if the vest is equal to 35 or less than. I have my code here but I cannot make it work and I am stuck on it. I'd appreciate some help, I am new to coding LUA so I am kind of limited on the knowledge too .

What I am trying to do with this is that if you do /av it enabled/disables the mod. Only accept vest if it is $200 and if you have 35 armor or less than 35 armor.


auto accept vest (lua):
require "lib.sampfuncs"

function main()
    sampAddChatMessage("{FFFFFF}AutoAccept - {0085ff}[Credit: Y2K]", -1)
    local isModActive = true -- Script is active by default
   
    while true do
        wait(0)
       
        if isModActive then
            for i = 98, 99 do
                local text, prefix, color, prefixColor = sampGetChatString(i)
                if text:find("wants to protect you for $200, type /accept bodyguard to accept.") then -- If the message is found
                    sampSendChat("/accept bodyguard")
                    wait(1000) -- Waits for a second
                end
            end
        end
    end
end

function toggleMod() -- Function to toggle mod on/off
    isModActive = not isModActive -- Toggles the boolean value of isModActive
    if isModActive then
        sampAddChatMessage("~y~Auto AcceptVest: ~g~on", -1) -- Displays message when mod is activated
    else
        sampAddChatMessage("~y~Auto AcceptVest: ~r~off", -1) -- Displays message when mod is deactivated
    end
end

sampRegisterChatCommand("av", toggleMod) -- Registers "/av" command to toggle mod on/off

bump

bump
Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage("{FFFFFF}AutoAccept - {0085ff}[Credit: Y2K]", -1)
    isModActive = true -- Script is active by default
    sampRegisterChatCommand("av", toggleMod) -- Registers "/av" command to toggle mod on/off
    while true do
        wait(0)
        
        if isModActive then
            for i = 98, 99 do
                sampAddChatMessage("repeat twice")
                local text, prefix, color, prefixColor = sampGetChatString(i)
                if text:find("wants to protect you for $200, type /accept bodyguard to accept.") then -- If the message is found
                    sampSendChat("/accept bodyguard")
                    wait(1000) -- Waits for a second
                end
            end
        end
    end
end

function toggleMod() -- Function to toggle mod on/off
    isModActive = not isModActive -- Toggles the boolean value of isModActive
    if isModActive then
        sampAddChatMessage("~y~Auto AcceptVest: ~g~on", -1) -- Displays message when mod is activated
    else
        sampAddChatMessage("~y~Auto AcceptVest: ~r~off", -1) -- Displays message when mod is deactivated
    end
end
 

SpnKO

Известный
56
14
In the future, do not use sampGetChatString method, if chat flows too fast your script will miss it, instead, hook onServerMessage and intercept them as they come.

Autoaccepter:
local sampev = require 'samp.events'
local isModEnable = false -- Dsiabled by default

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('av', Toggle)
end

function sampev.onServerMessage(color, text)
    if text:find(' wants to protect you for $200, type /accept bodyguard to accept.') and color == 0x33CCFFAA then
        lua_thread.create(function ()
            local PlayerArmor = getCharArmour(PLAYER_PED)
            if PlayerArmor <= 35 and isModEnable then
                sampSendChat("/accept bodyguard")
            end
        end)
    end
end

function Toggle()
    isModEnable = not isModEnable
    if isModEnable then
        sampAddChatMessage("Auto vest accepter enabled", -1)
    else
        sampAddChatMessage("Auto vest accepter disabled", -1)
    end
end