Zadara Posted August 10, 2009 Share Posted August 10, 2009 After ask some people at the IRC, what gives not much result. I ask it on the forums. The problem at the following script is that i go into the food shop markers of the ammu markers the addEventHandler for onMarkerHit doesn't work. Does anyone know why? Thanks, function onResStart() AMMU1 = createMarker(296.03073120117, -38.204479217529, 1000.515625, "cylinder", 1) AMMU2 = createMarker(289.80169677734, -109.62482452393, 1000.515625, "cylinder", 1) FDBURG1 = createMarker(375.91638183594, -67.679695129395, 1000.5151367188, "cylinder", 1) FDBURG2 = createMarker(375.91638183594, -67.679695129395, 1000.5151367188, "cylinder", 1) FDBURG3 = createMarker(375.91638183594, -67.679695129395, 1000.5151367188, "cylinder", 1) FDCHICK1 = createMarker(368.56079101563, -6.4645309448242, 1000.8515625, "cylinder", 1) FDCHICK2 = createMarker(368.56079101563, -6.4645309448242, 1000.8515625, "cylinder", 1) FDCHICK3 = createMarker(368.56079101563, -6.4645309448242, 1000.8515625, "cylinder", 1) FDPIZZA1 = createMarker(373.77386474609, -119.16807556152, 1000.4921875, "cylinder", 1) FDPIZZA2 = createMarker(373.77386474609, -119.16807556152, 1000.4921875, "cylinder", 1) setElementInterior(AMMU1, 1) setElementInterior(AMMU2, 6) setElementDimension(AMMU1, 1) setElementDimension(AMMU2, 5) setElementInterior(FDBURG1, 10) setElementInterior(FDBURG2, 10) setElementInterior(FDBURG3, 10) setElementDimension(FDBURG1, 2) setElementDimension(FDBURG2, 3) setElementDimension(FDBURG3, 4) setElementInterior(FDCHICK1, 9) setElementInterior(FDCHICK2, 9) setElementInterior(FDCHICK3, 9) setElementDimension(FDCHICK1, 2) setElementDimension(FDCHICK2, 6) setElementDimension(FDCHICK3, 7) setElementInterior(FDPIZZA1, 5) setElementInterior(FDPIZZA2, 5) setElementDimension(FDPIZZA1, 6) setElementDimension(FDPIZZA2, 7) ammuTable = {AMMU1, AMMU2} foodTable = {FDBURG1, FDBURG2, FDBURG3, FDCHICK1, FDCHICK2, FDCHICK3, FDPIZZA1, FDPIZZA2} for index, ammuMarker in next, ammuTable do addEventHandler("onMarkerHit", ammuMarker, onAmmuMarkerHit) end for index, foodMarker in next, foodTable do addEventHandler("onMarkerHit", foodMarker, onFoodMarkerHit) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onResStart) function onAmmuMarkerHit(hitPlayer, matchingDimension) outputChatBox("Buy your weapon!") end function onFoodMarkerHit(hitPlayer, matchingDimension) outputChatBox("Buy your food!") end Link to comment
DutchCaffeine Posted August 10, 2009 Share Posted August 10, 2009 for index, ammuMarker in next, ammuTable do addEventHandler("onMarkerHit", ammuMarker, onAmmuMarkerHit) end for index, foodMarker in next, foodTable do addEventHandler("onMarkerHit", foodMarker, onFoodMarkerHit) end Where is the variable 'next'? And put in all the for loops the next code: outputDebugString("Execuded for loop"); And do that allways in your code, it helps finding things you overlooked! Link to comment
50p Posted August 10, 2009 Share Posted August 10, 2009 ...Where is the variable 'next'? ...! It's not a variable. It's an iterator function that is used in pairs() function. You can do either, for key, value in next, tab do or for key, value in pairs( tab ) do This should work: -- ... Your code above addEventHandler( "onMarkerHit", getRootElement(), function( ) for k,marker in pairs( foodTable ) do -- go through all food markers if source == marker then -- and find out if hit marker (source) is one of markers in foodTable -- OK, you hit a food marker break; -- break the loop because you found what you wanted... end end end ) Link to comment
eAi Posted August 10, 2009 Share Posted August 10, 2009 And sorry to be repetitive, but you'll find it easier long-term if you specify markers (and any other elements) in a map file. You can then use the map editor and everything is generally much better! Link to comment
Zadara Posted August 10, 2009 Author Share Posted August 10, 2009 And sorry to be repetitive, but you'll find it easier long-term if you specify markers (and any other elements) in a map file. You can then use the map editor and everything is generally much better! How do you mean? I don't get it... Link to comment
50p Posted August 10, 2009 Share Posted August 10, 2009 And sorry to be repetitive, but you'll find it easier long-term if you specify markers (and any other elements) in a map file. You can then use the map editor and everything is generally much better! How do you mean? I don't get it... He's trying to tell you to use the map files instead of creating markers inside your script. http://development.mtasa.com/index.php? ... ement_tree http://development.mtasa.com/index.php? ... ment_Types Link to comment
Zadara Posted August 11, 2009 Author Share Posted August 11, 2009 And sorry to be repetitive, but you'll find it easier long-term if you specify markers (and any other elements) in a map file. You can then use the map editor and everything is generally much better! How do you mean? I don't get it... He's trying to tell you to use the map files instead of creating markers inside your script. http://development.mtasa.com/index.php? ... ement_tree http://development.mtasa.com/index.php? ... ment_Types How can i get elements that are in a .map file into a table then? Link to comment
Lordy Posted August 11, 2009 Share Posted August 11, 2009 getElementsByType(elementType,getResourceMapRootElement(getThisResource(),mapName)) Will get exactly the wanted elements in specified map file, usually just getElementsByType(elementType,getResourceRootElement(getThisResource())) works too Link to comment
eAi Posted August 13, 2009 Share Posted August 13, 2009 Although it is useful not to limit yourself to just your own resource - that allows other people to extend your code easily. Link to comment
Zadara Posted August 13, 2009 Author Share Posted August 13, 2009 Although it is useful not to limit yourself to just your own resource - that allows other people to extend your code easily. Its not gonna be a open script, its for a pretty big server... And its easy to figure out, where where is. 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