Jump to content

Problems with some vehicle functions


Enkanet

Recommended Posts

I want to lock a vehicle. I can lock but it only locks when I am inside it because of the:

local vehicle = getPedOccupiedVehicle(Player)

code. Any way to make it even if you aren't inside it? And, when I lock the vehicle inside, I still can get out without unlocking. Any way to fix this?

Link to comment

You need to save element of car in player element data. While creating car for player, or while first enter, or while player targeting the car. There is many possibilities.

Those in lua are just examples of couple function that you can use to get car element.

  
setElementData() 
onPlayerTarget()  
onVehicleEnter() 
onClientVehicleEnter() 
  

Or you can just setDataElement for car with owner serial, then loop through all cars searching for the right one with owner serial. Yep but this is less efficient way.

For exiting you need to check if car is locked on onClientVehicleStartExit event if yes then cancelEvent() with information.

onClientVehicleStartExit() 
cancelEvent 

Link to comment
Two brothers playing MTA on the same computer will have the same serial (even if they are not using the same user session)

Yeah, so I guess I should use setElementData ? Maybe like, setElementData(theVehicle "owner") ? Or setAccountData or sth? I am going to use MySQL for this problems but I am new for MySQL

Link to comment
Two brothers playing MTA on the same computer will have the same serial (even if they are not using the same user session)

Yeah, so I guess I should use setElementData ? Maybe like, setElementData(theVehicle "owner") ? Or setAccountData or sth? I am going to use MySQL for this problems but I am new for MySQL

Well you can use setVehiclePlateText and getVehiclePlateText, then just add setElementData to owner of the car text-plate + serial, so you will avoid, doing it by nickname and what Citizen said.

Link to comment

You can define a lastVehicle variable on client-side using onClientVehicleEnter. And using a command handler on client-side, trigger a server event to lock the vehicle while passing the lastVehicle userdata.

Didn't read carefully the rest of the replies.

local lastVehicle 
  
function defineLastVehicle() 
    lastVehicle = source 
end 
addEventHandler ("onClientVehicleEnter", root, defineLastVehicle) 

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