Advertisement
ShadyX-SAMP

autogarbagetruck.lua

Nov 22nd, 2024 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | Gaming | 0 0
  1. script_name("autogarbagetruck")
  2. script_author("Rockwell / Shady (Discord: shadyxo)")
  3. script_version("0.1")
  4. script_version_number(100000)
  5.  
  6. local samp = require 'sampfuncs'
  7. local sampev = require 'lib.samp.events'
  8.  
  9. local autoGarbageEnabled = false
  10. local configFolder = getWorkingDirectory() .. '\\config\\'
  11. local configFile = configFolder .. 'autogarbagetruck.ini'
  12.  
  13. local isTrashmaster = false
  14. local delayTimer = 0
  15.  
  16. local targetX, targetY, targetZ = 0, 0, 0
  17. local detectionRange = 10.0
  18.  
  19. function main()
  20.     if not doesDirectoryExist(configFolder) then
  21.         createDirectory(configFolder)
  22.     end
  23.  
  24.     if doesFileExist(configFile) then
  25.         loadGarbageState()
  26.     else
  27.         blankIni()
  28.     end
  29.  
  30.     while not isSampAvailable() do wait(100) end
  31.  
  32.     sampRegisterChatCommand("agt", toggleAutoGarbage)
  33.  
  34.     while true do
  35.         wait(0)
  36.  
  37.         if autoGarbageEnabled and isCharInAnyCar(PLAYER_PED) then
  38.             local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
  39.             local model = getCarModel(vehicle)
  40.            
  41.             if model == 408 then
  42.                 if not isTrashmaster then
  43.                     isTrashmaster = true
  44.                     sampAddChatMessage("* Trashmaster detected, please wait a second.", 0x33CCFF)
  45.                     delayTimer = os.clock() + 2
  46.                 end
  47.             else
  48.                 isTrashmaster = false
  49.             end
  50.         else
  51.             isTrashmaster = false
  52.         end
  53.  
  54.         if isTrashmaster and delayTimer > 0 and os.clock() >= delayTimer then
  55.             sampSendChat("/pickuptrash")
  56.             delayTimer = 0
  57.         end
  58.  
  59.         removeOldCheckpoints()
  60.     end
  61. end
  62.  
  63. function removeOldCheckpoints()
  64.     if targetX == 0 and targetY == 0 and targetZ == 0 then
  65.         return
  66.     end    
  67.  
  68.     local playerX, playerY, playerZ = getCharCoordinates(PLAYER_PED)
  69.     local distance = math.sqrt((playerX - targetX)^2 + (playerY - targetY)^2 + (playerZ - targetZ)^2)
  70.  
  71.     if distance <= detectionRange then
  72.         removeWaypoint()
  73.     end
  74. end
  75.  
  76. function sampev.onSetCheckpoint(pos, float)
  77.     if math.abs(pos.x - 1423.8372802734) < 0.01 and
  78.        math.abs(pos.y + 1318.9272460938) < 0.01 and
  79.        math.abs(pos.z - 13.554699897766) < 0.01 and
  80.        math.abs(float - 5) < 0.01 then
  81.         sampAddChatMessage("* You will be picking up the trash from Downtown Los Santos | Landmark: Materials Pickup 1.", 0x33CCFF)
  82.         placeWaypoint(1423.8372802734, -1318.9272460938, 13.554699897766)
  83.         targetX, targetY, targetZ = 1423.8372802734, -1318.9272460938, 13.554699897766
  84.     elseif math.abs(pos.x - 1142.04296875) < 0.01 and
  85.            math.abs(pos.y + 1350.2926025391) < 0.01 and
  86.            math.abs(pos.z - 13.677399635315) < 0.01 and
  87.            math.abs(float - 5) < 0.01 then
  88.         sampAddChatMessage("* You will be picking up the trash from Market | Landmark: (behind) All Saints General Hospital.", 0x33CCFF)
  89.         placeWaypoint(1142.04296875, -1350.2926025391, 13.677399635315)
  90.         targetX, targetY, targetZ = 1142.04296875, -1350.2926025391, 13.677399635315
  91.     elseif math.abs(pos.x - 1665.3306884766) < 0.01 and
  92.            math.abs(pos.y + 1002.8746948242) < 0.01 and
  93.            math.abs(pos.z - 24.05590057373) < 0.01 and
  94.            math.abs(float - 5) < 0.01 then
  95.         sampAddChatMessage("* You will be picking up the trash from Mulholland Intersection | Landmark: Parking Lot next to the Bank of Los Santos.", 0x33CCFF)
  96.         placeWaypoint(1665.3306884766, -1002.8746948242, 24.05590057373)
  97.         targetX, targetY, targetZ = 1665.3306884766, -1002.8746948242, 24.05590057373
  98.     elseif math.abs(pos.x - 2484.8706054688) < 0.01 and
  99.            math.abs(pos.y + 2529.1831054688) < 0.01 and
  100.            math.abs(pos.z - 13.543171882629) < 0.01 and
  101.            math.abs(float - 5) < 0.01 then
  102.         placeWaypoint(2484.8706054688, -2529.1831054688, 13.543171882629)
  103.         targetX, targetY, targetZ = 2484.8706054688, -2529.1831054688, 13.543171882629
  104.     end
  105. end
  106.  
  107. function toggleAutoGarbage()
  108.     if autoGarbageEnabled then
  109.         autoGarbageEnabled = false
  110.         sampAddChatMessage("[{33CCFF}AGT{FFFFFF}]: You have {FF0000}disabled{FFFFFF} Automatic Garbage Truck.", 0xFFFFFF)
  111.     else
  112.         autoGarbageEnabled = true
  113.         sampAddChatMessage("[{33CCFF}AGT{FFFFFF}]: You have {00FF00}enabled{FFFFFF} Automatic Garbage Truck.", 0xFFFFFF)
  114.     end
  115.  
  116.     saveGarbageState()
  117. end
  118.  
  119. function saveGarbageState()
  120.     local f = io.open(configFile, "w")
  121.     if f then
  122.         f:write("[Settings]\n")
  123.         f:write("autoGarbageEnabled=" .. tostring(autoGarbageEnabled) .. "\n")
  124.         f:close()
  125.     end
  126. end
  127.  
  128. function loadGarbageState()
  129.     local f = io.open(configFile, "r")
  130.     if f then
  131.         local content = f:read("*all")
  132.         f:close()
  133.  
  134.         local enabled = content:match("autoGarbageEnabled=(%w+)")
  135.         if enabled == "false" then
  136.             autoGarbageEnabled = false
  137.         else
  138.             autoGarbageEnabled = true
  139.         end
  140.     end
  141. end
  142.  
  143. function doesDirectoryExist(path)
  144.     local f = io.open(path, "r")
  145.     if f then
  146.         f:close()
  147.         return true
  148.     else
  149.         return false
  150.     end
  151. end
  152.  
  153. function createDirectory(path)
  154.     os.execute("mkdir " .. path)
  155. end
  156.  
  157. function doesFileExist(path)
  158.     local f = io.open(path, "r")
  159.     return f ~= nil
  160. end
  161.  
  162. function blankIni()
  163.     autoGarbageEnabled = true
  164.     saveGarbageState()
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement