Auto Vest Accepted for SAMP (LUA version)

designer

Member
Joined
Apr 3, 2023
Messages
14
Reaction score
0
Location
United States
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
 

ryider

Member
Joined
Apr 16, 2022
Messages
10
Reaction score
2
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
local ev = require("lib.samp.events")

-- Register the functions with MoonLoader
function main()
sampRegisterChatCommand("av", toggleAutoAccept)
end

-- Function to check chat messages for a bodyguard offer and automatically accept it if armor is less than 35
function ev.onServerMessage(color, text)
local armor = sampGetPlayerArmor(PLAYER_PED)
if active and text:find("wants to protect you for $200") and armor < 35 then
sampSendChat("/accept bodyguard")
sampAddChatMessage(text, -1)
end
end

function toggleAutoAccept()
active = not active
sampAddChatMessage(active and '{FFFFFF}Auto Accept Vest {00FF00}On{FFFFFF} - Zac' or '{FFFFFF}Auto Accept Vest {FF0000}Off{FFFFFF} - Zac')
end
 

Vilhelm

Member
Joined
Apr 15, 2023
Messages
12
Reaction score
0
my game crashes when someone tries to vest me while this mod is on, any idea why?
 

designer

Member
Joined
Apr 3, 2023
Messages
14
Reaction score
0
Location
United States
This is not the right code. I figured it out. Try using this mod instead.
 

Attachments

  • AutoAcceptVest.lua
    1.2 KB · Views: 22
Top