Oscuro87 Posted June 27, 2012 Share Posted June 27, 2012 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
qaisjp Posted June 27, 2012 Share Posted June 27, 2012 The player enters and the vehicle. Block one of them by using getElementType Link to comment
Oscuro87 Posted June 28, 2012 Author Share Posted June 28, 2012 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
qaisjp Posted June 28, 2012 Share Posted June 28, 2012 Please show the new code. Your welcome Link to comment
Oscuro87 Posted June 28, 2012 Author Share Posted June 28, 2012 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
qaisjp Posted June 28, 2012 Share Posted June 28, 2012 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
Oscuro87 Posted June 28, 2012 Author Share Posted June 28, 2012 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. 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! EDIT: Or not... If i do the totalSalary trick, vehicle won't get deleted. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now