Jump to content

is creating colshape like this is safe ?


smw94

Recommended Posts

is creating colshape like this is safe ? it's working perfectly on my server, but after a few hours after my server start, all of colshape element in my server get error, isElementWithinColShape error expected colshape at argument 2, then OnColShapeHit and OnColShapeLeave isn't triggerd anymore, its just like, all colshape in my server just disappear, all of them.

but when i stop this resource, the colshape is normal again, thanks before, i'd appreciate anyone you help solving this.

here is the script :

  
function addTurf(id,x,y,z,sizeX,sizeY,red,green,blue,owner) 
    -- Load all turfs 
    if not owner then 
        owner = 0 
    end 
    local colCuboid = createColCuboid( x, y, z-30, sizeX, sizeY, z+30 ) 
    local radArea = createRadarArea( x, y, sizeX, sizeY, red, green, blue, 130 ) 
     
    addEventHandler( "onColShapeHit", colCuboid, onTurfEnter ) 
    addEventHandler( "onColShapeLeave", colCuboid, onTurfLeave ) 
    setElementData( colCuboid, "owner", owner ) 
    setElementData( radArea, "owner", owner ) 
    setElementData( colCuboid, "turfId", id ) 
    setElementData( radArea, "turfId", id ) 
    setElementData( radArea, "posx", x ) 
    setElementData( radArea, "posy", y ) 
    setElementData( colCuboid, "posx", x ) 
    setElementData( colCuboid, "posy", y ) 
    setElementData( colCuboid, "area", radArea ) 
end 

Link to comment

You should store your turfs in an table. And whenever 'onColShapeHit' gets triggered, look if it is in the table. another way you can check it is to see if it as the element 'turfId'. Would also solve your problem. :)

edit; I would do it like this;

function addTurf ( id, x, y, z, sizeX, sizeY, r, g, b, owner ) 
    if ( not owner ) then 
        owner = 0; 
    end 
     
    local col = createColCuboid ( x, y, z - 30, sizeX, sizeY, z + 30 ); 
    local rArea = createRadarArea ( x, y, sizeX, sizeY, r, g, b, 130 ); 
     
    setElementData ( col, "owner", owner ); 
    setElementData ( col, "turfId", id ); 
    setElementData ( col, "posx", x ); 
    setElementData ( col, "posy", y ); 
    setElementData ( col, "areaObj", rArea ); 
end 
  
addEventHandler ( "onColShapeHit", root, 
    function () 
        if ( getElementData ( source, "turfId" ) ) then 
            -- onTurfEnter() 
        end 
    end 
); 
  
addEventHandler ( "onColShapeLeave", root, 
    function () 
        if ( getElementData ( source, "turfId" ) ) then 
            -- onTurfLeave() 
        end 
    end 
); 

Can you tell me, why did you add double values? Both on the colshape and radararea.

setElementData( colCuboid, "owner", owner ) 
setElementData( colCuboid, "turfId", id ) 
setElementData( colCuboid, "posx", x ) 
setElementData( colCuboid, "posy", y ) 
setElementData( colCuboid, "area", radArea ) 
  
setElementData( radArea, "turfId", id ) 
setElementData( radArea, "posx", x ) 
setElementData( radArea, "posy", y ) 
setElementData( radArea, "owner", owner ) 

Quite overrated because you already linked the radArea ( in your code ) to the colshape so you can retrieve its data from there. :)

Link to comment

thanks for your help, if you dont mind, i'd very appreciated if you want to give some example how to store the area location into tables, and cmiiw, if i store it to table, then i need too loop all over table to add oncolshapehit for each area right ?

oh because i dont know how to get area value of the col :D, so i added double values, i think i much easier to get element value of each col and area ..

Link to comment
thanks for your help, if you dont mind, i'd very appreciated if you want to give some example how to store the area location into tables, and cmiiw, if i store it to table, then i need too loop all over table to add oncolshapehit for each area right ?

oh because i dont know how to get area value of the col :D, so i added double values, i think i much easier to get element value of each col and area ..

on my way you can just get the object like this;

local radarArea = getElementData ( source, "areaObj" ); 
getElementData ( radarArea, "turfId" ); -- etc 

Using a table can be done on an easy way too, check this magical moment out;

local tblTurfs = { }; 
  
function addTurf ( id, x, y, z, sizeX, sizeY, r, g, b, owner ) 
    if ( not owner ) then 
        owner = 0; 
    end 
  
    local col = createColCuboid ( x, y, z - 30, sizeX, sizeY, z + 30 ); 
    local rArea = createRadarArea ( x, y, sizeX, sizeY, r, g, b, 130 ); 
     
    tblTurfs [ col ] = col; -- storing it in the table 
     
    setElementData ( col, "owner", owner ); 
    setElementData ( col, "turfId", id ); 
    setElementData ( col, "posx", x ); 
    setElementData ( col, "posy", y ); 
    setElementData ( col, "areaObj", rArea ); 
end 
  
addEventHandler ( "onColShapeHit", root, 
    function () 
        if ( tblTurfs [ source ] ) then -- checking if it's in your table 
            -- onTurfEnter() 
        end 
    end 
); 
  
addEventHandler ( "onColShapeLeave", root, 
    function () 
        if ( tblTurfs [ source ] ) then -- checking if it's in your table 
            -- onTurfLeave() 
        end 
    end 
); 

Link to comment

on my way you can just get the object like this;

local radarArea = getElementData ( source, "areaObj" ); 
getElementData ( radarArea, "turfId" ); -- etc 

Using a table can be done on an easy way too, check this magical moment out;

local tblTurfs = { }; 
  
function addTurf ( id, x, y, z, sizeX, sizeY, r, g, b, owner ) 
    if ( not owner ) then 
        owner = 0; 
    end 
  
    local col = createColCuboid ( x, y, z - 30, sizeX, sizeY, z + 30 ); 
    local rArea = createRadarArea ( x, y, sizeX, sizeY, r, g, b, 130 ); 
     
    tblTurfs [ col ] = col; -- storing it in the table 
     
    setElementData ( col, "owner", owner ); 
    setElementData ( col, "turfId", id ); 
    setElementData ( col, "posx", x ); 
    setElementData ( col, "posy", y ); 
    setElementData ( col, "areaObj", rArea ); 
end 
  
addEventHandler ( "onColShapeHit", root, 
    function () 
        if ( tblTurfs [ source ] ) then -- checking if it's in your table 
            -- onTurfEnter() 
        end 
    end 
); 
  
addEventHandler ( "onColShapeLeave", root, 
    function () 
        if ( tblTurfs [ source ] ) then -- checking if it's in your table 
            -- onTurfLeave() 
        end 
    end 
); 

okay, thanks for your help, i got it now :)

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