Mossy Posted November 19, 2012 Posted November 19, 2012 Hey I'm trying to get this script to restrict cars to teams only. I have this script but if I'm greater than or equal to, say, 20 feet, the message disappears but if I'm less than or equal to 20 feet the message keeps appearing: addEventHandler("onVehicleStartEnter", root, function(p) local m = getElementModel(source) if m == 598 or m == 596 or m == 597 or m == 599 or m == 523 then if (getPlayerTeam(p) and getTeamName(getPlayerTeam(p)) == "Police") then outputChatBox ( "Access Granted.", p, 124, 252, 0, false ) else cancelEvent() outputChatBox ( "You must be part of the Police team to get access to this vehicle.", p, 255, 0, 0, false ) end end end ) How can I set a distance from the nearest car and the player? Thanks.
Castillo Posted November 20, 2012 Posted November 20, 2012 I don't understand what are you trying to do.
Mossy Posted November 20, 2012 Author Posted November 20, 2012 I don't understand what are you trying to do. If I approach a car and not on the Police team, I get a message saying something like "Can't access" and make the player not enter. However, if I leave the police car (say 20 footsteps), and if I press enter, the message still appears, yet I'm not next to the cop car. Basically, the distance radius from the car is too big. How can I make the message appear when I'm completely next to the car and not 20 feet away?
Mossy Posted November 20, 2012 Author Posted November 20, 2012 I want to cancel the event if a player is not on the Police team. I modified it a bit but it's still not working. addEventHandler("onVehicleEnter", root, function(p) local m = getElementModel(source) if m == 598 or m == 596 or m == 597 or m == 599 or m == 523 then if (getPlayerTeam(p) and getTeamName(getPlayerTeam(p)) == "Police") then outputChatBox ( "Access Granted.", p, 124, 252, 0, false ) else removePedFromVehicle ( p ) outputChatBox ( "You must be part of the Police team to get access to this vehicle.", p, 255, 0, 0, false ) end end end )
myonlake Posted November 20, 2012 Posted November 20, 2012 Server-side local models = {[523]=true, [596]=true, [597]=true, [598]=true, [599]=true} addEventHandler("onPlayerVehicleEnter", root, function(vehicle, seat, jacked) if models[getElementModel(vehicle)] then if (getPlayerTeam(source) and getTeamName(getPlayerTeam(source)) == "Police") then outputChatBox("Access Granted.", source, 124, 252, 0, false) else removePedFromVehicle(source) outputChatBox("You must be part of the Police team to get access to this vehicle.", source, 255, 0, 0, false) end end end )
Castillo Posted November 20, 2012 Posted November 20, 2012 local minDistance = 5 addEventHandler ( "onVehicleStartEnter", root, function ( p ) local m = getElementModel ( source ) if ( m == 598 or m == 596 or m == 597 or m == 599 or m == 523 ) then local px, py, pz = getElementPosition ( p ) local vx, vy, vz = getElementPosition ( source ) if ( getDistanceBetweenPoints3D ( px, py, pz, vx, vy, vz ) > minDistance ) then return end if ( getPlayerTeam ( p ) and getTeamName ( getPlayerTeam ( p ) ) == "Police" ) then outputChatBox ( "Access Granted.", p, 124, 252, 0, false ) else cancelEvent ( ) outputChatBox ( "You must be part of the Police team to get access to this vehicle.", p, 255, 0, 0, false ) end end end ) Change 'minDistance' to whatever you want.
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