Jump to content

Checking Multiple cols to see if element is in it.


harryh

Recommended Posts

Now I have a different problem. How can I check if someone is in any of the cols. Here is what I current have. I have tried using a for loop

for _, value in pairs(wcols) do 

  
weed1 = createObject(3409, -1070.0712890625, -1621.3779296875, 75 ) 
wc1 = createColRectangle(-1071.9111328125, -1623.5166015625, 4, 4) 
weed2 = createObject(3409,  -1061.048828125, -1621.3779296875, 75 ) 
wc2 = createColRectangle(-1062.865234375, -1623.3974609375, 4, 4) 
weed3 = createObject(3409, -1061.048828125+9, -1621.3779296875, 75 ) 
wc3 = createColRectangle(-1053.984375, -1623.375, 4, 4) 
weed4 = createObject(3409, -1052.1123046875, -1631.681640625, 75 ) 
wc4 = createColRectangle(-1054.1328125, -1633.4208984375, 4, 4) 
weed5 = createObject(3409, -1052.1123046875-9, -1631.681640625, 75 ) 
wc5 = createColRectangle(-1063.2421875, -1633.6806640625, 4, 4) 
weed6 = createObject(3409, -1070.0712890625, -1631.681640625, 75 ) 
wc6 = createColRectangle(-1072.0537109375, -1633.6484375, 4, 4) 
wcols = { wc1, wc2, wc3, wc4, wc5, wc6 } 
  
function pickBud( thePlayer ) 
    if isElementWithinColShape(thePlayer, wcols) then 
        if ( getHarvested == 0) then 
            exports.global:sendLocalMeAction(element, "picks some bud.") 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick(thePlayer, thePlayer) 
            exports.global:giveItem(targetPlayer, 30, 0) 
            exports.global:giveItem(targetPlayer, 30, 0) 
        end 
    end 
end 
addCommandHandler("pickbud", pickBud) 

Also (SolidSnake as you gave me the code) I am unable to reset the weed.

function forceWeed () 
    setElementData ( wc1, "isHarvested", 0 ) 
    setElementData ( wc2, "isHarvested", 0 ) 
    setElementData ( wc3, "isHarvested", 0 ) 
    setElementData ( wc4, "isHarvested", 0 ) 
    setElementData ( wc5, "isHarvested", 0 ) 
    setElementData ( wc6, "isHarvested", 0 ) 
    outputChatBox("Weed Grown") 
end 
addCommandHandler("forceweed", forceWeed) 
  

Link to comment

Oh, I didn't notice you had a table, my bad.

function isPlayerInColshape ( thePlayer ) 
    local is = false 
    for _, col in ipairs ( wcols ) do 
        if isElement ( col ) then 
            if isElementWithinColShape ( thePlayer, col ) then 
                is = col 
                break 
            end 
        end 
    end 
  
    return is 
end 

Then you can replace your isElementWithinColShape with isPlayerInColshape.

Link to comment

Thanks SolidSnake, but you know the setElementData harvested you helped me with yesterday, I cannot find away to set it back as I do not know what element it was binded to.

function weedhit ( element, matchingDimension ) 
    if ( isElement ( element ) and matchingDimension and getElementType ( element ) == "player" ) then 
        thePlayer = getPlayerName(element) 
        if isPedInVehicle ( element ) then 
            local vehicle = getPedOccupiedVehicle ( element ) 
            local vehicleID = getElementModel ( vehicle ) 
            local getHarvested = getElementData ( source, "isHarvested" ) 
            if ( getHarvested == 1 ) then 
                outputChatBox("Weed has already been harvested!", element) 
            else 
                if ( vehicleID == 532 ) then 
                    setElementData ( source, "isHarvested", 1 ) 
                    harvestWeed ( thePlayer ) 
                else 
                    outputChatBox ( "You can't harvest with this vehicle!!", element ) 
                end 
            end 
        else 
            outputChatBox ( "/pickbud to pick the weed!", element ) 
        end 
    else 
        outputChatBox("Error!! Contact an Admin, F2", element ) 
    end 
end 
addEventHandler ( "onColShapeHit", getRootElement(), weedhit ) 

function forceWeed () 
    setElementData ( wc1, "isHarvested", 0 ) 
    setElementData ( wc2, "isHarvested", 0 ) 
    setElementData ( wc3, "isHarvested", 0 ) 
    setElementData ( wc4, "isHarvested", 0 ) 
    setElementData ( wc5, "isHarvested", 0 ) 
    setElementData ( wc6, "isHarvested", 0 ) 
    outputChatBox("Weed Grown") 
end 
addCommandHandler("forceweed", forceWeed) 
  

Link to comment

Doesn't work no errors.

function weedhit ( element, matchingDimension ) 
    if ( isElement ( element ) and matchingDimension and getElementType ( element ) == "player" ) then 
        thePlayer = getPlayerName(element) 
        if isPedInVehicle ( element ) then 
            local vehicle = getPedOccupiedVehicle ( element ) 
            local vehicleID = getElementModel ( vehicle ) 
            getHarvested = getElementData ( source, "isHarvested" ) 
            if ( getHarvested == 1 ) then 
                outputChatBox("Weed has already been harvested!", element) 
            else 
                if ( vehicleID == 532 ) then 
                    if ( getHarvested == 0 ) then 
                        setElementData ( source, "isHarvested", 1 ) 
                        harvestWeed ( thePlayer ) 
                        setTimer ( respawnWeed, 50, 1, source ) -- 300000 
                    else 
                        outputChatBox("Weed has already been harvested!", element) 
                        setTimer ( respawnWeed, 50, 1, source ) 
                    end 
                else 
                    outputChatBox ( "You can't harvest with this vehicle!!", element ) 
                end 
            end 
        else 
            outputChatBox ( "/pickbud to pick the weed!", element ) 
        end 
    else 
        outputChatBox("Error!! Contact an Admin, F2", element ) 
    end 
end 
addEventHandler ( "onColShapeHit", getResourceRootElement(), weedhit ) 

function respawnWeed ( col ) 
    if isElement ( col ) then 
        setElementData ( col, "isHarvested", 0 ) 
        outputChatBox("Weed Grown ") -- debug 
    end 
end 

Link to comment
You are passing the player name, not the element to harvestWeed function.

Yes but the timer isnt respawning the weed, the timer and respawn weed has nothing to do with harvestweed also the timer is not even in the harvest weed function. I have also manually spawned the weed by putting respawnWeed ( Source ) it works but the element data is not set.

function weedhit ( element, matchingDimension ) 
    if ( isElement ( element ) and matchingDimension and getElementType ( element ) == "player" ) then 
        thePlayer = getPlayerName(element) 
        if isPedInVehicle ( element ) then 
            local vehicle = getPedOccupiedVehicle ( element ) 
            local vehicleID = getElementModel ( vehicle ) 
            getHarvested = getElementData ( source, "isHarvested" ) 
            if ( getHarvested == 1 ) then 
                outputChatBox("Weed has already been harvested!", element) 
            else 
                if ( vehicleID == 532 ) then 
                    if ( getHarvested == 0 ) then 
                        setElementData ( source, "isHarvested", 1 ) 
                        harvestWeed ( thePlayer ) 
                        setTimer ( respawnWeed, 50, 1, source ) -- 300000 
                    else 
                        outputChatBox("Weed has already been harvested!", element) 
                        setTimer ( respawnWeed, 50, 1, source ) 
                    end 
                else 
                    outputChatBox ( "You can't harvest with this vehicle!!", element ) 
                end 
            end 
        else 
            outputChatBox ( "/pickbud to pick the weed!", element ) 
        end 
    else 
        outputChatBox("Error!! Contact an Admin, F2", element ) 
    end 
end 
addEventHandler ( "onColShapeHit", getResourceRootElement(), weedhit ) 

Edited by Guest
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...