[DemoN] Posted June 24, 2011 Share Posted June 24, 2011 (edited) I've added a button to my FR Gui called 'icons'. When I click icons button, a window appears. Here is my code ( in fr_client.lua below the setskin command and setskin window): ---------------------------- -------- Icon window ------- ---------------------------- wndIcon = { 'wnd', text = 'Icon Window', width = 250, controls = { { 'lst', id='iconlist', width=230, height=280, columns={ {text='Icons', attr='name'} }, rows={xml='icons.xml', attrs={'id', 'name'}}, onitemdoubleclick=function(leaf) attachElements(leaf, g_Me, 0, 0, 1.5) end }, {'btn', id='Use', onclick=attachElements}, {'btn', id='Close', closeswindow=true} } } I have preapared an icons.xml file: <catalog type="icons"> <object id="1559" name="Arrow" /> <object id="954" name="Horse Shoe" /> <object id="1212" name="Money" /> <object id="1239" name="Newbie (Info Icon)" /> <object id="1240" name="Fall in Love" /> <object id="1241" name="Drug" /> <object id="1242" name="Safe" /> <object id="1247" name="I am popular" /> <object id="1254" name="Serial Killer" /> <object id="1274" name="Rich" /> <object id="1275" name="Poor" /> <object id="1276" name="Magic" /> <object id="2768" name="Hunger" /> <object id="2916" name="Strong" /> <object id="953" name="Searching Strange Things" /> </catalog> I want to make that: When I click an item in grid list, selected item will be attached to source (attachElementToElement(selectedItem, source, 0, 0, 1.5, 0, 0, 0)) and without collisions like that: but as you can see (look at first picture) there is no item in the grid list and i don't know where to put setElementCollisionsEnabled function -.- Please Help Me! Edited June 25, 2011 by Guest Link to comment
Castillo Posted June 24, 2011 Share Posted June 24, 2011 Your XML file is wrong, use this: <catalog type="icon"> <icon name="Arrow" id="1559" /> <icon name="Horse Shoe" id="954" /> <icon name="Money" id="1212" /> <icon name="Newbie (Info Icon)" id="1239" /> <icon name="Fall in Love" id="1240" /> <icon name="Drug" id="1241" /> <icon name="Safe" id="1242" /> <icon name="I am popular" id="1247" /> <icon name="Serial Killer" id="1254" /> <icon name="Rich" id="1274" /> <icon name="Poorid" id="1275" /> <icon name="Magic" id="1276" /> <icon name="Hunger" id="2768" /> <icon name="Strong" id="2916" /> <icon name="Searching Strange Things" id="953" /> </catalog> Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 onitemdoubleclick=function(leaf) attachElements(leaf, g_Me, 0, 0, 1.5) end ("g_Me = getLocalPlayer()") List is ok but check my debugscript: it says bad argument @ attachElements Link to comment
JR10 Posted June 25, 2011 Share Posted June 25, 2011 function(leaf) attachElements(leaf, g_Me, 0, 0, 1.5) end if this function is onClientGUIDoubleClick then leaf is not the icon it is The Parameters for the event string button, string state, int absoluteX, int absoluteY you should do this function getIconIDByName(name) for i, v in ipairs(getElementsByType('icon')) do if getElementData(v, 'name') == name then return tonumber(getElementData(v, 'id')) end end end Use the above function function to retrieve the icon id from it's name you can get the name by the below is onClientGUIDoubleClick function onDoubleClick(botton, state) local row, column = guiGridListGetSelectedItem(IconGridList) local text = guiGridListGetItemText(IconGridList, row, column) local icon = getIconIDByName(text) local leaf = createPickup(0, 0, 0, 3, icon) attachElements(leaf, g_Me, 0, 0, 1.5) but make sure to change IconGridList to your gridlist. Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 wndIcon = { 'wnd', text = 'Icon Window', width = 250, controls = { { 'lst', id='IconGridList', width=230, height=280, columns={ {text='Icons', attr='name'} }, rows={xml='icons.xml', attrs={'id', 'name'}}, function getIconIDByName(name) for i, v in ipairs(getElementsByType('icon')) do if getElementData(v, 'name') == name then return tonumber(getElementData(v, 'id')) end end end function onDoubleClick(botton, state) local row, column = guiGridListGetSelectedItem(IconGridList) local text = guiGridListGetItemText(IconGridList, row, column) local icon = getIconIDByName(text) local leaf = createPickup(0, 0, 0, 3, icon) attachElements(leaf, g_Me, 0, 0, 1.5) }, {'btn', id='Use', onclick=attachElements}, {'btn', id='Close', closeswindow=true} } } I have changed my script like that but i think it's wrong ( I have edited it wrong. I don't say your informations are wrong ) when I press F1, nothing happens Link to comment
JR10 Posted June 25, 2011 Share Posted June 25, 2011 i forgot an end here wndIcon = { 'wnd', text = 'Icon Window', width = 250, controls = { { 'lst', id='IconGridList', width=230, height=280, columns={ {text='Icons', attr='name'} }, rows={xml='icons.xml', attrs={'id', 'name'}}, function getIconIDByName(name) for i, v in ipairs(getElementsByType('icon')) do if getElementData(v, 'name') == name then return tonumber(getElementData(v, 'id')) end end end function onDoubleClick(botton, state) local row, column = guiGridListGetSelectedItem(IconGridList) local text = guiGridListGetItemText(IconGridList, row, column) local icon = getIconIDByName(text) local leaf = createPickup(0, 0, 0, 3, icon) attachElements(leaf, g_Me, 0, 0, 1.5) end }, {'btn', id='Use', onclick=attachElements}, {'btn', id='Close', closeswindow=true} } } Sorry. And i never edited the FR but is this right?? {'btn', id='Use', onclick=attachElements} shouldn't it be {'btn', id='Use', onclick=onDoubleClick} im just saying, i never looked in the FR resource before so maybe you are right. Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 And i never edited the FR but is this right?? No but I have same problem again and my debugscript says: '(' expected near 'getIconIDByName' Link to comment
JR10 Posted June 25, 2011 Share Posted June 25, 2011 Hmm put the two functions outside wndIcon, if this happens again post the line. Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 I'm going to be crazy!!! ---------------------------- -------- Icon window ------- ---------------------------- wndIcon = { 'wnd', text = 'Icon Window', width = 250, controls = { { 'lst', id='IconGridList', width=230, height=280, columns={ {text='Icons', attr='name'} }, rows={xml='icons.xml', attrs={'id', 'name'}}, }, {'btn', id='Use', onclick=attachElements}, {'btn', id='Close', closeswindow=true} } } function getIconIDByName(name) for i, v in ipairs(getElementsByType('icon')) do if getElementData(v, 'name') == name then return tonumber(getElementData(v, 'id')) end end end function onDoubleClick(botton, state) local row, column = guiGridListGetSelectedItem(IconGridList) local text = guiGridListGetItemText(IconGridList, row, column) local icon = getIconIDByName(text) local leaf = createPickup(0, 0, 0, 3, icon) attachElements(leaf, g_Me, 0, 0, 1.5) end FR Gui appears, Grid list appears, when i click on an item, nothing happens. my debugscript doesn't say anything... Link to comment
JR10 Posted June 25, 2011 Share Posted June 25, 2011 Are you sure about this: {'btn', id='Use', onclick=attachElements} i think it should be the function like this: {'btn', id='Use', onclick=onDoubleClick} Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 when I use {'btn', id='Use', onclick=attachElements} (When I click Use button) it says bad argument @ attachElements (but when I double click nothing happens) and when I use {'btn', id='Use', onclick=onDoubleClick} nothing happens. Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 The Script became crazy... WARNING: freeroam/gui.lua:235: Bad argument @ attachElements here is the line 235: clickhandler = function() wnd.onclick() end Edit: I'm working on fr_client.lua but bad argument is in gui.lua Link to comment
JR10 Posted June 25, 2011 Share Posted June 25, 2011 Ok try this ---------------------------- -------- Icon window ------- ---------------------------- wndIcon = { 'wnd', text = 'Icon Window', width = 250, controls = { { 'lst', id='IconGridList', width=230, height=280, columns={ {text='Icons', attr='name'} }, rows={xml='icons.xml', attrs={'id', 'name'}}, }, {'btn', id='Use', onclick=onDoubleClick}, {'btn', id='Close', closeswindow=true} } } function getIconIDByName(name) for i, v in ipairs(getElementsByType('icon')) do if getElementData(v, 'name') == name then return tonumber(getElementData(v, 'id')) end end end onDoubleClick = function (botton, state) local row, column = guiGridListGetSelectedItem(IconGridList) local text = guiGridListGetItemText(IconGridList, row, column) local icon = getIconIDByName(text) local leaf = createPickup(0, 0, 0, 3, icon) attachElements(leaf, g_Me, 0, 0, 1.5) end Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 It's not working my debugscript says nothing... If you don't want to help me anymore (because it's getting hard and hard!), you can give up Link to comment
Castillo Posted June 25, 2011 Share Posted June 25, 2011 function applyAttachment(leaf) if type(leaf) ~= 'table' then leaf = getSelectedGridListLeaf(wndIcon, 'iconlist') if not leaf then return end end local x, y, z = getElementPosition(g_Me) local pickup = createPickup(x, y, z, 3, tonumber(leaf.id)) if pickup then attachElements(pickup, g_Me, 0, 0, 1.5) end end wndIcon = { 'wnd', text = 'Icon Window', width = 250, controls = { { 'lst', id='iconlist', width=230, height=280, columns={ {text='Icons', attr='name'} }, rows={xml='icons.xml', attrs={'id', 'name'}}, onitemdoubleclick=applyAttachment }, {'btn', id='Use', onclick=applyAttachment}, {'btn', id='Close', closeswindow=true} } } Everything works fine, but it won't attach it, dunno why. Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 (edited) Everything works fine, but it won't attach it, dunno why. lol I had tried it and it just spawned pickups but when I changed my skin it attached :D anyway thank you guys. If i share this script, I will add your names in meta.xml and in description Edit: How to attach... This is my skin I'm typing /ss 29 and attached Edited June 25, 2011 by Guest Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 Sorry but I need a little help I want to destroy the pickup when other pickup selected Link to comment
Castillo Posted June 25, 2011 Share Posted June 25, 2011 function applyAttachment(leaf) if type(leaf) ~= 'table' then leaf = getSelectedGridListLeaf(wndIcon, 'iconlist') if not leaf then return end end if isElement(pickup) then destroyElement(pickup) end local x, y, z = getElementPosition(g_Me) pickup = createPickup(x, y, z, 3, tonumber(leaf.id)) if pickup then attachElements(pickup, g_Me, 0, 0, 1.5) end end Link to comment
[DemoN] Posted June 25, 2011 Author Share Posted June 25, 2011 Thank you! Now It is really a script Thank you Solidsnake14 (a.k.a. Castillo) and JR10 (a.k.a. Jacob) Link to comment
qaisjp Posted June 26, 2011 Share Posted June 26, 2011 Demon, send me your newest code snippet via PM, I'll finish it off for you Link to comment
Castillo Posted June 26, 2011 Share Posted June 26, 2011 qaisjp, finish what? it's already "finished" as you say, there's nothing to finish, if you want to use it, then just say it . Link to comment
[DemoN] Posted June 28, 2011 Author Share Posted June 28, 2011 Sorry but I need a problem again I have tested this script on my friends server and it's working but I can't see my friend's icon and he can't see mine too. What do I need to do? Link to comment
Castillo Posted June 28, 2011 Share Posted June 28, 2011 That's obiously, because you are creating the icons client-side, and if you wanted others to see them it should be server-side. --client side function applyAttachment(leaf) if type(leaf) ~= 'table' then leaf = getSelectedGridListLeaf(wndIcon, 'iconlist') if not leaf then return end end triggerServerEvent("createPickup",g_Me,g_Me,leaf.id) end --server side local pickup = {} addEvent("createPickup",true) addEventHandler("createPickup",root, function (client, icon) if isElement(pickup[client]) then destroyElement(pickup[client]) end local x, y, z = getElementPosition(client) pickup[client] = createPickup(x, y, z, 3, tonumber(icon)) if pickup[client] then attachElements(pickup[client], client, 0, 0, 1.5) end end) addEventHandler("onPlayerQuit",root, function () if isElement(pickup[source]) then destroyElement(pickup[source]) end end) Try it, should work (not tested). 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