harryh Posted April 27, 2014 Posted April 27, 2014 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)
Castillo Posted April 27, 2014 Posted April 27, 2014 To use a for-loop, you need a table, and you haven't got one.
harryh Posted April 27, 2014 Author Posted April 27, 2014 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.
harryh Posted April 27, 2014 Author Posted April 27, 2014 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
Castillo Posted April 27, 2014 Posted April 27, 2014 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.
harryh Posted April 27, 2014 Author Posted April 27, 2014 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)
harryh Posted April 27, 2014 Author Posted April 27, 2014 When do you want to reset the status? Ok a timer resWeed = setTimer ( respawnWeed, 300000, 1, source )
Castillo Posted April 27, 2014 Posted April 27, 2014 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 )
harryh Posted April 27, 2014 Author Posted April 27, 2014 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
harryh Posted April 27, 2014 Author Posted April 27, 2014 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.
Castillo Posted April 27, 2014 Posted April 27, 2014 You are passing the player name, not the element to harvestWeed function.
harryh Posted April 27, 2014 Author Posted April 27, 2014 (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 April 28, 2014 by Guest
harryh Posted April 28, 2014 Author Posted April 28, 2014 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
Castillo Posted April 28, 2014 Posted April 28, 2014 Loop the "wcols" table the same way I did in "isPlayerInColshape" function.
harryh Posted April 28, 2014 Author Posted April 28, 2014 Loop the "wcols" table the same way I did in "isPlayerInColshape" function. Thank you, you have taught me a lot
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now