Jump to content

Help - Unpack


manve1

Recommended Posts

I tried using unpack function for createObject and when i use the unpack function for marker it work, but it doesn't for createObject, so i need help to know how to make it:

local lol =  
{ 
    { 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 } 
} 
  
local s = createObject(unpack(lol)) 

Link to comment

You can save object elements in a table and get their position with getElementPosition.

E.g.

local pObjects = {}; 
local pTable = 
{ 
    { 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 }; 
}; 
  
for key, value in ipairs( pTable ) do 
    pObjects[key] = createObject( unpack( value ) ); 
end 
  
-- 
  
local string = string.format( "Object's X: %d, Y: %d, Z: %d", getElementPosition( pObjects[1] ) ); 
outputChatBox( string, root, 255, 255, 255, false ); 

An easier way is: create the object inside the table.

local pTable = 
{ 
    createObject( 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 ); 
}; 

Link to comment

alright, it worked, it might have been my mistake, but how can i attach a collision shape to an specific object?

local collision = createColCuboid( 2493.25, -1675.25, 12.335947036743, 1.25, 2, 1 ) 
local string = string.format( "Object's X: %d, Y: %d, Z: %d", getElementPosition( present[1] ) ); 
attachElements( collision, present ) 

Link to comment

Well, I want to make like from a table objects and i need them to have separate col shape, so when player hits it some stuff happens, but the problem is that when i try to attach them to each other i can't, and I'm using table because i will need to create loads of objects and i think that will speed up things ... and take a lot less space.

local present = {} 
  
local gifts =  
{ 
    { 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 } 
} 
  
for key, value in ipairs( gifts ) do 
    present[key] = createObject( unpack( value ) ); 
end 
  
  
local collision = createColCuboid( 2493.25, -1675.25, 12.335947036743, 1.25, 2, 1 ) 
local string = string.format( "Object's X: %d, Y: %d, Z: %d", getElementPosition( present[1] ) ); 
attachElements( collision, present ) 

^

that's how the script is looking

Link to comment
Well, I want to make like from a table objects and i need them to have separate col shape, so when player hits it some stuff happens, but the problem is that when i try to attach them to each other i can't, and I'm using table because i will need to create loads of objects and i think that will speed up things ... and take a lot less space.
local present = {} 
  
local gifts =  
{ 
    { 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 } 
} 
  
for key, value in ipairs( gifts ) do 
    present[key] = createObject( unpack( value ) ); 
end 
  
  
local collision = createColCuboid( 2493.25, -1675.25, 12.335947036743, 1.25, 2, 1 ) 
local string = string.format( "Object's X: %d, Y: %d, Z: %d", getElementPosition( present[1] ) ); 
attachElements( collision, present ) 

^

that's how the script is looking

Use multi dimensional tables to store objects & its respective colshape arguments.

Link to comment

but, if i do something like this:

local gifts =  
{ 
    objects = 
    { 
        { 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 }; 
    }, 
     
    colshapes = 
    { 
        { 2493.25, -1675.25, 12.335947036743, 1.25, 2, 1 }; 
    } 
}; 
  
for key, value in ipairs( gifts.objects ) do 
    present = createObject( unpack( value ) ); 
end 
  
for key, value in ipairs( gifts.colshapes ) do 
    colshape = createColCuboid( unpack( value ) ); 
end 

I made it, but how i attach the object to col shape?

Link to comment
but, if i do something like this:
local gifts =  
{ 
    objects = 
    { 
        { 2289, 2494.0295410156, -1674.1334228516, 12.335947036743 }; 
    }, 
     
    colshapes = 
    { 
        { 2493.25, -1675.25, 12.335947036743, 1.25, 2, 1 }; 
    } 
}; 
  
for key, value in ipairs( gifts.objects ) do 
    present = createObject( unpack( value ) ); 
end 
  
for key, value in ipairs( gifts.colshapes ) do 
    colshape = createColCuboid( unpack( value ) ); 
end 

I made it, but how i attach the object to col shape?

No, not that. You create two tables inside ONE table, that's what is a multi dimensional table.

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