Jump to content

Restrict vehicle to team [Help pls]


Leonard.DC

Recommended Posts

Im trying to restrict some vehicles to teams, but it doesn't work, and doesn't output anything in the debugscript, can someone tell me why?

copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } 
  
function enterVehicle1 ( thePlayer, seat, jacked ) 
    if getElementType ( thePlayer ) == "player" then 
        if ( copVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "team i use" ) ) then 
            removePedFromVehicle( thePlayer )-- force the player out of the vehicle 
            outputChatBox("********", thePlayer, 255, 0, 0) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle1 ) 
  
medicVehicles = { [416] = true, } 
  
function enterVehicle2 ( thePlayer, seat, jacked ) 
    if getElementType ( thePlayer ) == "player" then 
        if ( medicVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "team i use" ) ) 
            removePedFromVehicle( thePlayer ) 
            outputChatBox("*******", thePlayer, 255, 0, 0) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle2 ) 

It is all the code

Link to comment

try this:

copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } 
 copTeam  = "TEAM1" --- adds this team here 
  
function enterVehicle1 ( thePlayer, seat, jacked ) 
     if ( getElementType ( thePlayer ) == "player" ) then 
        local team = getPlayerTeam ( thePlayer ) 
        local teamName = ( team and getTeamName ( team ) or "" ) 
        if ( teamName == copTeam ) and ( copVehicles[getElementModel ( source )] )) then 
        if ( copVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "team i use" ) ) then 
            removePedFromVehicle( thePlayer )-- force the player out of the vehicle 
            outputChatBox("********", thePlayer, 255, 0, 0) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle1 ) 
  
medicVehicles = { [416] = true, } 
  
medicTeam = "TEAM2" 
  
function enterVehicle2 ( thePlayer, seat, jacked ) 
     if ( getElementType ( thePlayer ) == "player" ) then 
        local team = getPlayerTeam ( thePlayer ) 
        local teamName = ( team and getTeamName ( team ) or "" ) 
        if ( teamName == medicTeam ) and ( medicVehicles[getElementModel ( source )] )) then 
            removePedFromVehicle( thePlayer ) 
            outputChatBox("*******", thePlayer, 255, 0, 0) 
        end 
    end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle2 ) 

Link to comment

It doesn't work i dont know why, im changed removePedFromVehicle to cancelEvent(), and used and fixed the code NearGreen say me, but it doesn't output anything in the debugscript, and the event doesn't cancel when i am in another team that not be medic or cop

copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } 
copTeam  = "Police" 
  
function enterVehicle1 ( thePlayer, seat, jacked ) 
     if ( getElementType ( thePlayer ) == "player" ) then 
        local team = getPlayerTeam ( thePlayer ) 
        local teamName = ( team and getTeamName ( team ) or "" ) 
        if ( teamName == copTeam ) and ( copVehicles[getElementModel ( source )] ) then 
         if ( copVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "Police" ) ) then 
            cancelEvent() 
            outputChatBox("You cant use this vehicle", thePlayer, 255, 0, 0) 
        end 
    end 
end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle1 ) 
  
medicVehicles = { [416] = true, } 
medicTeam = "Medic" 
  
function enterVehicle2 ( thePlayer, seat, jacked ) 
     if ( getElementType ( thePlayer ) == "player" ) then 
        local team = getPlayerTeam ( thePlayer ) 
        local teamName = ( team and getTeamName ( team ) or "" ) 
        if ( teamName == medicTeam ) and ( medicVehicles[getElementModel ( source )] ) then 
         if ( medicVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "Medic" ) ) then 
            cancelEvent() 
            outputChatBox("You cant use this vehicle", thePlayer, 255, 0, 0) 
        end 
    end 
    end 
    end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle2 ) 

Recent code, i use Server side

Link to comment

Maybe try this;

copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } 
  
addEventHandler ( "onVehicleStartEnter", root, 
    function ( thePlayer, seat, jacked ) 
        if ( getElementType ( thePlayer ) == "player" ) then 
            local team = getPlayerTeam ( thePlayer ); 
            if ( team ) then 
                if ( ( copVehicles [ getElementModel ( source ) ] ) and not ( team == getTeamFromName ( "Police" ) ) ) then 
                    cancelEvent(); 
                    outputChatBox ( "You can't use this vehicle", thePlayer, 255, 0, 0, true ); 
                end 
            end 
        end 
    end 
); 

Just woke up, can be garbage. xD

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