AlfaMTA Posted April 10, 2014 Share Posted April 10, 2014 Hi guys I need to start this event addEventHandler("onMarkerHit",marker,...) Only, when the player is getVehicleEngineState = false and vehicle is getElementVelocity = 0 ie parked! I tried to do it addEventHandler("onMarkerHit",marker,function(player) if getElementVelocity(player) == 0 and getVehicleEngineState(getPedOccupiedVehicle(player)) == false then --code... end end) But, the event only executed one time and I dont have time to turn off the engine and neither park the car.. I need to update it constaly to check if the player is parked the car or not... I already tried to use timers and killTimer, but I couldn't stop it and generated a infinite loop! Thanks for all Link to comment
Gallardo9944 Posted April 10, 2014 Share Posted April 10, 2014 1. You are checking only 1 velocity value, which is X velocity. getElementVelocity returns 3 values, so you need to check all of them. Like that: local vehicle = getPedOccupiedVehicle(player) local vx,vy,vz = getElementVelocity(vehicle) if vx == 0 and vy == 0 and vz == 0 then -- bla bla bla end 2. You are checking both vehicle state and player velocity. Looks strange. It's better to change both to vehicle checks. 3. You can toggle to addEventHandler clientside with onClientRender to start the check if the vehicle has no velocity and etc and removeEventHandler as soon as he leaves the marker. Link to comment
Bonsai Posted April 10, 2014 Share Posted April 10, 2014 Maybe you should use "isElementWithinMarker" and a check every xx amount of time to check if the player is within that marker. Because onMarkerHit, as you said, is only triggered when u first hit it. After that you are inside of it. Link to comment
AlfaMTA Posted April 10, 2014 Author Share Posted April 10, 2014 Thx for the two who tried to help me! Now, my problem is in this line: local theVehicle = getPedOccupiedVehicle(hitElement) I'm already 2 hours trying to fix it but I don't have success! >;( >ERRO Bad argument @ 'getPedOccupiedVehicle' Link to comment
Bonsai Posted April 10, 2014 Share Posted April 10, 2014 Thx for the two who tried to help me! Now, my problem is in this line: local theVehicle = getPedOccupiedVehicle(hitElement) I'm already 2 hours trying to fix it but I don't have success! >;( >ERRO Bad argument @ 'getPedOccupiedVehicle' As far as I know client side marker hit event only supports player elements. If you do it server side you will have to check if the hitElement is a player or a vehicle first. Try getElementType. Link to comment
Gallardo9944 Posted April 11, 2014 Share Posted April 11, 2014 If it's a player, it uses his vehicle. If it's already a vehicle, then it stays. local vehicle = hitElement if getElementType(vehicle) == "player" then vehicle = getPedOccupiedVehicle(vehicle) end 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