Jump to content

OnClientMarkerHit triggers more than once when in vehicle.


Oscuro87

Recommended Posts

Ohai :)

I come today with a new oddity MTA came up with today.

When any player is in a vehicle, and drives onto a marker, it triggers it not only once, but 4 times.

Code might help, so :

  
function showSweeperGuiOrStopJob() 
    if getElementData(source, "markerJOB") == "streetsweeper" and not isPedInVehicle(localPlayer) then 
        triggerServerEvent("onPlayerToggleMouse", localPlayer) 
        guiSetVisible(gui,true) 
    elseif isPedInVehicle(localPlayer) and getElementData(source, "markerJOB") == "streetsweeper" then 
        local veh = getPedOccupiedVehicle(localPlayer) 
        if getElementData(veh, "vehicleJOB") and getElementData(veh, "vehicleJOB") == "streetsweeper" then 
            triggerServerEvent("onPlayerStopsStreetsweeperJob", localPlayer, totalSalary, veh) 
            totalSalary = 0 
            killTimer(cleanerTimer) 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", root, showSweeperGui) 
  

I'm basically using the same function to start the job (show the GUI) whenever a player steps on the marker while on foot.

If the player is in a streetsweeper vehicle and drives through the marker, then it stops the job and pays him/her.

That works, but it trigger the marker hit 4 times!

Here's the chatbox output :

((Street Cleaner Job)) $12 was added to your final pay.

You stopped working and got paid $12

You stopped working and got paid $0

You stopped working and got paid $0

You stopped working and got paid $0

And the warnings i get are that server cannot destroy element (of the car), nor kill the timer, which is normal as it's both been destroyed at the first "pass" of marker hit.

How do I avoid my vehicle to trigger marker hit more than once? D:

Thanks!

Link to comment

Hey, thanks for the reply!

I just tried your solution, and it fixes half of the problem indeed.

Instead of triggering 4 times, it triggers twice, which is an improvement already.

I just dunno why it still triggers 2 times as i blocked the "vehicle" element type. Kind of unsure on this one.

Link to comment

Oh yes sure,

First i separated both jobs into 2 distinct functions, i thought it was clearer that way.

Here it is :

  
function showSweeperGui(player) 
    if player == localPlayer and getElementType(player) == "player" and not isPedInVehicle(player) then 
        if getElementData(source, "markerJOB") == "streetsweeper" and not isPedInVehicle(player) then 
            triggerServerEvent("onPlayerToggleMouse", localPlayer) 
            guiSetVisible(gui,true) 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", root, showSweeperGui) 
  

  
function stopSweeperJob(player) 
    if player == localPlayer and getElementType(player) == "player" and isPedInVehicle(player) and getElementData(source, "markerJOB") == "streetsweeper" then 
        local veh = getPedOccupiedVehicle(player) 
        if getElementData(veh, "vehicleJOB") and getElementData(veh, "vehicleJOB") == "streetsweeper" then 
            triggerServerEvent("onPlayerStopsStreetsweeperJob", player, totalSalary, veh) 
            totalSalary = 0 
            killTimer(cleanerTimer) 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", root, stopSweeperJob) 
  

Link to comment
  
function showSweeperGui(player) 
    if (player == localPlayer) and (getElementData(source, "markerJOB") == "streetsweeper") then 
        if  (not isPedInVehicle(player) ) then 
            triggerServerEvent("onPlayerToggleMouse", localPlayer) 
            guiSetVisible(gui,true) 
            return 
        end 
        local veh = getPedOccupiedVehicle(player) 
        if getElementData(veh, "vehicleJOB") and getElementData(veh, "vehicleJOB") == "streetsweeper" then 
            triggerServerEvent("onPlayerStopsStreetsweeperJob", player, totalSalary, veh) 
            totalSalary = 0 
            killTimer(cleanerTimer) 
        end 
end 
addEventHandler("onClientMarkerHit", root, showSweeperGui) 
  

this has a combination of both

Link to comment

Hmmm I just tried this, and again it triggers twice. It's bizarre 'cause logically, this should work nicely.

Might aswell consider it's an MTA bug. xD

Well if this remains like this, i can just say : if the total salary is == 0, then i don't trigger the server event or anything. It's really using duct tape, but whatever! xD

EDIT: Or not... If i do the totalSalary trick, vehicle won't get deleted. :P

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...