Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script_name("autogarbagetruck")
- script_author("Rockwell / Shady (Discord: shadyxo)")
- script_version("0.1")
- script_version_number(100000)
- local samp = require 'sampfuncs'
- local sampev = require 'lib.samp.events'
- local autoGarbageEnabled = false
- local configFolder = getWorkingDirectory() .. '\\config\\'
- local configFile = configFolder .. 'autogarbagetruck.ini'
- local isTrashmaster = false
- local delayTimer = 0
- local targetX, targetY, targetZ = 0, 0, 0
- local detectionRange = 10.0
- function main()
- if not doesDirectoryExist(configFolder) then
- createDirectory(configFolder)
- end
- if doesFileExist(configFile) then
- loadGarbageState()
- else
- blankIni()
- end
- while not isSampAvailable() do wait(100) end
- sampRegisterChatCommand("agt", toggleAutoGarbage)
- while true do
- wait(0)
- if autoGarbageEnabled and isCharInAnyCar(PLAYER_PED) then
- local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
- local model = getCarModel(vehicle)
- if model == 408 then
- if not isTrashmaster then
- isTrashmaster = true
- sampAddChatMessage("* Trashmaster detected, please wait a second.", 0x33CCFF)
- delayTimer = os.clock() + 2
- end
- else
- isTrashmaster = false
- end
- else
- isTrashmaster = false
- end
- if isTrashmaster and delayTimer > 0 and os.clock() >= delayTimer then
- sampSendChat("/pickuptrash")
- delayTimer = 0
- end
- removeOldCheckpoints()
- end
- end
- function removeOldCheckpoints()
- if targetX == 0 and targetY == 0 and targetZ == 0 then
- return
- end
- local playerX, playerY, playerZ = getCharCoordinates(PLAYER_PED)
- local distance = math.sqrt((playerX - targetX)^2 + (playerY - targetY)^2 + (playerZ - targetZ)^2)
- if distance <= detectionRange then
- removeWaypoint()
- end
- end
- function sampev.onSetCheckpoint(pos, float)
- if math.abs(pos.x - 1423.8372802734) < 0.01 and
- math.abs(pos.y + 1318.9272460938) < 0.01 and
- math.abs(pos.z - 13.554699897766) < 0.01 and
- math.abs(float - 5) < 0.01 then
- sampAddChatMessage("* You will be picking up the trash from Downtown Los Santos | Landmark: Materials Pickup 1.", 0x33CCFF)
- placeWaypoint(1423.8372802734, -1318.9272460938, 13.554699897766)
- targetX, targetY, targetZ = 1423.8372802734, -1318.9272460938, 13.554699897766
- elseif math.abs(pos.x - 1142.04296875) < 0.01 and
- math.abs(pos.y + 1350.2926025391) < 0.01 and
- math.abs(pos.z - 13.677399635315) < 0.01 and
- math.abs(float - 5) < 0.01 then
- sampAddChatMessage("* You will be picking up the trash from Market | Landmark: (behind) All Saints General Hospital.", 0x33CCFF)
- placeWaypoint(1142.04296875, -1350.2926025391, 13.677399635315)
- targetX, targetY, targetZ = 1142.04296875, -1350.2926025391, 13.677399635315
- elseif math.abs(pos.x - 1665.3306884766) < 0.01 and
- math.abs(pos.y + 1002.8746948242) < 0.01 and
- math.abs(pos.z - 24.05590057373) < 0.01 and
- math.abs(float - 5) < 0.01 then
- sampAddChatMessage("* You will be picking up the trash from Mulholland Intersection | Landmark: Parking Lot next to the Bank of Los Santos.", 0x33CCFF)
- placeWaypoint(1665.3306884766, -1002.8746948242, 24.05590057373)
- targetX, targetY, targetZ = 1665.3306884766, -1002.8746948242, 24.05590057373
- elseif math.abs(pos.x - 2484.8706054688) < 0.01 and
- math.abs(pos.y + 2529.1831054688) < 0.01 and
- math.abs(pos.z - 13.543171882629) < 0.01 and
- math.abs(float - 5) < 0.01 then
- placeWaypoint(2484.8706054688, -2529.1831054688, 13.543171882629)
- targetX, targetY, targetZ = 2484.8706054688, -2529.1831054688, 13.543171882629
- end
- end
- function toggleAutoGarbage()
- if autoGarbageEnabled then
- autoGarbageEnabled = false
- sampAddChatMessage("[{33CCFF}AGT{FFFFFF}]: You have {FF0000}disabled{FFFFFF} Automatic Garbage Truck.", 0xFFFFFF)
- else
- autoGarbageEnabled = true
- sampAddChatMessage("[{33CCFF}AGT{FFFFFF}]: You have {00FF00}enabled{FFFFFF} Automatic Garbage Truck.", 0xFFFFFF)
- end
- saveGarbageState()
- end
- function saveGarbageState()
- local f = io.open(configFile, "w")
- if f then
- f:write("[Settings]\n")
- f:write("autoGarbageEnabled=" .. tostring(autoGarbageEnabled) .. "\n")
- f:close()
- end
- end
- function loadGarbageState()
- local f = io.open(configFile, "r")
- if f then
- local content = f:read("*all")
- f:close()
- local enabled = content:match("autoGarbageEnabled=(%w+)")
- if enabled == "false" then
- autoGarbageEnabled = false
- else
- autoGarbageEnabled = true
- end
- end
- end
- function doesDirectoryExist(path)
- local f = io.open(path, "r")
- if f then
- f:close()
- return true
- else
- return false
- end
- end
- function createDirectory(path)
- os.execute("mkdir " .. path)
- end
- function doesFileExist(path)
- local f = io.open(path, "r")
- return f ~= nil
- end
- function blankIni()
- autoGarbageEnabled = true
- saveGarbageState()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement