Jump to content

FR Gui...


[DemoN]

Recommended Posts

I've added a button to my FR Gui called 'icons'. When I click icons button, a window appears.

j8kx2t.jpg

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:

11lo4mt.jpg

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 by Guest
Link to comment

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
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
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 :P ) when I press F1, nothing happens

Link to comment

i forgot an end :oops:

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

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

I'm going to be crazy!!! :twisted:

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

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

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

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
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
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 :D

anyway thank you guys. If i share this script, I will add your names in meta.xml and in description :D

Edit: How to attach...

This is my skin

wcclmx.png

I'm typing /ss 29

2u5cj8g.png

and attached :D

msetfs.png

Edited by Guest
Link to comment
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

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

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