Jump to content

onColShapeHit


MatXpl

Recommended Posts

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
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
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 by Guest
Link to comment
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

You're wrong and Aibo too xD

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

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

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 by Guest
Link to comment

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

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 by Guest
Link to comment

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

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