designer
Member
Hey, so I've been trying to code a LUA version of auto accepting vests. I am having a hard time doing it because I just learned LUA and don't know much about it. Sometimes I run into barriers and can't overcome them. I need help with my code. I would appreciate it if you guys could help me get my code working!
Code:
script_name("Auto Accept Vest by Y2K")
script_description("Auto Accepts Vests")
script_version("1.0")
script_authors("Y2K")
script_dependencies("default")
local active = false -- Auto Accept Vest is deactivated by default
-- Function to check chat messages for a bodyguard offer and automatically accept it if armor is less than 35
function checkChatMessages()
local chatLineCount = sampGetChatMaxMessages() -- Get the number of lines in the chat
local armor = sampGetPlayerArmor(PLAYER_HANDLE) -- Get player's armor
-- Loop through the chat lines
for i = chatLineCount - 1, chatLineCount do
local message, prefix, suffix = sampGetChatMessage(i) -- Get the chat message
-- Check if the message is a bodyguard offer and Auto Accept Vest is active and player's armor is less than 35
if active and armor < 35 and string.find(message, "wants to protect you for $200, type /accept bodyguard to accept.") then
sampSendChat("/accept bodyguard") -- Send the "/accept bodyguard" command to accept the offer
end
end
end
-- Function to toggle the Auto Accept Vest
function toggleAutoAccept()
active = not active -- Toggle the value of active
if active then
sampAddChatMessage("{FFFFFF}Auto Accept Vest {00FF00}On{FFFFFF} - Zac", -1) -- Display a message indicating that the Auto Accept Vest is enabled
else
sampAddChatMessage("{FFFFFF}Auto Accept Vest {FF0000}Off{FFFFFF} - Zac", -1) -- Display a message indicating that the Auto Accept Vest is disabled
end
end
-- Register the Auto Accept Vest command with SAMP
function registerAutoAcceptCommand()
sampRegisterChatCommand("av", toggleAutoAccept) -- Register the "av" command to toggle the Auto Accept Vest
end
-- Register the functions with MoonLoader
function main()
while not isSampAvailable() do wait(0) end -- Wait for SAMP to be available
registerAutoAcceptCommand() -- Register the Auto Accept Vest command with SAMP
while true do
wait(0)
checkChatMessages() -- Check chat messages for bodyguard offers and automatically accept them if Auto Accept Vest is active and player's armor is less than 35
end
end