Jump to content

How to start a a event when


AlfaMTA

Recommended Posts

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

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

Thx for the two who tried to help me! :D

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
Thx for the two who tried to help me! :D

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

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