local MarkerCaixas = { {2781.453, -2410.471, 13.635}, {2789.665, -2449.085, 13.633}, {2789.689, -2463.15, 13.633}, {2789.931, -2501.496, 13.648}, {2789.727, -2487.733, 13.648}, {2789.069, -2424.517, 13.633}, {2789.896, -2410.572, 13.633}, {2781.097, -2424.963, 13.635}, {2781.404, -2447.608, 13.635}, {2781.545, -2463.246, 13.635}, {2781.879, -2486.11, 13.657}, {2781.484, -2501.025, 13.663}, } local caixasCache = {} local Entregas = { {2763.212, -2379.358, 13.633}, {2763.284, -2515.589, 13.642}, } local blipCaixas = {} local MarkerEntrega = false local ped = createPed(306, 2751.31592, -2453.76782, 13.64319, 265) setElementData(ped, "imortal", true) setElementFrozen(ped, true) setElementData(ped, 'visibleName', 'Emprego de Empilhador') function PedImortal() if getElementData(source, "imortal") then cancelEvent() end end addEventHandler('onClientPedDamage', root, PedImortal) addEventHandler('onClientClick', root, function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld) if button == "right" and state == "down" or button == "left" and state == "down" then if clickedWorld == ped then if getElementData(localPlayer, 'Emprego') == config['ElementData'] then local playerPosX, playerPosY, playerPosZ = getElementPosition(localPlayer) local pedPosX, pedPosY, pedPosZ = getElementPosition(ped) if getDistanceBetweenPoints3D(playerPosX, playerPosY, playerPosZ, pedPosX, pedPosY, pedPosZ) <= 5 then if not serviceActive then entrarService() else sairService() end end else notifyC ('Você não trabalha como Empilhador.', 'error') end end end end) function entrarService() serviceActive = true triggerServerEvent("dock.spawnarVehicle", resourceRoot) generateBoxes() end function sairService() if isElement(MarkerEntrega) then destroyElement(MarkerEntrega) end if isElement(MarkerEntrega2) then destroyElement(MarkerEntrega2) end for k,v in pairs(caixasCache) do local obj, mark = unpack(v) if blipCaixas[obj] and isElement(blipCaixas[obj]) then destroyElement(blipCaixas[obj]) end if isElement(obj) then destroyElement(obj) end if isElement(mark) then destroyElement(mark) end end setElementData(localPlayer, "objectCaixaPlayer", false) triggerServerEvent("dock.removerVehicle", localPlayer, localPlayer) serviceActive = false end function generateBoxes() local modelID = 1224 for k,v in pairs(MarkerCaixas) do local x, y, z = unpack(v) local obj = createObject(modelID, x, y, z-0.37) setElementFrozen(obj, true) local mark = createMarker(x, y, z-0.9, "cylinder", 3.0, 252, 0, 75, 100) -- setElementData(mark, 'markerData', {icon = 'marker'}) blipCaixas[obj] = createBlipAttachedTo(obj, 41) setElementData(blipCaixas[obj], 'blipIcon', 'loc') setElementData(blipCaixas[obj], 'blipSize', 22, false) setElementData(blipCaixas[obj], 'blipFarShow', true, false) setElementData(mark, "dock.objectCaixa", obj) setElementData(localPlayer, "objectCaixaPlayer", obj) addEventHandler("onClientMarkerHit", mark, function(hitElement) if hitElement == localPlayer then local veh = getPedOccupiedVehicle(localPlayer) if veh and getElementModel(veh) == 530 and serviceActive then if getElementData(veh, "dock.Caixa") then notifyC ('Já existe uma caixa na empilhadeira.', 'error') return end triggerServerEvent("dock.attachCaixa", localPlayer, localPlayer) if getElementData(source, "dock.objectCaixa") and isElement(getElementData(source, "dock.objectCaixa")) and blipCaixas[getElementData(source, "dock.objectCaixa")] and isElement(blipCaixas[getElementData(source, "dock.objectCaixa")]) then setElementData(blipCaixas[getElementData(source, "dock.objectCaixa")], 'blipIcon', nil) setElementData(blipCaixas[getElementData(source, "dock.objectCaixa")], 'blipSize', nil) setElementData(blipCaixas[getElementData(source, "dock.objectCaixa")], 'blipFarShow', nil) destroyElement(blipCaixas[getElementData(source, "dock.objectCaixa")]) end destroyElement(getElementData(source, "dock.objectCaixa")) destroyElement(source) createEnd() end end end) caixasCache[#caixasCache + 1] = {obj, mark} end end function createEnd() local money = math.random(1,#Entregas) local x,y,z = unpack(Entregas[money]) MarkerEntrega = createMarker(x, y, z-0.9, "cylinder", 2, 252, 0, 75, 100) -- setElementData(MarkerEntrega, 'markerData', {icon = 'marker'}) addEventHandler("onClientMarkerHit", MarkerEntrega, function(hitElement) if hitElement == localPlayer then local veh = getPedOccupiedVehicle(localPlayer) if veh and getElementModel(veh) == 530 then local box = getElementData(veh, "dock.Caixa") if box and serviceActive then if getElementData(source, "dock.objectCaixa") and isElement(getElementData(source, "dock.objectCaixa")) and blipCaixas[getElementData(source, "dock.objectCaixa")] and isElement(blipCaixas[getElementData(source, "dock.objectCaixa")]) then destroyElement(blipCaixas[getElementData(source, "dock.objectCaixa")]) end triggerServerEvent("dock.removeCaixa", resourceRoot) --triggerEvent('addBox', localPlayer, "Se você ainda quer continuar trabalhando, continue pegando as caixas.", "info") if getBoxCount() < 1 then generateBoxes() end destroyElement(source) else notifyC ('Não há nenhuma caixa na empilhadeira.', 'error') end end end end) end function getBoxCount() local count = 0 for k,v in pairs(caixasCache) do local obj, mark = unpack(v) if isElement(obj) and isElement(mark) then count = count + 1 end end return count end