-.Paradox.- Posted September 16, 2013 Share Posted September 16, 2013 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 Link to comment
TAPL Posted September 16, 2013 Share Posted September 16, 2013 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 = {} Link to comment
kevenvz Posted September 16, 2013 Share Posted September 16, 2013 guiSetVisible(GUIEditor.Window[1], false) must be guiSetVisible(GUIEditor.window[1], false) with a lower case w Link to comment
-.Paradox.- Posted September 16, 2013 Author Share Posted September 16, 2013 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. Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 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. Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 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 Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 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) Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 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. Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 Okay, but i don't know how to trigger that function to server side, can you do it to me please? Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 -- Client Side -- triggerServerEvent("setMyArmor", localPlayer) -- Server Side -- addEvent("setMyArmor", true) addEventHandler("setMyArmor", root, function() setPedArmor(source, 100) end) Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 (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 September 17, 2013 by Guest Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 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. Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 Please read my last post i show you what i've done Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 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 but can't take money from the button . I told you do it server side because client side money will not change the server side money. Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 --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 Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 shopBuy? You should have same trigger name. in client remove line 6 and replace it with trigger. Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 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 Link to comment
TAPL Posted September 17, 2013 Share Posted September 17, 2013 Yes, but you just have a typo "4.". Link to comment
-.Paradox.- Posted September 17, 2013 Author Share Posted September 17, 2013 Ok gonna try tomorrow thanks for helping I will tell you if there is some errors 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