Jump to content

Checking Multiple cols to see if element is in it.


harryh

Recommended Posts

Posted

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) 
  

Posted

To use a for-loop, you need a table, and you haven't got one.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
To use a for-loop, you need a table, and you haven't got one.

Ah Solid look at the code below the loop, thats what I used the loop for.

Posted

Any error in the debugscript?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Any error in the debugscript?

Expected element got table, or with

for k, val in pairs (wcols) do 

expected element is number. for index of were the colshape variable is in the table

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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) 
  

Posted

When do you want to reset the status?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
function respawnWeed ( col ) 
    if isElement ( col ) then 
        setElementData ( col, "isHarvested", 0 ) 
    end 
end 

Then after:

harvestWeed ( thePlayer ) 

You can put:

setTimer ( respawnWeed, 300000, 1, source ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

Posted

Does it output "Weed Grown"?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Does it output "Weed Grown"?

No that was why I assume its not working. Also it doesn't seem to let me harvest the weed after 5 seconds so its not working clearly.

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)
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
Posted

Move the timer before "harvestWeed".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Move the timer before "harvestWeed".

Thank you SolidSnake. But how can I set it so on the resource start It will setElementData for all cols not to be harvested.

I know I will need:

onResourceStart 
setElementData 

Posted

Loop the "wcols" table the same way I did in "isPlayerInColshape" function.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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