Jump to content

please help me


manve1

Recommended Posts

How can i make that when i select object on grid list and i press a button, it will be created by side, or on his head, here is LUA

local hRow = nil; 
      
hWnd = guiCreateWindow( 0.1, 0.1, 0.2, 0.65, "Hats", true ); 
hButton_use = guiCreateButton( 0.1, 0.725, 0.5, 0.1, "Use", true, hWnd ); 
hButton_close = guiCreateButton( 0.1, 0.85, 0.5, 0.1, "Close", true, hWnd ); 
  
local aObjects = 
{ 
    "Gate", 
    "Bottle", 
    "Flower pot", 
    "Bin", 
    "Fan", 
    "WW1 hat", 
    "WW2 hat"; 
}; 
            
hGrid = guiCreateGridList( 0.1, 0.10, 0.8, 0.60, true, hWnd ); 
guiGridListAddColumn( hGrid, "ZM hats", 0.85 ); 
      
local x, y, z = getElementPosition()      
      
for i,m_obj in ipairs( aObjects ) do 
    hRow = guiGridListAddRow( hGrid ); 
    -- 
    guiGridListSetItemText ( hGrid, hRow, 1, tostring( m_obj ), false, false ); 
end 
  
function use() 
if (source == "Gate" and hButton_use) then 
createObject( 980, x + 1, y, z, 0, 0, 0 ) 
end 
end 
addEventHandler("onClientGUIClick", hButton_use, aObjects ) 

Link to comment
local hRow = nil 
  
hWnd = guiCreateWindow( 0.1, 0.1, 0.2, 0.65, "Hats", true ); 
hButton_use = guiCreateButton( 0.1, 0.725, 0.5, 0.1, "Use", true, hWnd ); 
hButton_close = guiCreateButton( 0.1, 0.85, 0.5, 0.1, "Close", true, hWnd ); 
  
local aObjects = 
{ 
    { "Gate", 980 }, 
    { "Bottle", 980 }, 
    { "Flower pot", 980 }, 
    { "Bin", 980 }, 
    { "Fan", 980 }, 
    { "WW1 hat", 980 }, 
    { "WW2 hat" 
}; 
            
hGrid = guiCreateGridList( 0.1, 0.10, 0.8, 0.60, true, hWnd ); 
guiGridListAddColumn( hGrid, "ZM hats", 0.85 ); 
      
for i,m_obj in ipairs( aObjects ) do 
    hRow = guiGridListAddRow( hGrid ); 
    -- 
    guiGridListSetItemText ( hGrid, hRow, 1, tostring( m_obj [ 1 ] ), false, false ); 
    guiGridListSetItemData ( hGrid, hRow, 1, tostring( m_obj [ 2 ] ) ); 
end 
  
function use ( ) 
    local row, col = guiGridListGetSelectedItem ( hGrid ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local model = tonumber ( guiGridListGetItemData ( hGrid, row, 1 ) ) 
        local x, y, z = getElementPosition ( localPlayer ) 
        createObject ( model, x + 1, y, z, 0, 0, 0 ) 
    end 
end 
addEventHandler ( "onClientGUIClick", hButton_use, use, false ) 

Link to comment

You telling me that im not trying to learn using MTA wiki? then why the F*** is it up?

And what you MTA team posted and don't even understand at all...that's why its confusing for me..

EDIT: i made new LUA, as you told me too, but it still doesn't do it, i am still confused on how to make attachElements right, but i made another that should of worked, but idk why it just doesn't

    function use ( ) 
        local row, col = guiGridListGetSelectedItem ( hGrid ) 
        if ( row and col and row ~= -1 and col ~= -1 ) then 
            local model = tonumber ( guiGridListGetItemData ( hGrid, row, 1 ) ) 
            local x, y, z = getElementPosition ( localPlayer ) 
                if ( isElement ( object ) ) then 
        destroyElement ( object ) 
    end 
    object = createObject ( model, x, y, z + 0.8, 0, 0, 0 ) 
        object = createObject ( model, x, y, z + 0.8, 0, 0, 0 ) 
            attachElements ( object, source, x, y, z) 
        end 
    end 
    addEventHandler ( "onClientGUIClick", hButton_use, use, false )  

Link to comment

You have double createObject in your code.

And you need to use localPlayer in attachElements not source.

Also you have to notice that the object will be visible only for the player who has pressed the button.

Edited by Guest
Link to comment

fixed what you guys said.. now it doesn't even create the object, here is lua

    local hRow = nil 
    local x, y, z = getElementPosition ( source ) 
     
    hWnd = guiCreateWindow( 0.1, 0.1, 0.2, 0.65, "Hats", true ); 
    hButton_use = guiCreateButton( 0.1, 0.725, 0.5, 0.1, "Use", true, hWnd ); 
    hButton_close = guiCreateButton( 0.1, 0.85, 0.5, 0.1, "Close", true, hWnd ); 
      
    local aObjects = 
    { 
        { "Bottle", 1512 }, 
        { "Flower pot", 742 }, 
        { "Bin", 1362 }, 
        { "Fan", 14527 }, 
        { "WW1 hat", 2052 }, 
        { "WW2 hat", 2053 }, 
    }; 
                
    hGrid = guiCreateGridList( 0.1, 0.10, 0.8, 0.60, true, hWnd ); 
    guiGridListAddColumn( hGrid, "ZM hats", 0.85 ); 
          
    for i,m_obj in ipairs( aObjects ) do 
        hRow = guiGridListAddRow( hGrid ); 
        -- 
        guiGridListSetItemText ( hGrid, hRow, 1, tostring( m_obj [ 1 ] ), false, false ); 
        guiGridListSetItemData ( hGrid, hRow, 1, tostring( m_obj [ 2 ] ) ); 
    end 
      
    function use ( ) 
        local row, col = guiGridListGetSelectedItem ( hGrid ) 
        if ( row and col and row ~= -1 and col ~= -1 ) then 
            local model = tonumber ( guiGridListGetItemData ( hGrid, row, 1 ) ) 
            local x, y, z = getElementPosition ( localPlayer ) 
                if ( isElement ( object ) ) then 
        destroyElement ( object ) 
    end 
        object = createObject ( model, x, y, z + 0.8, 0, 0, 0 ) 
            attachElements ( object, localPlayer, x, y, z) 
        end 
    end 
    addEventHandler ( "onClientGUIClick", hButton_use, use, false ) 

Link to comment

Line 1 - 2 make no sense, just remove it.

Did you read what sockz said?

i think you need it like this:

attachElements(object, localPlayer, 0, 0, 1) 

and again

Also you have to notice that the object will be visible only for the player who has pressed the button.
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...