harryh Posted April 26, 2014 Share Posted April 26, 2014 I cannot seem to get the colshape variable name and assign it to setElementData. What I am trying to do is set the the colshape to harvested(true) so when you go back though that colshape it says "this has already been harvested". So basically if I harvest colshape wc, so I can still harvest colshape wc2. wc = colshape blah wc2 = colshape blah getHarvested = getElementData( element, "isHarvested" ) if (getHarvested == true ) then outputChatBox("Weed has already been harvested!", element) else if ( vehicleID == 532 ) then outputChatBox( tostring( getHarvested ) ) --debug harvestWeed ( ) sHar = setElementData( getElementColShape ( element ), "isHarvested", true) Link to comment
Castillo Posted April 26, 2014 Share Posted April 26, 2014 I don't really get it, mind posting the full script? Link to comment
harryh Posted April 26, 2014 Author Share Posted April 26, 2014 I don't really get it, mind posting the full script? 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) 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( element, "isHarvested" ) if (getHarvested == 1 ) then outputChatBox("Weed has already been harvested!", element) else if ( vehicleID == 532 ) then outputChatBox( tostring( getHarvested ) ) harvestWeed ( thePlayer ) sHar = setElementData( getElementColShape ( element ), "isHarvested", 1) 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 ) Link to comment
Castillo Posted April 26, 2014 Share Posted April 26, 2014 "element" is the player that hit the colshape, not the colshape. Link to comment
harryh Posted April 26, 2014 Author Share Posted April 26, 2014 (edited) "element" is the player that hit the colshape, not the colshape. Oh yeah woops. wrong code. Do you know how I would be able to set the setElementData to the colshape so if they go in it again it cannot be harvested? What I want to do is to assign setElementData to the colshape so if the player tries to harvest from the say colshape again it will say its already harvested. 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( getElementColShape ( element ), "isHarvested" ) if (getHarvested == 1 ) then outputChatBox("Weed has already been harvested!", element) else if ( vehicleID == 532 ) then outputChatBox( tostring( getHarvested ) ) harvestWeed ( thePlayer ) sHar = setElementData( getElementColShape ( element ), "isHarvested", 1) 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 ) Edited April 26, 2014 by Guest Link to comment
Castillo Posted April 26, 2014 Share Posted April 26, 2014 Are you setting the element data when it gets harvested? post "harvestWeed" function code. Link to comment
harryh Posted April 26, 2014 Author Share Posted April 26, 2014 Are you setting the element data when it gets harvested? post "harvestWeed" function code. function harvestWeed( thePlayer ) local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick(thePlayer, thePlayer) exports.global:giveItem(targetPlayer, 30, 0) exports.global:giveItem(targetPlayer, 30, 0) exports.global:giveItem(targetPlayer, 30, 0) exports.global:giveItem(targetPlayer, 30, 0) end Link to comment
harryh Posted April 26, 2014 Author Share Posted April 26, 2014 (edited) So say when you harvest colshape 1 you can still harvest colshape 2,6 but not 1 as setElementData to the colshape stopping it being harvested, it says expected element for boolean. so basically trying to get the colshape that the player is in and setting that colshape to harvested Edited April 26, 2014 by Guest Link to comment
Castillo Posted April 26, 2014 Share Posted April 26, 2014 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 ) Link to comment
harryh Posted April 26, 2014 Author Share Posted April 26, 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 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
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