Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 31/08/23 in all areas

  1. This is a dirt job script I'm currently working on... There's a bug here, why isn't the marker destroyed when the player exits the vehicle? client side -- client side local screenW, screenH = guiGetScreenSize() local w, h = 400, 330 local jobMarker = createMarker(-1895.57104, -1660.41797, 22.11562, "cylinder", 1.0, 0, 255, 0) local window setMoonSize(1000) function getJob(player, matchingDeminsion) if player == localPlayer and matchingDeminsion then if not isPedInVehicle(player) then if isPedOnGround(player) then if not (window) then window = guiCreateWindow((screenW / 2) - (w / 2), (screenH / 2) - (h / 2), w, h, "garbage job", false) memo = guiCreateMemo(0, 30, w, 200, "this is garbage job!", false, window) guiMemoIsReadOnly(memo) accept = guiCreateButton(0, 290, 100, 40, "Accept", false, window) leave = guiCreateButton(130, 290, 100, 40, "Leave Job", false, window) close = guiCreateButton(250, 290, 100, 40, "Close", false, window) showCursor(true) else guiSetVisible(window, false) window = nil showCursor(false) end end end end end addEventHandler("onClientMarkerHit", jobMarker, getJob) function clicks() if (source == accept) then guiSetVisible(window, false) window = nil showCursor(false) triggerServerEvent("acceptJob", resourceRoot, localPlayer) elseif (source == leave) then guiSetVisible(window, false) window = nil showCursor(false) triggerServerEvent("leaveJob", resourceRoot, localPlayer) elseif (source == close) then guiSetVisible(window, false) window = nil showCursor(false) end end addEventHandler("onClientGUIClick", root, clicks) Server side -- server side addEventHandler("onResourceStart", root, function() team = createTeam("garbage", 0, 255, 0) end) addEvent("acceptJob", true) addEvent("leaveJob", true) function checkAccept(player) -- [accept job function] if (getElementData(player, "Jobs") == "garbage") then outputChatBox("you have alrady garbage job sorry!", player, 255, 0, 0) else setElementData(player, "Jobs", "garbage") setElementData(player, "trashlocation", 0) outputChatBox("job accept successfully!", player, 0, 255, 0) startJob(player) if (team) then setPlayerTeam(player, team) end end end addEventHandler("acceptJob", root, checkAccept) vehicles = { [408] = true } garbages = { [1] = {-1881.14380, -1707.47888, 21.75000}, [2] = {-1885.83081, -1723.84656, 21.75641}, [3] = {-1896.03723, -1731.46301, 21.75000}, [4] = {-1908.80933, -1733.61536, 21.75000}, [5] = {-1930.82690, -1767.77832, 26.18353}, [6] = {-1938.78809, -1781.46545, 29.32999}, [7] = {-1936.23059, -1760.15820, 24.36698}, [8] = {-1935.32361, -1742.58679, 22.91065}, [9] = {-1935.62610, -1719.10291, 21.75000}, [10] = {-1921.58350, -1706.34143, 21.90317}, [11] = {-1902.96033, -1704.98352, 21.75000} } function pickUpLocation(player, id) local x, y, z = garbages[id][1],garbages[id][2],garbages[id][3] local marker = createMarker(x, y, z, "cylinder", 3.0) -- <<<<<< Marker is here addEventHandler("onMarkerHit", marker, function(player) if getElementModel(getPedOccupiedVehicle(player)) == 408 then destroyElement(marker) marker = nil outputChatBox("hitted") setElementData(player, "trashlocation", getElementData(player, "trashlocation")+1) newLocation = getElementData(player, "trashlocation") pickUpLocation(player, newLocation) end end) end addEventHandler("onPlayerVehicleEnter", root, function(vehicle, seat, jacked) --[on player vehicle enter] if (vehicles[getElementModel(vehicle)]) and (getElementData(source, "Jobs") ~= "garbage") then removePedFromVehicle(source) x, y, z = getElementPosition(source) setElementPosition(source, x+1, y, z) outputChatBox("You don't have a garbage job", player, 255, 0, 0) end end) addEventHandler("onPlayerVehicleExit", root, function(vehicle, seat, jeacked) --[on player vehicle exit] if (getElementData(source, "Jobs") == "garbage") then if (getElementModel(vehicle) == 408) then outputChatBox("exited") setElementData(source, "Jobs", nil) destroyElement(marker) -- <<<<<<< problem is ehere end end end) trashVehicles = {} trashVehiclesBlips = {} function startJob(player) trashVehicle = createVehicle(408, -1879.74951, -1672.44751, 21.75000, 0, 0, 180) trashVehicleBlip = createBlipAttachedTo(trashVehicle, 51) trashVehicles[player] = trashVehicle trashVehiclesBlips[player] = trashVehicleBlip function checkVehicle(player) local vehicle = getPedOccupiedVehicle(source) local vehicleId = getElementModel(vehicle) outputChatBox(vehicleId) if (vehicleId == 408) then pickUpLocation(player, 1) setElementData(player, "trashlocation", 1) end end addEventHandler("onPlayerVehicleEnter", root, checkVehicle) end function leave(player)-- [leave job function] setElementData(player, "Jobs", nil) setPlayerTeam(player, nil) outputChatBox("leave successfully garbage job!", player, 255, 255, 0) end addEventHandler("leaveJob", root, leave)
    1 point
  2. its worked. Thank you very much for explaining it to me
    1 point
  3. Remove local word who is in front of marker first like this -> If u put local in front of variable and the variable is in a function the variable can be used in that function only. With ,,local`` you limit the scope of the variable! marker = createMarker(x, y, z, "cylinder", 3.0) -- <<<<<< like this! And again do this here too
    1 point
  4. Well which is client and which is server? Also here you should change your code with this -> function pickUpLocation(player, id) local x, y, z = garbages[id][1],garbages[id][2],garbages[id][3] marker = createMarker(x, y, z, "cylinder", 3.0) addEventHandler("onMarkerHit", marker, function(player) if getPedOccupiedVehicle(player) == 408 then destroyElement(marker) marker = nil outputChatBox("hitted",player) setElementData(player, "trashlocation", getElementData(player, "trashlocation")+1) newLocation = getElementData(player, "trashlocation") pickUpLocation(player, newLocation) end end) end
    1 point
×
×
  • Create New...