Chaos Posted June 29, 2015 Share Posted June 29, 2015 hey guys, I'm wondering which functions should i use to prevent car running over player ? Link to comment
tuaos Posted June 29, 2015 Share Posted June 29, 2015 hey guys,I'm wondering which functions should i use to prevent car running over player ? setElementCollisionsEnabled There is even an example on wiki for that function, as what you described/wanted. Link to comment
Chaos Posted June 29, 2015 Author Share Posted June 29, 2015 So i should use this with onPlayerDamage or which event ? function disableVehicleCollisionsNearPlayer(thePlayer, maxDistance) local playerX, playerY, playerZ = getElementPosition(thePlayer) local vehicles = getElementsByType("vehicle") for k,v in ipairs(vehicles) do local vehicleX, vehicleY, vehicleZ = getElementPosition(v) -- get the distance between the player and the vehicle: local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ) if (distance <= maxDistance) then -- disable collisions for the vehicle setElementCollisionsEnabled(v, false) end end end Link to comment
tuaos Posted June 29, 2015 Share Posted June 29, 2015 onResourceStart or onPlayerJoin or onVehicleEnter Link to comment
Chaos Posted June 29, 2015 Author Share Posted June 29, 2015 it's not working correctly function enterVehicle ( thePlayer, seat, jacked ) local playerX, playerY, playerZ = getElementPosition(thePlayer) local vehicles = getElementsByType("vehicle") for k,v in ipairs(vehicles) do local vehicleX, vehicleY, vehicleZ = getElementPosition(v) -- get the distance between the player and the vehicle: local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ) if (distance <= 1) then -- disable collisions for the vehicle setElementCollisionsEnabled(v, false) end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) Link to comment
tuaos Posted June 29, 2015 Share Posted June 29, 2015 it's not working correctly function enterVehicle ( thePlayer, seat, jacked ) local playerX, playerY, playerZ = getElementPosition(thePlayer) local vehicles = getElementsByType("vehicle") for k,v in ipairs(vehicles) do local vehicleX, vehicleY, vehicleZ = getElementPosition(v) -- get the distance between the player and the vehicle: local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ) if (distance <= 1) then -- disable collisions for the vehicle setElementCollisionsEnabled(v, false) end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) Making it easy, this is client-sided.. on entering vehicle sets it disabled to collide with players, and on exit reverse it. function enterVehicle() local players = getElementsByType ( "player" ) setElementCollidableWith ( source, players, false ) end addEventHandler ( "onClientVehicleEnter", getRootElement(), enterVehicle ) function exitingVehicle () local players = getElementsByType ( "player" ) setElementCollidableWith ( source, players, true ) addEventHandler("onClientVehicleStartExit", getRootElement(), exitingVehicle) Link to comment
Chaos Posted June 29, 2015 Author Share Posted June 29, 2015 well, i don't want ghost mode i just want to cancel it Link to comment
tuaos Posted June 29, 2015 Share Posted June 29, 2015 well, i don't want ghost mode i just want to cancel it ah, thats weird, you have to use: onClientVehicleCollision and do something like on hitting element player, bouncing back the vehicle or setting delay by freezing vehicle! cancelEvent() will not work! Link to comment
codeluaeveryday Posted June 30, 2015 Share Posted June 30, 2015 Try this. addEventHandler("onClientPlayerDamage", localPlayer, function(theAttacker, theWeapon, theBodypart) if ( theAttacker.type == "vehicle" and localPlayer.vehicle ~= theAttacker ) then cancelEvent() end end ) You can also use OnClientPreRender and run a quick check to see if a player has collided with the vehicle and quickly allow it to pass through 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