Zuher Laith Posted January 19, 2016 Share Posted January 19, 2016 Greetings Everyone .. I Was looking for a way to moveObject Only If a Ped is in Vehicle and if the ped not in Vehicle , then do nothing. So here's my Code for Moving the Object: (Work's Fine) local Door4 = createObject(980,2087.5,1433.1999511719,12.300000190735,0,359.75,89.499969482422) local markerDoor4 = createMarker(2088.3000488281,1433.3000488281,9.8000001907349,'cylinder',8,0,0,0,0) addEventHandler('onMarkerHit',markerDoor4, function ( hitElement2 ) moveObject(Door4,1000,2087.5,1433.1999511719,7.1999998092651) end ) What i want is to "MoveObject" Only if the Player was in Vehicle .. I Saw this isPedInVehicle , and i tried this code: local Door4 = createObject(980,2087.5,1433.1999511719,12.300000190735,0,359.75,89.499969482422) local markerDoor4 = createMarker(2088.3000488281,1433.3000488281,9.8000001907349,'cylinder',8,0,0,0,0) function outputIsInVehicle ( sourcePlayer, commandName, checkedPlayerName ) -- we get the player element from the nick specified local checkedPlayer = getPlayerFromName ( checkedPlayerName ) -- if there exists a player with that nick if ( checkedPlayer ) then -- if he's in a vehicle, if isPedInVehicle ( checkedPlayer ) then -- tell the source player addEventHandler('onMarkerHit',markerDoor4, function ( hitElement2 ) moveObject(Door4,1000,2087.5,1433.1999511719,7.1999998092651) end ) outputChatBox ( checkedPlayerName .. " is in a vehicle.", sourcePlayer ) -- if he's not in a vehicle, else -- Nothing if the player not in vehicle. end -- if it doesn't exist, else -- tell the source player outputChatBox ( "Invalid player name.", sourcePlayer ) end end So i tried this, but didn't worked. P.S: i used this code only on server side. Waiting for Reply. Link to comment
tosfera Posted January 19, 2016 Share Posted January 19, 2016 try this; local Door4 = createObject(980,2087.5,1433.1999511719,12.300000190735,0,359.75,89.499969482422) local markerDoor4 = createMarker(2088.3000488281,1433.3000488281,9.8000001907349,'cylinder',8,0,0,0,0) addEventHandler('onMarkerHit',markerDoor4, function ( hitElement ) if ( getElementType ( hitElement ) == "player" ) then if ( getPedOccupiedVehicle ( hitElement ) ) then moveObject(Door4,1000,2087.5,1433.1999511719,7.1999998092651) end end end ) Link to comment
Army@1 Posted January 19, 2016 Share Posted January 19, 2016 Or this: local Door4 = createObject(980,2087.5,1433.1999511719,12.300000190735,0,359.75,89.499969482422) local markerDoor4 = createMarker(2088.3000488281,1433.3000488281,9.8000001907349,'cylinder',8,0,0,0,0) addEventHandler('onMarkerHit',markerDoor4, function ( hitElement2 ) if getElementType ( hitElement2 ) == "player" then if isPedInVehicle ( hitElement2 ) then moveObject(Door4,1000,2087.5,1433.1999511719,7.1999998092651) end end ) If for some reason, the above doesn't work, this should: local Door4 = createObject(980,2087.5,1433.1999511719,12.300000190735,0,359.75,89.499969482422) local markerDoor4 = createMarker(2088.3000488281,1433.3000488281,9.8000001907349,'cylinder',8,0,0,0,0) addEventHandler('onMarkerHit',markerDoor4, function ( hitElement2 ) if getElementType ( hitElement2 ) == "vehicle" then if isElement ( getVehicleOccupant ( hitElement2 ) ) then moveObject(Door4,1000,2087.5,1433.1999511719,7.1999998092651) end end ) Link to comment
Zuher Laith Posted January 19, 2016 Author Share Posted January 19, 2016 @tosfera Works Great ! I Wonder if i can Destroy Vehicle On the same last code .. can i do that? Link to comment
Zuher Laith Posted January 19, 2016 Author Share Posted January 19, 2016 Problem Solved. Thank's every one for help! 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