Jump to content

Team Vehicles [HELP]


Recommended Posts

No errors in debug. But when Im on Team A it doesnt give me the outputChatBox, and beside from Team A, it allows me still to enter :) Thanks in advance. Maybe the problem is just the table. Can anyone help me with this. So that I wont make

a function

onVehicleStartEnter 

one by one.

listveh = { 
veh1 = createVehicle( 602, 1681.0999755859, 999.59997558594, 10.7 ), 
veh2 = createVehicle( 602, 1676.0999755859, 999.59997558594, 10.7 ), 
veh3 = createVehicle( 602, 1671.0999755859, 999.59997558594, 10.7 ), 
} 
  
function lockteamAcars( player, seat, jacked ) 
    if ( source == listveh ) then 
        local playerTeam = getPlayerTeam ( player ) 
        local oldTeamName = ( playerTeam and getTeamName ( playerTeam ) or "" ) 
        if ( oldTeamName ~= "Team A" ) then 
            cancelEvent ( ) 
            outputChatBox ( "This vehicle is only available for Team A", player, 255, 0, 0, false ) 
        else 
            outputChatBox ( "Have a safe trip BLAHAHASHDHAS", player, 0, 255, 0, false ) 
        end 
    end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), lockteamAcars ) 

Link to comment
Can anyone help me here. Its working if i put source == veh1, since I dont want to do the function 1by1 per vehicle so i managed to make tables but its not working..

Try this it should work

local listveh = { 
{602, 1681.0999755859, 999.59997558594, 10.7}, 
{602, 1676.0999755859, 999.59997558594, 10.7}, 
{602, 1671.0999755859, 999.59997558594, 10.7}, 
} 
  
function createVehicles() 
    for i , v in pairs (listveh) do  
        vehicle = createVehicle (v[1],v[2],v[3],v[4]) 
        addEventHandler ( "onVehicleStartEnter",vehicle, lockteamAcars ) 
    end  
end  
addEventHandler("onResourceStart", resourceRoot, createVehicles) 
  
function lockteamAcars( player, seat, jacked ) 
    local playerTeam = getPlayerTeam ( player ) 
    if playerTeam then  
    local teamName = getTeamName(playerTeam) 
        if ( teamName ~= "Team A" ) then 
         -- Your code  
        end 
    end 
end  
  
-- also you can add team names inside the table. 

Link to comment
Can anyone help me here. Its working if i put source == veh1, since I dont want to do the function 1by1 per vehicle so i managed to make tables but its not working..

didn't work because listveh it's a table so ou can't use (if source == listveh then).

Try this it should work

local listveh = { 
{602, 1681.0999755859, 999.59997558594, 10.7}, 
{602, 1676.0999755859, 999.59997558594, 10.7}, 
{602, 1671.0999755859, 999.59997558594, 10.7}, 
} 
  
function createVehicles() 
    for i , v in pairs (listveh) do  
        vehicle = createVehicle (v[1],v[2],v[3],v[4]) 
        addEventHandler ( "onVehicleStartEnter",vehicle, lockteamAcars ) 
    end  
end  
addEventHandler("onResourceStart", resourceRoot, createVehicles) 
  
function lockteamAcars( player, seat, jacked ) 
    local playerTeam = getPlayerTeam ( player ) 
    if playerTeam then  
    local teamName = getTeamName(playerTeam) 
        if ( teamName ~= "Team A" ) then 
         -- Your code  
        end 
    end 
end  
  
-- also you can add team names inside the table. 

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