Jump to content

GUI editor problem


-.Paradox.-

Recommended Posts

Posted

Hello ,I have a gui bug can somebody fix it please thanks for help

  
GUIEditor = { 
    tab = {}, 
    tabpanel = {}, 
    button = {}, 
    window = {}, 
    gridlist = {} 
} 
  
  
  
        GUIEditor.window[1] = guiCreateWindow(0.41, 0.33, 0.25, 0.42, "Health and Armor shop", true) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
        GUIEditor.tabpanel[1] = guiCreateTabPanel(9, 17, 319, 253, false, GUIEditor.window[1]) 
        GUIEditor.tab[1] = guiCreateTab("Shop", GUIEditor.tabpanel[1]) 
        GUIEditor.gridlist[1] = guiCreateGridList(8, 5, 304, 167, false, GUIEditor.tab[1]) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "Shop", 0.4) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "$", 0.4) 
        for i = 1, 2 do 
            guiGridListAddRow(GUIEditor.gridlist[1]) 
        end 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 1, "-", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 2, "-", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 1, "-", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 2, "-", false, false) 
        GUIEditor.button[1] = guiCreateButton(94, 174, 121, 44, "Buy Stuff", false, GUIEditor.tab[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") 
        GUIEditor.gridlist[2] = guiCreateGridList(8, 5, 304, 167, false, GUIEditor.tab[1]) 
        guiGridListAddColumn(GUIEditor.gridlist[2], "Shop", 0.4) 
        guiGridListAddColumn(GUIEditor.gridlist[2], "$", 0.4) 
        for i = 1, 2 do 
            guiGridListAddRow(GUIEditor.gridlist[2]) 
        end 
        guiGridListSetItemText(GUIEditor.gridlist[2], 0, 1, "-", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[2], 0, 2, "-", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[2], 1, 1, "-", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[2], 1, 2, "-", false, false) 
        GUIEditor.button[2] = guiCreateButton(99, 273, 136, 36, "Close Shop", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")     
        guiSetVisible(GUIEditor.Window[1], false) 
        showCursor(false) 
  
function enableShop() 
    if guiGetVisible(GUIEditor.Window[1]) == false then 
        guiSetVisible(GUIEditor.Window[1], true) 
        showCursor(true) 
    else 
        guiSetVisible(GUIEditor.Window[1], false) 
        showCursor(false) 
    end 
end 
addCommandHandler("shop", enableShop) 
  
function closeButton() 
        guiSetVisible(GUIEditor.Window[1], false) 
        showCursor(false) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor.Button[2], closeButton, false ) 

I want when player click on the first row sethealth to 100

and second row setarmor to 100

Errors in debug

ERROR: Shops/c_gui.lua:41:attempt to index field 'Window' (a nil value)

thanks for help

Posted

As you can see, all of them start with lowercase letters so be sure your whole script have them the same.

     tab = {}, 
    tabpanel = {}, 
    button = {}, 
    window = {}, 
    gridlist = {} 

Posted

Yes, I understand but how I can set text of the rows and when player click in first row it take 1000$ from player cash and setElementHealth to max thanks for helping.

Shop $

_________________

Health 1000$

Armor 1000$

That's the rows I want set text for it.

Posted

I'm not sure if the first row number is 0 or 1 (i forgot) so be sure to test this thing.

addEventHandler("onClientGUIClick", guiRoot, 
function() 
    if source == GUIEditor.button[1] then 
        local row = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) 
        if row == 0 then 
            -- set the health 
        elseif row == 1 then 
            -- set the armour 
        end 
    end 
end) 

Also you have two grid list in same position, i guess that you copied it with the guieditor by mistake.

Posted

Ok thanks gonna try but i saw that too when i open window setting i saw Column called "copy" i tough it will output the code but it just copied the oanel to create another one thanks again :)

Posted

Alright i tried this it's working fine but when i select armor and i click in Buy stuff it output in debug

ERROR:Shops/c_gui.lua:58:attempt to call global 'setElementArmor' (a nil value)

