StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 I'm adding more GUI code to the client file, which will be shown when the player clicks the button "Create" which I've added to the main GUI. The code is this, but according to my server, there's a problem with it because the whole script doesn't work. Here is the code: local status = "Your current position will be used for this marker." local gui.newLocation = guiCreateWindow(0, 0, w, h, "Create Teleport © Almighty", false) centerWindow(gui.newLocation) guiSetVisible(gui.newLocation, false) guiWindowSetSizable(gui.newLocation, false) local gui.valueLabel = guiCreateLabel(10, 53, 54, 15, "Value", false, gui.newLocation) local gui.valueInput = guiCreateEdit(10, 28, 150, 25, "", false, gui.newLocation) local gui.descLabel = guiCreateLabel(164, 53, 118, 15, "Location Description", false, gui.newLocation) local gui.descInput = guiCreateEdit(164, 28, 226, 25, "", false, gui.newLocation) local gui.localeMessage = guiCreateLabel(10, 78, 380, 22, status, false, gui.newLocation) local gui.localeStatusColor = guiLabelSetColor(gui.localeMessage, 255, 255, 255) local gui.newCreate = guiCreateButton(240, 110, 150, 30, "Create", false, gui.newLocation) I added that directly beneath the main 'window' GUI on the client file. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Can you explain more clear and use /debugscript 3 to check the errors in game it would be easy to find and solve the problem as i understood, you created a button in the main GUI defined as "window", if you clicked in it you want the main window be invisible and show new GUI Link to comment
Moderators Citizen Posted September 26, 2015 Moderators Share Posted September 26, 2015 You are creating the new window but you hide it immediately, is that really what you wanted to do at this point of the code ? Are you showing it later ? local gui.newLocation = guiCreateWindow(0, 0, w, h, "Create Teleport © Almighty", false) ... guiSetVisible(gui.newLocation, false) Also, I just read the whole topic, and KariiM did a pretty nice job (with you of course) but you guys are using: guiGridListGetSelectedItem(grid)+1 to know which row has been clicked and get the right row in the table. However this is working only if the gridlist hasn't been reordered. The player can reorder the gridlist by clicking on the column headers. By doing that the 1st row in the gridlist might not match the 1st row in the data table anymore. To fix that you can ask a row (well actually a cell of a row) to store a value for you which will be the corresponding row's number in the data table: function viewGUI (aTable) if ( source == getLocalPlayer() ) then guiSetVisible (window, true) showCursor (true) guiGridListClear(grid) for index ,val in ipairs (aTable) do local row = guiGridListAddRow (grid) guiGridListSetItemText (grid, row, col1, val[1], false, true) guiGridListSetItemText (grid, row, col2, val[2], false, false) guiGridListSetItemText (grid, row, col3, val[3], false, false) guiGridListSetItemData (grid, row, 1, index ) -- storing the row's number (or index) of the [b]data [/b]table end end end and then get it back this way: addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must select the destination !", getLocalPlayer(), 255, 0, 0) return false end guiSetVisible(window, false) showCursor(false) local rowSelected = guiGridListGetSelectedItem(grid) -- getting the gridlist row's number as you did triggerServerEvent("warp", getLocalPlayer(), guiGridListGetItemData (grid, rowSelected, 1)) -- but getting the [b]data [/b]table index from the row instead of doing a +1 end end) So now the gridlist can be reordered as much as it wants to, our item data we set won't be modified. @KariiiM: Nice to see you now helping others (I remember I was helping you not so much time ago). Keep doing that, you are helping the community and it's great. However if I can say just one thing, try to indent your code properly: 1 tab or 4 spaces is the recommended size for 1 level of indentation. The code is more readable and you can instantly see if you missed for example an end to close an opened if or a for loop or whatever. Thanks and keep up the good work. Link to comment
KariiiM Posted September 26, 2015 Share Posted September 26, 2015 Thanks Citizen,for the kind words, with those words you make the person love what he do,I like that and yes i still remember when you helped me everyone start from zero and i'm one of them just need some logic and practice to success, everything is possible Link to comment
StefanAlmighty Posted September 27, 2015 Author Share Posted September 27, 2015 I'm working on the GUI for create and delete buttons, so I'll get back to you if I get issues. But for now I'm getting this issue, the script doesn't work because I've added the "elseif (source == create)" onwards. I don't see what I did wrong there? addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) if guiGetVisible(window) ~= nil then guiSetVisible (window, false) -- closes current gui showCursor(false) end end end) Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 I'm going to bump this because I don't think my question was clear enough. My code is crashing because I added an additional elseif for when the button "Create" is clicked. Here is the code in question: addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) if guiGetVisible(window) ~= nil then guiSetVisible (window, false) -- closes current gui showCursor(false) end end end) I'll narrow down the specific part which is causing the script to not work. Here it is: elseif (source == create) if guiGetVisible(window) ~= nil then guiSetVisible (window, false) -- closes current gui showCursor(false) end end Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end end end) Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 Thanks KariiM (again), you've been sooooo much help. Appreciated. Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 Thanks KariiM (again), you've been sooooo much help. Appreciated. You're welcome Stefan Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 When I keep adding more click responses to that function, it messes up, what am I doing wrong? addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) guiSetVisible (newLocation, true) showCursor (true) end elseif (source == newLocationCancel) if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) guiSetVisible (window, true) end elseif (source == newLocationCreate) if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) showCursor (false) end end end) I added more to it, but now the script doesn't work again Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 I added more to it, but now the script doesn't work again You're using elseif without adding then so it will return false with ERRORs elseif (source == newLocationCreate) Must be like that elseif (source == newLocationCreate) then Full code addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) guiSetVisible (newLocation, true) showCursor (true) end elseif (source == newLocationCancel) then if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) guiSetVisible (window, true) end elseif (source == newLocationCreate) then if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) showCursor (false) end end end) Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 Okay so now I'm trying to create GUI text if a player doesn't fill out the name box or the description box. However, the text for some reason does not show up. addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) guiSetVisible (newLocation, true) showCursor (true) end elseif (source == newLocationCancel) then if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) guiSetVisible (window, true) end elseif (source == newLocationCreate) then if (nameInput == "") then guiSetText (errorMessage, "You have not entered a name for the teleport.") elseif (descInput == "") then guiSetText (errorMessage, "You have not entered a description for the teleport.") else -- ill continue this after end end end) That's the function for when the button is clicked. Here is the code which creates the label which can be found at the top of my script. local errorMessage = guiCreateLabel(10, 78, 380, 22, "", false, newLocation) Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 Try this and tell me the result addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) guiSetVisible (newLocation, true) showCursor (true) end elseif (source == newLocationCancel) then if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) guiSetVisible (window, true) end elseif (source == newLocationCreate) then if (nameInput == "") then guiSetText (errorMessage, "You have not entered a name for the teleport.") return end if (descInput == "") then guiSetText (errorMessage, "You have not entered a description for the teleport.") return end -- ill continue this after end end) Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 Doesn't seem to work. I've checked the X and Y of my label and there's no issue with them. Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 nameInput and descInput are Edit boxs? Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 local nameInput = guiCreateEdit(10, 28, 120, 25, "", false, newLocation) local descInput = guiCreateEdit(134, 28, 256, 25, "", false, newLocation) Yes. Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 Try that, addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) guiSetVisible (newLocation, true) showCursor (true) end elseif (source == newLocationCancel) then if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) guiSetVisible (window, true) end elseif (source == newLocationCreate) then local name = guiGetText(nameInput) local desc = guiGetText(descInput) if (name == "") then guiSetText (errorMessage, "You have not entered a name for the teleport.") return end if (desc == "") then guiSetText (errorMessage, "You have not entered a description for the teleport.") return end -- ill continue this after end end) Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 That worked! Thanks! Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 That worked! Thanks! No problem Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 Okay so now for the hard part. I'm not sure how to use table.insert. When the player types in the name and description, it should add a row to the data table which is in server.lua. It's at the bottom of this code. addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) elseif (source == create) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) guiSetVisible (newLocation, true) showCursor (true) end elseif (source == newLocationCancel) then if guiGetVisible(newLocation) ~= nil then guiSetVisible (newLocation, false) guiSetVisible (window, true) end elseif (source == newLocationCreate) then local name = guiGetText(nameInput) local desc = guiGetText(descInput) if (name == "") then guiSetText (errorMessage, "You have not entered a name for the teleport.") return end if (desc == "") then guiSetText (errorMessage, "You have not entered a description for the teleport.") return end -- How do I create the function which adds a row to my data table (which is located in the server.lua) end end) Here is the data table: local data = { [1] = {"1", "Los Santos", "Pershing Square", 1479.9873046875, -1710.9453125, 13.36874961853, 0, 0, 0}, [2] = {"2", "San Fierro", "Doherty", -1988.5693359375, 507.0029296875, 35.171875, 0, 0, 90}, [3] = {"3", "Las Venturas", "Las Venturas Airport", 1691.6801757813, 1449.1293945313, 10.765375, 0, 0, 268}, } Also, I want it so for the IDs, it grabs the next available ID. So for example, if there was 1, 2 and 4 it would create a teleport as 3. Link to comment
KariiiM Posted September 29, 2015 Share Posted September 29, 2015 I'm going to sleep i'll try that by myself tomorrow if i have time and tell you the results , send me the full code via pm Link to comment
StefanAlmighty Posted September 29, 2015 Author Share Posted September 29, 2015 Sent, thank you, take your time. Link to comment
KariiiM Posted September 30, 2015 Share Posted September 30, 2015 Sent, thank you, take your time. I didn't get any new message Link to comment
StefanAlmighty Posted September 30, 2015 Author Share Posted September 30, 2015 Sent it again. Also, everything is working anyway, it's just the code to insert a row to the data table. Link to comment
KariiiM Posted September 30, 2015 Share Posted September 30, 2015 Sent it again. Also, everything is working anyway, it's just the code to insert a row to the data table. Yes now fine i got it, working on it when i finish i'll send the results 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