Jump to content

Help| Marker Hit Problem


scolen

Recommended Posts

When one of the markers here is hit, why does the chat run 3 times in the outputchatbox? What is the reason for it? 

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
}

addEventHandler("onPlayerVehicleEnter", root, function(vehicle, seat, jacked)
    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)

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

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]
    marker = createMarker(x, y, z, "cylinder", 3.0)

    addEventHandler("onMarkerHit", marker, function(player)
        destroyElement(marker)
        outputChatBox("hitted")
        setElementData(player, "trashlocation", getElementData(player, "trashlocation")+1)
        newLocation = getElementData(player, "trashlocation")
        pickUpLocation(player, newLocation)
    end)
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)

 

Link to comment

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

 

  • Thanks 1
Link to comment
12 hours ago, FlorinSzasz said:

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

 

thank you worked ❤️

  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...