Jump to content

Vehicle locked for class Help?


Bean666

Recommended Posts

Posted (edited)

hi guys . please help i have class as Admin but it wont work. i still cant enter the locked vehicle even i have the class as Admin. any help? and all vehicles shows the msg.

function cars () 
        c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
    end 
      
    addEventHandler ( "onResourceStart", resourceRoot, cars ) 
      
    function onEnter(thePlayer) 
        if getElementData(source, "class") ~= "Admin" then 
            cancelEvent() 
            outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        end 
    end 
      
    addEventHandler("onVehicleStartEnter", getRootElement(), onEnter) 

Edited by Guest
Posted
function cars () 
        c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
    end 
      
    addEventHandler ( "onResourceStart", resourceRoot, cars ) 
      
    function onEnter(thePlayer) 
        if getElementData(thePlayer, "class") ~= "Admin" then 
            cancelEvent() 
            outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        end 
    end 
      
    addEventHandler("onVehicleStartEnter", getRootElement(), onEnter) 

Posted (edited)
  
        c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
  
  
function onEnter(thePlayer) 
        if getElementModel(source) == 520 and getElementData(thePlayer, "class") ~= "Admin" then 
            cancelEvent() 
            outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        end 
    end 
      
    addEventHandler("onVehicleStartEnter", getRootElement, onEnter) 

EDIT:

function data (plr) 
        if getElementData(plr, "class") ~="Admin" then 
        setElementData(plr, "class", "Admin") 
        outputChatBox("Your class data is: "..getElementData(plr, "class"), plr) 
    else 
        setElementData(plr, "class", "Nope") 
        outputChatBox("Your class data is: "..getElementData(plr, "class"), plr) 
    end 
end 
    addCommandHandler("class", data) 

Use this function to add/remove you and check your data so you can be sure whether your data is "Admin" or whatever.

Edited by Guest
Posted (edited)

Check the code again. You wouldn't have to use a function for creating a vehicle in this resource. The second code (EDIT one) is a function that removes/adds and shows the data, and I guess you've just copied that code which is why the vehicle wasn't created.

Edited by Guest
Posted

There was ')' missing in the code in the line 13.

function cars () 
        c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
    end 
addEventHandler("onResourceStart", root, cars)  
  
function onEnter(thePlayer) 
        if getElementModel(source) == 520 and getElementData(thePlayer, "class") ~= "Admin" then 
            cancelEvent() 
            outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        end 
    end 
      
    addEventHandler("onVehicleStartEnter", getRootElement(Sr)) 

Posted

35614b26ba.png

you don't need to check the vehicle model it can be like this

if source == c1 then 

we know all that the source of this event (onVehicleStartEnter) is the vehicle in which a player began to enter.

Posted
i need for class not skin

you can do the same thing just change skins with getElementData.

tried ur code using skins , didnt even work it was accessible to all skins.

Posted

Try this

function cars () 
    c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
    addEventHandler("onVehicleStartEnter", c1, onEnter) 
end 
addEventHandler ( "onResourceStart", resourceRoot, cars ) 
      
function onEnter(thePlayer) 
    if not isPlayerAdmin(thePlayer) then 
        outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        cancelEvent()      
    end 
end 
      
     
function isPlayerAdmin(plr) 
    if not isElement(plr) then return end  
        if (getElementData(plr,"class") == "Admin") then  
        return true 
    else 
        return false 
    end  
end  

Posted
function cars () 
    c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, cars ) 
  
function onEnter(thePlayer) 
    if getElementModel(thePlayer) == 520 and getElementData(thePlayer, "class") ~= "Admin" then 
        outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        cancelEvent() 
    end 
end 
addEventHandler("onVehicleStartEnter", root, onEnter) 

Posted
when i'm in admin class , it is still locked.

bro try this and tell me what you can see in chatbox.

function checkClass(player) 
    if not isElement(player) then return end  
      local class = getElementData(player,"class") 
       if class then  
         outputChatBox("You current calss is : "..class,player,255,0,0) 
      end  
end  
addCommandHandler("class",checkClass) 

Posted
function cars () 
    c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, cars ) 
  
function onEnter(thePlayer) 
    if getElementModel(thePlayer) == 520 and getElementData(thePlayer, "class") ~= "Admin" then 
        outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        cancelEvent() 
    end 
end 
addEventHandler("onVehicleStartEnter", root, onEnter) 

anyone can ride it.

Posted

@Walid it shows Squads , but in TAB , my team is squads... and my class is Alpha Team

i'm using Castillo's Spawn panel that we bought before.

Posted (edited)
@Walid it shows Squads , but in TAB , my team is squads... and my class is Alpha Team

Try this type T/admin in chatBox then try to enter the vehicle

  
function cars () 
    c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
    addEventHandler("onVehicleStartEnter", c1, onEnter) 
end 
addEventHandler ( "onResourceStart", resourceRoot, cars ) 
      
function onEnter(thePlayer) 
    if not isPlayerAdmin(thePlayer) then 
        outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        cancelEvent()     
    end 
end 
      
function isPlayerAdmin(plr) 
    if not isElement(plr) then return end 
        if (getElementData(plr,"class") == "Admin") then 
        return true 
    else 
        return false 
    end 
end 
  

Edited by Guest
Posted
wait.

edit:

doesnt work.

Try this i already tried it it's working fine without typing t/admin

function cars () 
    c1 = createVehicle ( 520, -2891.84765625, 460.4560546875, 4.9140625, 0, 0, 90 ) 
    addEventHandler("onVehicleStartEnter", c1, onEnter) 
end 
addEventHandler ( "onResourceStart", resourceRoot, cars ) 
      
function onEnter(thePlayer) 
    if not isPlayerAdmin(thePlayer) then 
        outputChatBox("This Vehicle Is Locked for the Class:Admin", thePlayer, 0, 255, 0) 
        cancelEvent()     
    end 
end 
      
function isPlayerAdmin(plr) 
    if not isElement(plr) then return end 
        if (getElementData(plr,"class") == "Admin") then 
        return true 
    else 
        return false 
    end 
end 
  
function setMyClassTo (player) 
  if not isElement(player) then return end 
     local class = "Admin" 
       setElementData(player,"class",tostring(class)) 
end 
addCommandHandler("admin",setMyClassTo) 

Note: your class must be different to Admin

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