MatXpl Posted April 16, 2012 Share Posted April 16, 2012 local redArea1 = createColRectangle (...) local redArea2 = createColRectangle (...) local redArea3 = createColRectangle (...) local greenArea1 = createColRectangle (...) local greenArea2 = createColRectangle (...) local greenArea3 = createColRectangle (...) and i wanna to group this.. i need this to use in onColShapeHit events: function hitRed() ... end addEventHandler ( "onColShapeHit", WHAT HERE?, hitRed ) function hitGreen() ... end addEventHandler ( "onColShapeHit", WHAT HERE?, hitGreen ) Tabeles ? Link to comment
Sparrow Posted April 16, 2012 Share Posted April 16, 2012 function hitRed() if (source == redArea1 or source == redArea2 or source == redArea3) then ... end end addEventHandler ( "onColShapeHit", root, hitRed ) function hitGreen() if (source == greenArea1 or source == greenArea2 or source == greenArea3) then ... end end addEventHandler ( "onColShapeHit", root, hitGreen ) I set 'root' on 'WHAT HERE?' because I did 'if source == area then Link to comment
MatXpl Posted April 16, 2012 Author Share Posted April 16, 2012 oohhh... that's right, I had not thought about it. thanks! Link to comment
drk Posted April 16, 2012 Share Posted April 16, 2012 (edited) local rAreas = { }; local gAreas = { }; local tRedAreas = { { fX = 200, fY = 100, fWidth = 500, fHeight = 500 }; { fX = 300, fY = 50, fWidth = 250, fHeight = 300 }; } local tGreenAreas = { { fX = 200, fY = 100, fWidth = 500, fHeight = 500 }; { fX = 300, fY = 50, fWidth = 250, fHeight = 300 }; } for _, rArea in pairs ( tRedAreas ) do rAreas[_] = createColRectangle ( rArea.fX, rArea.fY, rArea.fwidth, rArea.fHeight ); addEventHandler ( 'onColShapeHit', rAreas[_], onRectangleHit ); addEventHandler ( 'onColShapeLeave', rAreas[_], onRectangleLeave ); end for _, gArea in pairs ( tGreenAreas ) do gAreas[_] = createColRectangle ( gArea.fX, gArea.fY, gArea.fWidth, gArea.fHeight ); addEventHandler ( 'onColShapeHit', gAreas[_], onRectangleHit ); addEventHandler ( 'onColShapeLeave', gAreas[_], onRectangleLeave ); end onRectangleHit = function ( uPlayer ) outputChatBox ( getPlayerName ( uPlayer ) .. ' entered the ColShape!', root, 255, 255, 255, false ); end onRectangleLeave = function ( uPlayer ) outputChatBox ( getPlayerName ( uPlayer ) .. ' left the ColShape!', root, 255, 255, 255, false ); end Edited April 16, 2012 by Guest Link to comment
Aibo Posted April 16, 2012 Share Posted April 16, 2012 DrakeN youre adding event handlers before handler functions are even defined. Link to comment
drk Posted April 16, 2012 Share Posted April 16, 2012 That's not a problem, it works. Link to comment
qaisjp Posted April 16, 2012 Share Posted April 16, 2012 local areas = { ['red'] = { {200, 100, 500, 500} {300,50, 250, 300} { ['green'] = { {200, 100, 500, 500 } {300, 50, 250, 300 } } } function onRectangleHit( pl ) outputChatBox ( getPlayerName (pl) .. ' entered the ColShape!', root, 255, 255, 255, false) end function onRectangleLeave(pl) outputChatBox ( getPlayerName (pl) .. ' left the ColShape!', root, 255, 255, 255, false) end for area, part in pairs ( areas ) do for i,rArea in ipairs(part) do areas[area] = createColRectangle ( unpack(values) ); addEventHandler ( 'onColShapeHit', areas[area][i], onRectangleHit ); addEventHandler ( 'onColShapeLeave', areas[area][i], onRectangleLeave ); end end better, correct code. aibo is right. Link to comment
drk Posted April 16, 2012 Share Posted April 16, 2012 You're wrong and Aibo too First, in your code, values is nil. And Aibo, I tested it some times. You don't need create functions first, believe me. I can show the part of my GangWar where I add handlers first and then functions and work. Link to comment
Castillo Posted April 16, 2012 Share Posted April 16, 2012 Oh, really? [2012-04-16 18:04:09] WARNING: 124: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] [2012-04-16 18:04:09] WARNING: 125: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] [2012-04-16 18:04:09] WARNING: 123: Bad argument @ 'createColPolygon' [2012-04-16 18:04:09] WARNING: 124: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] [2012-04-16 18:04:09] WARNING: 125: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] [2012-04-16 18:04:09] WARNING: 130: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil] [2012-04-16 18:04:09] WARNING: 131: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] [2012-04-16 18:04:09] WARNING: 130: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil] [2012-04-16 18:04:09] WARNING: 131: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] local rAreas = { }; local gAreas = { }; local tRedAreas = { { fX = 200, fY = 100, fWidth = 500, fHeight = 500 }; { fX = 300, fY = 50, fWidth = 250, fHeight = 300 }; } local tGreenAreas = { { fX = 200, fY = 100, fWidth = 500, fHeight = 500 }; { fX = 300, fY = 50, fWidth = 250, fHeight = 300 }; } addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, rArea in ipairs ( tRedAreas ) do rAreas[_] = createColRectangle ( rArea.fX, rArea.fY, rArea.fWidth, rArea.fHeight ); addEventHandler ( 'onColShapeHit', rAreas[_], onRectangleHit ); addEventHandler ( 'onColShapeLeave', rAreas[_], onRectangleLeave ); end for _, gArea in ipairs ( tGreenAreas ) do gAreas[_] = createColRectangle ( gArea.fX, gArea.fY, gArea.fWidth, gArea.fHeight ); addEventHandler ( 'onColShapeHit', gAreas[_], onRectangleHit ); addEventHandler ( 'onColShapeLeave', gAreas[_], onRectangleLeave ); end end ) onRectangleHit = function ( uPlayer ) outputChatBox ( getPlayerName ( uPlayer ) .. ' entered the ColShape!', root, 255, 255, 255, false ); end onRectangleLeave = function ( uPlayer ) outputChatBox ( getPlayerName ( uPlayer ) .. ' left the ColShape!', root, 255, 255, 255, false ); end You had many errors in your code, Draken. 1: Your table contained strings, not numbers. 2: You had "rAreas" instead of "gAreas" in the second loop. Do you even test what you post? because you're not helping if you don't. Link to comment
drk Posted April 16, 2012 Share Posted April 16, 2012 (edited) First, why don't you stop calling others "KID" when you're one, Solidsnaka? Second, I forgot "Your table contained strings, not numbers.", what the problem? You never missed something? Third, "You had "rAreas" instead of "gAreas" in the second loop." LOL? Fourth, You don't need the fucking onClientResourceStart event. Edited April 16, 2012 by Guest Link to comment
Castillo Posted April 16, 2012 Share Posted April 16, 2012 1: I never called anyone "kid". 2: I'd, but I test many times the script before posting it here. 3: You'd, you can check your original code. 4: Is "onResourceStart", not "onClientResourceStart". If you don't use this, then you have to declare the functions before adding the events. Link to comment
drk Posted April 16, 2012 Share Posted April 16, 2012 (edited) Are you sure you never called? You must pay more attention in what you say ^^ I can't test scripts in my machine because it sucks and if you have missed something already, why don't you just shut up? And maybe I have somethings wrong because I made it fast, I said it's correct? Edited April 16, 2012 by Guest Link to comment
Castillo Posted April 16, 2012 Share Posted April 16, 2012 I'm not going to argue with you, it would be a waste of time. Link to comment
drk Posted April 16, 2012 Share Posted April 16, 2012 You don't like "Are you sure you never called? You must pay more attention in what you say ^^" ?? If not, why when I say something about, you say the same "I don't want to argue with you" ?? Anyway, I will not lost my time with you, it's a waste. Link to comment
Aibo Posted April 17, 2012 Share Posted April 17, 2012 And Aibo, I tested it some times. You don't need create functions first, believe me. I can show the part of my GangWar where I add handlers first and then functions and work. you should've learned some programming logic instead of semicolons and type prefixes in a dynamically-typed language. think whatever you like, but dont confuse other people into thinking they can pass nil values and "add function there later". also if you and SolidSnake14 are going to argue who called who what, please do that in PM. Link to comment
Kenix Posted April 17, 2012 Share Posted April 17, 2012 local tTempAreas = { tRedAreas = { }; tGreenAreas = { }; } local tAllAreas = { tRedAreas = { { nX = 300, nY = 50, nWidth = 50, nHeight = 50 }; }; tGreenAreas = { { nX = 200, nY = 100, nWidth = 50, nHeight = 50 }; }; } local fOnRectangleHit = function ( uPlayer ) outputChatBox ( getPlayerName ( uPlayer ) .. ' entered the ColShape!', root, 255, 255, 255 ) end local fOnRectangleLeave = function ( uPlayer ) outputChatBox ( getPlayerName ( uPlayer ) .. ' left the ColShape!', root, 255, 255, 255 ) end addEventHandler ( 'onResourceStart', resourceRoot, function ( ) for sName, tArea in pairs( tAllAreas ) do for _, tValue in pairs( tArea ) do tTempAreas[ sName ][ #tTempAreas[ sName ] + 1 ] = createColRectangle ( tValue.nX, tValue.nY, tValue.nWidth, tValue.nHeight ) addEventHandler ( 'onColShapeHit', tTempAreas[ sName ][ #tTempAreas[ sName ] ], fOnRectangleHit ) addEventHandler ( 'onColShapeLeave', tTempAreas[ sName ][ #tTempAreas[ sName ] ], fOnRectangleLeave ) end end end ) Link to comment
qaisjp Posted April 17, 2012 Share Posted April 17, 2012 and my less-redundant code disappeared in the fight. draken, adding semicolons and prefixes doesnt prove anything, nor does your x*1000 posts. 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