Jump to content

Locking cars to teams


Fantanic

Recommended Posts

You have to check if 'seat' is different to '0', then stop the function.

vehicle1 = createVehicle ( 602, 2279.1000976563, -1671.1999511719, 15.10000038147, 0, 0, 272 ) -----this car can be found at LS Grove Street near PoolBar 
vehicle = createVehicle ( modelID, x, y, z, rotX, rotY, rotZ ) 
state = setVehicleDoorState ( vehicle, 1, 1 ) 
setVehicleDamageProof ( vehicle, true )  -----car won't take damage (change it to false if you want to take damage) 
  
function lockPrivate( player, seat, jacked ) 
    if ( source == vehicle1 ) then 
        if ( seat ~= 0 ) then -- If the seat isn't '0' ( driver's seat ) 
            return -- Stop the function from executing. 
        end 
  
        local playerTeam = getPlayerTeam ( player ) 
        local oldTeamName = ( playerTeam and getTeamName ( playerTeam ) or "" ) 
        if ( oldTeamName ~= "admin" ) then 
            cancelEvent ( ) 
            outputChatBox ( "This vehicle is locked for following team: admin ", player, 255, 0, 0, false ) 
        else 
            outputChatBox ( "Welcome to your vehicle,Sir!", player, 0, 255, 0, false ) 
        end 
    end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), lockPrivate ) 
  
-----Made by Alen141(ingame name:Jimboy)------ 
-----Special thanks to : Solidsnake14(ingame name:Castillo)----- 
-----Visit SAUR Utopia RPG, IP: 128.204.203.103:22003----- 
-----Feel free to edit script on your own----- 
-----Don't remove credits----- 

Link to comment

It's a matter of relevancy but I want to point out that you can reduce the amount of lines by using the vehicle element inside the event handler instead of checking it inside the function.

vehicle1 = createVehicle(602, 2279.1000976563, -1671.1999511719, 15.10000038147, 0, 0, 272) -- This car can be found at LS Grove Street near Pool Bar 
  
vehicle = createVehicle(modelID, x, y, z, rotX, rotY, rotZ) 
setVehicleDoorState(vehicle, 1, 1) 
setVehicleDamageProof(vehicle, true)  -- Car won't take damage (change it to false if you want it to take damage) 
  
addEventHandler("onVehicleStartEnter", vehicle1, 
 function(player, seat, jacked) 
  if (seat ~= 0) then return end -- If the seat isn't '0' (driver's seat), then stop the function from executing 
   local playerTeam = getPlayerTeam(player) 
   local oldTeamName = (playerTeam and getTeamName(playerTeam) or "") 
   if (oldTeamName ~= "admin") then 
    cancelEvent() 
    outputChatBox("This vehicle is locked for following team: admin", player, 255, 0, 0, false) 
   else 
    outputChatBox("Welcome to your vehicle, Sir!", player, 0, 255, 0, false) 
   end 
  end 
 end 
) 
  
-----Made by Alen141(ingame name:Jimboy)------ 
-----Special thanks to : Solidsnake14(ingame name:Castillo)----- 
-----Visit SAUR Utopia RPG, IP: 128.204.203.103:22003----- 
-----Feel free to edit script on your own----- 
-----Don't remove credits----- 

Link to comment

I got a other question:

i've i place a car and i exit it , and im somewhere others that if i do a command that i teleport to the car that i placed.

Also is it posible to give police cars special sirens? i mean with special sirenss that the sirens are on the front of the cop car and etc

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...