Ernesto Posted March 9, 2018 Share Posted March 9, 2018 how to make a mta function before leaving a car Because when leaving the car the function is late and it says that I am not in the car I mean using onVehicleExit Link to comment
Ernesto Posted March 9, 2018 Author Share Posted March 9, 2018 addEventHandler( "onVehicleStartExit", resourceRoot, function( player ) local vehicle = getPedOccupiedVehicle( player ) if vehicle then local data = vehicles[ vehicle ] if data then if data.vehicleID < 0 then outputChatBox( "This temporal car " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") can´t be parked.", player, 255, 0, 0 ) elseif ( data.characterID > 0 and exports.players:getCharacterID( player ) == data.characterID and exports.items:has ( player, 1, data.vehicleID ) ) or hasObjectPermissionTo( player, "command.addmap", false ) and not isVehicleJob [ getVehicleName ( vehicle ) ] then local x, y, z = getElementPosition( vehicle ) local rx, ry, rz = getVehicleRotation( vehicle ) local success, error = exports.sql:query_free( "UPDATE vehicles SET respawnPosX = " .. x .. ", respawnPosY = " .. y .. ", respawnPosZ = " .. z .. ", respawnRotX = " .. rx .. ", respawnRotY = " .. ry .. ", respawnRotZ = " .. rz .. ", respawnInterior = " .. getElementInterior( vehicle ) .. ", respawnDimension = " .. getElementDimension( vehicle ) .. " WHERE vehicleID = " .. data.vehicleID ) if success then setVehicleRespawnPosition( vehicle, x, y, z, rx, ry, rz ) data.respawnInterior = getElementInterior( vehicle ) data.respawnDimension = getElementDimension( vehicle ) saveVehicle( vehicle ) outputChatBox( "The car " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") has been parked.", player, 0, 255, 0 ) else outputChatBox( "Parking Failed.", player, 255, 0, 0 ) end else outputChatBox( "You can´t park thiscar.", player, 255, 0, 0 ) end end else outputChatBox( "You are not driving any car.", player, 255, 0, 0 ) end end ) The same thing happens to me Any idea how to fix it? There is the function : Spoiler addEventHandler( "onVehicleStartExit", resourceRoot, function( player ) local vehicle = getPedOccupiedVehicle( player ) if vehicle then local data = vehicles[ vehicle ] if data then if data.vehicleID < 0 then outputChatBox( "This temporal car " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") can´t be parked.", player, 255, 0, 0 ) elseif ( data.characterID > 0 and exports.players:getCharacterID( player ) == data.characterID and exports.items:has ( player, 1, data.vehicleID ) ) or hasObjectPermissionTo( player, "command.addmap", false ) and not isVehicleJob [ getVehicleName ( vehicle ) ] then local x, y, z = getElementPosition( vehicle ) local rx, ry, rz = getVehicleRotation( vehicle ) local success, error = exports.sql:query_free( "UPDATE vehicles SET respawnPosX = " .. x .. ", respawnPosY = " .. y .. ", respawnPosZ = " .. z .. ", respawnRotX = " .. rx .. ", respawnRotY = " .. ry .. ", respawnRotZ = " .. rz .. ", respawnInterior = " .. getElementInterior( vehicle ) .. ", respawnDimension = " .. getElementDimension( vehicle ) .. " WHERE vehicleID = " .. data.vehicleID ) if success then setVehicleRespawnPosition( vehicle, x, y, z, rx, ry, rz ) data.respawnInterior = getElementInterior( vehicle ) data.respawnDimension = getElementDimension( vehicle ) saveVehicle( vehicle ) outputChatBox( "The car " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") has been parked.", player, 0, 255, 0 ) else outputChatBox( "Parking Failed.", player, 255, 0, 0 ) end else outputChatBox( "You can´t park thiscar.", player, 255, 0, 0 ) end end else outputChatBox( "You are not driving any car.", player, 255, 0, 0 ) end end ) Link to comment
Toliak Posted March 9, 2018 Share Posted March 9, 2018 use source instead of getPedOccupiedVehicle( player ) And if you want to check only driver exit, you should check addEventHandler( "onVehicleStartExit", resourceRoot, function( player, seat ) --you dont need if here. source always exists if (seat ~= 0) then return false end --exit if not driver -- your code here Link to comment
Ernesto Posted March 11, 2018 Author Share Posted March 11, 2018 Same error, say You are not driving any car 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