manve1 Posted August 26, 2012 Share Posted August 26, 2012 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
Castillo Posted August 26, 2012 Share Posted August 26, 2012 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
manve1 Posted August 26, 2012 Author Share Posted August 26, 2012 this wroked, thanx, but 2 more questions 1. how do i attach it to players head 2. when he clicks use and then on other object, how i make that first one gets deleted? Link to comment
Castillo Posted August 26, 2012 Share Posted August 26, 2012 1: attachElements 2: Define the object, like this: object = createObject ( model, x + 1, y, z, 0, 0, 0 ) and just before creating you do: if ( isElement ( object ) ) then destroyElement ( object ) end object = createObject ( model, x + 1, y, z, 0, 0, 0 ) Link to comment
manve1 Posted August 26, 2012 Author Share Posted August 26, 2012 you got me so confused for 5th time, can you just make a script? cuz you always nearly make me confused, thx Link to comment
Castillo Posted August 26, 2012 Share Posted August 26, 2012 Is not confused, because what you want is us to make the scripts for you, you are not learning at all. Link to comment
manve1 Posted August 27, 2012 Author Share Posted August 27, 2012 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
TAPL Posted August 27, 2012 Share Posted August 27, 2012 (edited) 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 August 27, 2012 by Guest Link to comment
sockz Posted August 27, 2012 Share Posted August 27, 2012 What were you thining when you used getElementPosition and then used that position with attachElements? Link to comment
manve1 Posted August 27, 2012 Author Share Posted August 27, 2012 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
TAPL Posted August 27, 2012 Share Posted August 27, 2012 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
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