Jump to content

problem restricting vehicle to level


goofie88

Recommended Posts

hello i have a problem on restricting a vehicle on player level =(

hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
function hydralock(player, seat, jacked) 
local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
    if (source == hydra) then 
        if (seat == 0) then 
        if  (level <= 7) then 
             cancelEvent() 
             outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
        end 
      end 
    end 
    end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), hydralock ) 

what did i do wrong? all level can enter it and no output =(

Link to comment
hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
  
function hydralock(player, seat, jacked) 
local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
    if (source == hydra) then 
        if (seat == 0) then 
        if  (level <= 7) then 
             cancelEvent() 
             outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
    end 
   end      
 end 
end 
addEventHandler ( "onVehicleStartEnter", hydra, hydralock) 

1)you forgot to mention which vehicle it should be the name of vehicle in-place of getRootElement()

2)an extra End

Link to comment

I think like this

Hydra = 
{ 
createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
createVehicle ( 520, x, y, z, 0, 0, 90 ) 
} 
  
    function hydralock(player, seat, jacked) 
    local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
        if (source == Hydra) then 
            if (seat == 0) then 
            if  (level <= 7) then 
                 cancelEvent() 
                 outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
        end 
       end     
     end 
    end 
    addEventHandler ( "onVehicleStartEnter", Hydra, hydralock) 

Just replace the x, y, z with the position.

Link to comment
hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
  
function hydralock(player, seat, jacked) 
local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
    if (source == hydra) then 
        if (seat == 0) then 
        if  (level <= 7) then 
             cancelEvent() 
             outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
    end 
   end      
 end 
end 
addEventHandler ( "onVehicleStartEnter", hydra, hydralock) 

1)you forgot to mention which vehicle it should be the name of vehicle in-place of getRootElement()

2)an extra End

Wrong. He used a statement with a condition "source == hydra" which does the same as putting the element 'hydra' instead of 'root'.

I think like this
Hydra = 
{ 
createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
createVehicle ( 520, x, y, z, 0, 0, 90 ) 
} 
  
    function hydralock(player, seat, jacked) 
    local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
        if (source == Hydra) then 
            if (seat == 0) then 
            if  (level <= 7) then 
                 cancelEvent() 
                 outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
        end 
       end     
     end 
    end 
    addEventHandler ( "onVehicleStartEnter", Hydra, hydralock) 

Just replace the x, y, z with the position.

It's wrong too because you can't compare an element with a table.

Link to comment
hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
  
function hydralock(player, seat, jacked) 
local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
    if (source == hydra) then 
        if (seat == 0) then 
        if  (level <= 7) then 
             cancelEvent() 
             outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
    end 
   end      
 end 
end 
addEventHandler ( "onVehicleStartEnter", hydra, hydralock) 

1)you forgot to mention which vehicle it should be the name of vehicle in-place of getRootElement()

2)an extra End

Wrong. He used a statement with a condition "source == hydra" which does the same as putting the element 'hydra' instead of 'root'.

I think like this
Hydra = 
{ 
createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) 
createVehicle ( 520, x, y, z, 0, 0, 90 ) 
} 
  
    function hydralock(player, seat, jacked) 
    local level = tonumber ( getElementData ( player, "level" ) or 0 ) 
        if (source == Hydra) then 
            if (seat == 0) then 
            if  (level <= 7) then 
                 cancelEvent() 
                 outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) 
        end 
       end     
     end 
    end 
    addEventHandler ( "onVehicleStartEnter", Hydra, hydralock) 

Just replace the x, y, z with the position.

It's wrong too because you can't compare an element with a table.

Oh okay sorry and thanks for the information

Link to comment
local pVehicles = 
{ 
    [1] = createVehicle( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ); 
} 
  
function VehicleEnter( player, seat ) 
    if ( seat == 0 ) then 
        local nLevel = tonumber( getElementData( player, "level" ) ) or 0; 
        if ( nLevel < 7 ) then 
            cancelEvent(); 
            outputChatBox( "To enter this hydra you must have level 7 or higher!", player, 255, 0, 0, false ); 
        end 
    end 
end 
  
-- 
  
for _, vehicle in ipairs( pVehicles ) do 
    addEventHandler( "onVehicleStartEnter", vehicle, VehicleEnter ); 
end 

Edited by Guest
Link to comment

One way would be to use same indexes as in "pVehicles" table in another table with its respective colors.

Example:

local pColors = 
{ 
    [1] = { 255, 0, 0 }; 
} 
  
for i, model in ipairs( pVehicles ) do 
    setVehicleColor( model, unpack( pColors[i] ) ); 
end 

( This will set vehicle with index 1 at "pVehicle" table with the specified color in the table at index 1 in "pColors" )

Put this below "pVehicles" table.

Link to comment

like that?

function VehicleEnter( player, seat ) 
    if ( seat == 0 ) then 
        local nLevel = tonumber( getElementData( player, "level" ) ) or 0; 
        local accountName = getAccountName ( getPlayerAccount ( player ) ) 
        local gangName = exports.gangsystem:getAccountGang ( accountName ) 
        if not (gangName == "Army") then 
        if ( nLevel < 7 ) then 
            cancelEvent(); 
            outputChatBox( "This vehicle is locked to the Army lvl 7!", player, 255, 0, 0, false ); 
        end 
    end 
    end 
end 

Link to comment
like that?
function VehicleEnter( player, seat ) 
    if ( seat == 0 ) then 
        local nLevel = tonumber( getElementData( player, "level" ) ) or 0; 
        local accountName = getAccountName ( getPlayerAccount ( player ) ) 
        local gangName = exports.gangsystem:getAccountGang ( accountName ) 
        if not (gangName == "Army") then 
        if ( nLevel < 7 ) then 
            cancelEvent(); 
            outputChatBox( "This vehicle is locked to the Army lvl 7!", player, 255, 0, 0, false ); 
        end 
    end 
    end 
end 

Would not "getAccountGang" use account element and not account name? Is the gang system made by you or is it from community? If it's from community, you mind sending me link to check that?

Try this, anyway:

function VehicleEnter( player, seat ) 
    if ( seat == 0 ) then 
        local nLevel = tonumber( getElementData( player, "level" ) ) or 0; 
        local szGang = exports.gangsystem:getAccountGang( getAccountName( getPlayerAccount( player ) ) ); 
        if ( ( szGang ~= "Army" ) or ( szGang == "Army" and nLevel < 7 ) ) then 
            cancelEvent(); 
            outputChatBox( "This vehicle is locked to Army level 7!", player, 255, 0, 0, false ); 
        end 
    end 
end 

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