Jump to content

Doesn't work if player in vehicle


harryh

Recommended Posts

Well, the idea here is that if the player is in a vehicle it executes the harvestWeed function and if he is not it tells him to /pickbud. But when the player is in a vehicle it says /pickbud. I do not understand why.

Code:

function weedhit( element, matchingDimension ) 
    if (isElement(element)) and (getElementType(element)=="vehicle") and (matchingDimension) then 
        local thePlayer = getVehicleOccupant(element) 
        local vehName = getVehicleName(element) 
        local vehicleID = getVehicleModelFromName(vehName) 
        if (vehicleID==532) then 
            harvestWeed() 
        else 
            outputChatBox("You can't harvest with this vehicle!!", thePlayer) 
        end 
    elseif (isElement(element)) and (matchingDimension) and not (getElementType(element)=="vehicle") then  
        outputChatBox("/pickbud to pick the weed!", thePlayer) 
    else 
        outputChatBox("Error!! Contact an Admin, F2", thePlayer) 
    end 
end 
addEventHandler ( "onColShapeHit", getRootElement(), weedhit ) 

Link to comment
function weedhit ( element, matchingDimension ) 
    if ( isElement ( element ) and matchingDimension and getElementType ( element ) == "player" ) then 
        if isPedInVehicle ( element ) then 
            local vehicle = getPedOccupiedVehicle ( element ) 
            local vehicleID = getElementModel ( vehicle ) 
            if ( vehicleID == 532 ) then 
                harvestWeed ( ) 
            else 
                outputChatBox ( "You can't harvest with this vehicle!!", element ) 
            end 
        else 
            outputChatBox ( "/pickbud to pick the weed!", element ) 
        end 
    else 
        outputChatBox("Error!! Contact an Admin, F2", element ) 
    end 
end 
addEventHandler ( "onColShapeHit", getRootElement(), weedhit ) 

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