here is the code

  
GUIEditor = { 
    tab = {}, 
    tabpanel = {}, 
    button = {}, 
    window = {}, 
    gridlist = {} 
} 
  
  
  
        GUIEditor.window[1] = guiCreateWindow(0.41, 0.33, 0.25, 0.42, "Health and Armor shop", true) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
        GUIEditor.tabpanel[1] = guiCreateTabPanel(9, 17, 319, 253, false, GUIEditor.window[1]) 
        GUIEditor.tab[1] = guiCreateTab("Shop", GUIEditor.tabpanel[1]) 
        GUIEditor.gridlist[1] = guiCreateGridList(8, 5, 304, 167, false, GUIEditor.tab[1]) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "Shop", 0.4) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "$", 0.4) 
        for i = 1, 2 do 
            guiGridListAddRow(GUIEditor.gridlist[1]) 
        end 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 1, "Health", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 2, "1000$", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 1, "Armor", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 2, "1000$", false, false) 
        GUIEditor.button[1] = guiCreateButton(94, 174, 121, 44, "Buy Stuff", false, GUIEditor.tab[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") 
        GUIEditor.button[2] = guiCreateButton(99, 273, 136, 36, "Close Shop", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")     
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
  
function enableShop() 
    if guiGetVisible(GUIEditor.window[1]) == false then 
        guiSetVisible(GUIEditor.window[1], true) 
        showCursor(true) 
    else 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
    end 
end 
addCommandHandler("shop", enableShop) 
  
function closeButton() 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor.button[2], closeButton, false ) 
  
addEventHandler("onClientGUIClick", guiRoot, 
function() 
    if source == GUIEditor.button[1] then 
        local row = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) 
        if row == 0 then 
            setElementHealth(source, 200) 
        elseif row == 1 then 
            setElementArmor(source,100) 
        end 
    end 
end) 

Posted

setElementArmor doesn't exist, the function name for armor is setPedArmor and you need to trigger server side because it's only server side function unlike setElementHealth.

Also don't use source because source here is button, use localPlayer instead.

Posted
-- Client Side -- 
  
triggerServerEvent("setMyArmor", localPlayer) 

-- Server Side -- 
  
addEvent("setMyArmor", true) 
addEventHandler("setMyArmor", root, 
function() 
    setPedArmor(source, 100) 
end) 

Posted (edited)

Thank you, and if i wan t to use takePlayerMoney what i must use?

That what i tried but it set health but dont take money from player

addEventHandler("onClientGUIClick", guiRoot, 
function() 
    if source == GUIEditor.button[1] then 
        local row = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) 
        if row == 0 then 
            if (getPlayerMoney (source) >= 1000) then 
            takePlayerMoney (source, tonumber(1000)) 
                        setElementHealth(source,200) 
        elseif row == 1 then 
            triggerServerEvent("setMyArmor", localPlayer) 
        end 
    end 
end 
end) 
  

Edited by Guest
Posted

You will need getPlayerMoney to make sure the player have the amount of money so that it won't be in negative.

And better do it server side because client side money doesn't change server side money.

Posted
setElementArmor doesn't exist, the function name for armor is setPedArmor and you need to trigger server side because it's only server side function unlike setElementHealth.

Also don't use source because source here is button, use localPlayer instead.

Thank you, and if i wan t to use takePlayerMoney what i must use?

That what i tried but it set health but dont take money from player

addEventHandler("onClientGUIClick", guiRoot, 
function() 
    if source == GUIEditor.button[1] then 
        local row = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) 
        if row == 0 then 
            if (getPlayerMoney (source) >= 1000) then 
            takePlayerMoney (source, tonumber(1000)) 
                        setElementHealth(source,200) 
        elseif row == 1 then 
            triggerServerEvent("setMyArmor", localPlayer) 
        end 
    end 
end 
end) 
  

How the hell it set the health to the button :mrgreen: but can't take money from the button :o.

I told you do it server side because client side money will not change the server side money.

Posted

--Client Side

addEventHandler("onClientGUIClick", guiRoot, 
function() 
    if source == GUIEditor.button[1] then 
        local row = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) 
        if row == 0 then 
            setElementHealth(source,200) 
        elseif row == 1 then 
            triggerServerEvent("setMyArmor", localPlayer) 
        end 
    end 
end 
) 

--Server Side

addEvent ("shopBuy", true) 
addEventHandler ("shopBuy", getRootElement(),  
function() 
  if (getPlayerMoney (source) >= tonumber(1000)) then 
    takePlayerMoney (source, tonumber (1000)) 
    setElementHealth(source,200) 
  else 
    outputChatBox ("You are too poor!", source, 255, 0, 0, false) 
  end 
end) 

That what i tried in server side

Posted
  
 addEventHandler("onClientGUIClick", guiRoot,  
 function()  
 if source == GUIEditor.button[1] then 4. local row = guiGridListGetSelectedItem (GUIEditor.gridlist[1])  
 if row == 0 then  
 triggerServerEvent ("shopBuy", localPlayer) 
 elseif row == 1 then  
 triggerServerEvent ("setMyArmor", localPlayer)  
 end  
 end  
 end  
 ) 

Like that sorry for bad code because i made it in phone

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