Stevenn Posted April 19, 2012 Posted April 19, 2012 Hello, i got an question, i want when a client enters a vehicle, and if the vehicle id is a special one then it will trigger an event but im new to this kind of things and i don't know how to do it. could anyone help out with givng an example?
Absence2 Posted April 19, 2012 Posted April 19, 2012 https://wiki.multitheftauto.com/wiki/OnC ... hicleEnter this?
Stevenn Posted April 19, 2012 Author Posted April 19, 2012 yes, i forgot to add this. but this is what i got so far function createMarkerOnVehicleEnter () if getElementModel ( getPedOccupiedVehicle ( localPlayer ) ) == myid then triggerEvent ( "my event", localPlayer ) end addEventHandler ( "onClientVehicleEnter", root, createMarkerOnVehicleEnter )
Stevenn Posted April 19, 2012 Author Posted April 19, 2012 well its rather obvious isn't it? i can't test the code atm as im not on my normal PC
Absence2 Posted April 19, 2012 Posted April 19, 2012 no it isn't, first of all, that code will never work. it's a complete mess, including syntax errors. read this (from wiki) function planeEnter ( theVehicle, seat, jacked ) -- when someone enters a vehicle local id = getElementModel ( theVehicle ) -- get the model ID of the vehicle if id == 519 or id == 577 then -- if theVehicle is either Shamal or AT-400 local vehicleName = getVehicleName ( theVehicle ) -- get the name of theVehicle outputChatBox ( "Someone stole a " .. vehicleName .. "!" ) -- announce that someone stole the plane end end -- add the event handler to the event addEventHandler ( "onPlayerVehicleEnter", getRootElement(), planeEnter )
Michael# Posted April 19, 2012 Posted April 19, 2012 (edited) yes, i forgot to add this. but this is what i got so far function createMarkerOnVehicleEnter () if getElementModel ( getPedOccupiedVehicle ( localPlayer ) ) == myid then triggerEvent ( "my event", localPlayer ) end addEventHandler ( "onClientVehicleEnter", root, createMarkerOnVehicleEnter ) local tVehicles = { [ 411 ] = true; } addEventHandler ( 'onClientVehicleEnter', root, function ( uPlayer ) if ( tVehicles [ getElementModel ( source ) ] ) then -- if vehicle is any of the ids in the table triggerEvent ( 'checkForData', uPlayer ); -- trigger event [ THAT'S JUST AN EXAMPLE ] end end ) You can add more vehicles to the table doing: [ Vehicle ID ] = true; -- change to false if you don't wanna check if vehicle is that Hope you understand. Edited April 19, 2012 by Guest
Stevenn Posted April 19, 2012 Author Posted April 19, 2012 Alright, it works perfectly thank ya'll. (I decided to use it serversided)
Castillo Posted April 19, 2012 Posted April 19, 2012 local tVehicles = { [ 411 ] = true; } addEventHandler ( 'onClientVehicleEnter', root, function ( uPlayer ) if ( tVehicles [ getPedOccupiedVehicle ( uPlayer ) ] ) then -- if vehicle is any of the ids in the table triggerEvent ( 'checkForData', uPlayer ); -- trigger event [ THAT'S JUST AN EXAMPLE ] end end ) You can add more vehicles to the table doing: [ Vehicle ID ] = true; -- change to false if you don't wanna check if vehicle is that Hope you understand. This will never work because you're checking if the userdata of the vehicle is on the table, you must get the vehicle model instead. local tVehicles = { [ 411 ] = true; } addEventHandler ( 'onClientVehicleEnter', root, function ( uPlayer ) if ( tVehicles [ getElementModel ( source ) ) ] ) then -- if vehicle is any of the ids in the table triggerEvent ( 'checkForData', uPlayer ); -- trigger event [ THAT'S JUST AN EXAMPLE ] end end )
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