Jump to content

Problem with getElementModel


Junim

Recommended Posts

Posted

Hi guys, i have a problem with this code: 

---------------------------------------------------------------------------------------------------------------------------------------------------------

function JoinVehicleCar (player, seat)
    
    local acc = getAccountName(getPlayerAccount(player))    
    if seat == 0 then
    
        if (getElementModel(player) == "Automobile" or "Bike") then
            if not (isObjectInACLGroup("user."..acc, aclGetGroup("HABCARMOTO"))) then
                cancelEvent()
                return outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!",player,255,255,255, true)
            end
        end    
        
        if (getElementModel(player) == "Helicopter" or "Plane") then
        
            if not (isObjectInACLGroup("user."..acc, aclGetGroup("HABAERO"))) then
                cancelEvent()
                return outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!",player,255,255,255, true)
            end
        end
        
        if (getElementModel(player) == "Boat") then
        
            if not (isObjectInACLGroup("user."..acc, aclGetGroup("HABBOAT"))) then
                cancelEvent()
                return outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!",player,255,255,255, true)
            end
        end    
    
    end
end
addEventHandler("onVehicleStartEnter",root,JoinVehicleCar) 

-------------------------------------------------------------------------------------------------------------------------

The problem is:

When I am inside an ACL for example "HABCARMOTO" that would be only car and motorcycle, I can get into planes and boats too and I did not want this. And when I enter the ACL "HABAERO" or "HABBOAT" I can not get into any vehicle, why does this happen?

 

SORRY MY ENGLISH, I AM FROM BRAZIL!

 

 

Posted

This cancel the event when the player join in car. I take and continue with problem! But the player join the car same with mensage saying "you can't join the car"

Posted (edited)
function JoinVehicleCar (player, seat)
    
    local acc = getAccountName(getPlayerAccount(player))    
    if seat == 0 then
    
        if (getVehicleType(source) == "Automobile" or getVehicleType(source) == "Bike") then
            if not (isObjectInACLGroup("user."..acc, aclGetGroup("HABCARMOTO"))) then
                cancelEvent()
                return outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!",player,255,255,255, true)
            end
        end    
        
        if (getVehicleType(source) == "Helicopter" or getVehicleType(source) == "Plane") then
        
            if not (isObjectInACLGroup("user."..acc, aclGetGroup("HABAERO"))) then
                cancelEvent()
                return outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!",player,255,255,255, true)
            end
        end
        
        if (getVehicleType(source) == "Boat") then
        
            if not (isObjectInACLGroup("user."..acc, aclGetGroup("HABBOAT"))) then
                cancelEvent()
                return outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!",player,255,255,255, true)
            end
        end    
    
    end
end
addEventHandler("onVehicleStartEnter",root,JoinVehicleCar)

 

Edited by IRBIS
Posted

That script doesn't make much sense where you compare the vehicle type. You're also repeating a lot of code, which isn't good.

Try this. Not tested.

function JoinVehicleCar(player, seat)
	if (seat == 0) then
		local accountName = getAccountName(getPlayerAccount(player))
		local hasAccess = true

		if (getVehicleType(source) == "Automobile") or (getVehicleType(source) == "Bike") then
			hasAccess = accountName and isObjectInACLGroup("user." .. accountName, aclGetGroup("HABCARMOTO"))
		elseif (getVehicleType(source) == "Helicopter") or (getVehicleType(source) == "Plane") then
			hasAccess = accountName and isObjectInACLGroup("user." .. accountName, aclGetGroup("HABAERO"))
		elseif (getVehicleType(source) == "Boat") then
			hasAccess = accountName and isObjectInACLGroup("user." .. accountName, aclGetGroup("HABBOAT"))
		end    

		if (not hasAccess) then
			cancelEvent()
			outputChatBox("#000000[ #FFFF00CNH#000000 ] #FFFFFFVocê não possui  #ff0000Habilitação #ffffff para conduzir este veiculo!", player, 255, 255, 255, true)
		end
	end
end
addEventHandler("onVehicleStartEnter", root, JoinVehicleCar)

 

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