Jump to content

Restrict vehicles to a team


TheNightRider

Recommended Posts

Hey guys ive been trying to set vehicles to only take driver based on their team I though to do 1 team and then try to do different teams which are in my server. However I cannot get the function to work :(

Could anyone give me some help please?

This far as i got so far,

  
  
function pAccess (thePlayer) 
if (police[getElementModel(source)]) and  then Cop = getPlayerTeam ( thePlayer ), not ( thePlayer ) then  
cancelEvent() 
outputChatBox("you are not a Police officer", thePlayer) 
  
  
end 
end 
addEventHandler("onVehicleStartEnter",root,pAccess) 
  
  

Link to comment

Do you want only 1 skin to be allowed to drive the vehicles? Or only specific vehicles to be driven by 1 team? Like, police officers can drive police vehicles?

Your if statement won't work.. Use "debugscript 3" command and try to run this script. You have to remember to debug your scripts, that is the most important action during scripting. Nobody scripts without debugging.

I don't really understand your question.

Link to comment
  
function pAccess (thePlayer) 
if (police[getElementModel(source)]) and getTeamName(getPlayerTeam(thePlayer)) == "Cop" then 
cancelEvent() 
outputChatBox("you are not a Police officer", thePlayer) 
end 
end 
addEventHandler("onVehicleStartEnter",root,pAccess) 

Link to comment

I have got it work however it only allows Cops to drive Police vehicles and nothing else lol

Anyone got any idea's?

  
local police = {[598]=true, [596]=true, [597]=true, [599]=true, [601]=true, [490]=true, [528]=true} 
  
function pAccess (thePlayer) 
if (police[getElementModel(source)]) and   
getTeamName(getPlayerTeam(thePlayer)) == "LVPD" then 
return 0 
else 
cancelEvent() 
outputChatBox("you are not a Police officer", thePlayer) 
end 
end 
addEventHandler("onVehicleStartEnter",root,pAccess) 
  
  

Link to comment

Okay but I didn't want it to restrict the Cops from driving other vehicles while their is no script in place to restrict them.

Could you please show me where ive gone wrong on this small script?

It should only allow police to drive police vehicles but not disallowing them to drive other vehicles.

Could i add something to make the script ignore other vehicles which isn't in the array?

Edited by Guest
Link to comment
local police = {[598]=true, [596]=true, [597]=true, [599]=true, [601]=true, [490]=true, [528]=true} 
  
function pAccess (thePlayer) 
if police[getElementModel(source)] and getTeamName(getPlayerTeam(thePlayer)) ~= "LVPD" then 
    cancelEvent() 
    outputChatBox("you are not a Police officer", thePlayer) 
end 
end 
addEventHandler("onVehicleStartEnter",root,pAccess) 
  

Link to comment

Thanks man that works a treat :D

I changed it from COP to LVPD cos i remembered that's the only police i have so far lol.

Another issue i noticed players cannot get into passengers seat what could I do to allow them to enter vehicle as passenger but disallow them to enter drivers seat?

PS could you explain the difference between using == and ~= ?

Link to comment
local police = {[598]=true, [596]=true, [597]=true, [599]=true, [601]=true, [490]=true, [528]=true} 
  
function pAccess (thePlayer, seat) 
if police[getElementModel(source)] and getTeamName(getPlayerTeam(thePlayer)) ~= "LVPD" and seat == 0 then 
    cancelEvent() 
    outputChatBox("you are not a Police officer", thePlayer) 
end 
end 
addEventHandler("onVehicleStartEnter",root,pAccess) 

Here you go. But.. You do realise that you must learn from the codes that are given to you, don't you?

Next time try to do it yourself. You need to learn from the mta wiki. Click the function names in the code for more info.

Link to comment

Thank you for your advise and I do use Wikki etc. and i did have the code working before you posted the code you modified.

I have it working 100% as expected and again thank you for your input.

PS you cannot expect someone to learn by just doing the Wikki thing getting input from other fellow human beings goes much further i.e. discussions brings more light to the subject :D

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...