Hero192 Posted July 23, 2015 Share Posted July 23, 2015 (edited) Any idea? It sends me another errors other IDs working fine,but the first ID always gives this Error ERROR: attempt to index field '?' (a nil value) it says the error is in this line local weapPrice = Weapons[guiGridListGetSelectedItem (grid)][3] --Table of weapons: Weapons = { {1,1,400}, {2,2,1500}, {5,5,550}, {6,6,700}, {7,7,850}, {8,8,1500}, {9,9,2000}, {10,10,800}, {12,12,800}, {15,15,500} } Edited July 24, 2015 by Guest Link to comment
HustraDev Posted July 23, 2015 Share Posted July 23, 2015 you need to now that what trying to do is trigger { id, Price} for weapon and maybe contain {Ammo} from The Client Side that contain { Table And Gridlist } well, What you Gone do is Client Side First :- Create Table and insert { ID , Price , AMMO } like This Weapons = { {ID,Price,AMMO} } Example Weapons = { {32,"Name",100,9999} } after The Table Created Now you need to Create Gridlist Then insert The Table in the Gridlist and Create Button for Triggering server function btnbuy = guiCreateButton(773, 596, 127, 41, "buyWep", false) gridlist = guiCreateGridList(412, 179, 488, 412, false) guiGridListAddColumn(gridlist, "#", 0.2) guiGridListAddColumn(gridlist, "Name", 0.2) guiGridListAddColumn(gridlist, "Price", 0.2) guiGridListAddColumn(gridlist, "AMMO", 0.2) for k,v in ipairs ( Weapons ) do local row = guiGridListAddRow (gridlist) guiGridListSetItemText (gridlist, row, 1,v [1] , false, false) guiGridListSetItemText (gridlist, row, 2, v [2], false, false) guiGridListSetItemText (gridlist, row, 3, v [3] , false, false) guiGridListSetItemText (gridlist, row, 4, v [4] , false, false) end function buygun() if (source == btnbuy) then if (guiGridListGetSelectedItem (gridlist)) then local weapID = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 1) local weapName = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 2) local weapPrice = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 3) local weapAMMO = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 4) triggerServerEvent ("buyweapon", getLocalPlayer(), weapID, weapName, weapPrice, weapAMMO) end end end addEventHandler ("onClientGUIClick", getRootElement(), buygun) Server Side :- addEvent ("createweap", true) addEventHandler ("buyweapon", getRootElement(), function(weapID, weapName, weapPrice, weapAMMO) if (getPlayerMoney (source) >= tonumber(weapPrice)) then takePlayerMoney (source, tonumber (weapPrice)) giveWeapon(source,weapID,weapAMMO) else outputChatBox ("Have No Cash!", source, 255, 0, 0, false) end end ) i Hope you get the idea for more information about the tables and gridlist viewtopic.php?f=148&t=87781 Link to comment
Hero192 Posted July 23, 2015 Author Share Posted July 23, 2015 (edited) Any idea? --Table in Client side: Weapons = { {1,1,100}, {2,2,1500}, {3,3,1000}, {4,4,10000}, {5,5,122}, {6,6,1222} } Thanks for the ideas, look when i do this type for money table guiGridListSetItemText(gridList, row, 3, v[3].."$" , false, false) i get Error and the player being not able to take money ERROR:server.lua:26:attempt to compare nil with number Line 26 is in server side its the part of 26line if (getPlayerMoney (source) >= tonumber(weapPrice)) then takePlayerMoney (source, tonumber (weapPrice)) Edited July 23, 2015 by Guest Link to comment
GTX Posted July 24, 2015 Share Posted July 24, 2015 Of course. The dollar string at the end of your item text is not a number! This is already the second time you did this. btnbuy = guiCreateButton(773, 596, 127, 41, "buyWep", false) gridlist = guiCreateGridList(412, 179, 488, 412, false) guiGridListAddColumn(gridlist, "#", 0.2) guiGridListAddColumn(gridlist, "Name", 0.2) guiGridListAddColumn(gridlist, "Price", 0.2) guiGridListAddColumn(gridlist, "AMMO", 0.2) for k,v in ipairs ( Weapons ) do local row = guiGridListAddRow (gridlist) guiGridListSetItemText (gridlist, row, 1,v [1] , false, false) guiGridListSetItemText (gridlist, row, 2, v [2], false, false) guiGridListSetItemText (gridlist, row, 3, v [3].."$" , false, false) guiGridListSetItemText (gridlist, row, 4, v [4] , false, false) end function buygun() if (source == btnbuy) then if (guiGridListGetSelectedItem (gridlist)) then local weapID = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 1) local weapName = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 2) local weapPrice = tonumber(guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 3):gsub("$", "")) local weapAMMO = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 4) triggerServerEvent ("buyweapon", getLocalPlayer(), weapID, weapName, weapPrice, weapAMMO) end end end addEventHandler ("onClientGUIClick", getRootElement(), buygun) Link to comment
Hero192 Posted July 24, 2015 Author Share Posted July 24, 2015 It's still doesn't works ,i mean it doesn't take player money@GTX it gives Error about tonumber here's the message: bad argument #2 to 'tonumber' (base out of range) Link to comment
GTX Posted July 24, 2015 Share Posted July 24, 2015 btnbuy = guiCreateButton(773, 596, 127, 41, "buyWep", false) gridlist = guiCreateGridList(412, 179, 488, 412, false) guiGridListAddColumn(gridlist, "#", 0.2) guiGridListAddColumn(gridlist, "Name", 0.2) guiGridListAddColumn(gridlist, "Price", 0.2) guiGridListAddColumn(gridlist, "AMMO", 0.2) for k,v in ipairs ( Weapons ) do local row = guiGridListAddRow (gridlist) guiGridListSetItemText (gridlist, row, 1,v [1] , false, false) guiGridListSetItemText (gridlist, row, 2, v [2], false, false) guiGridListSetItemText (gridlist, row, 3, v [3].."$" , false, false) guiGridListSetItemText (gridlist, row, 4, v [4] , false, false) end function buygun() if (source == btnbuy) then if (guiGridListGetSelectedItem (gridlist)) then local weapID = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 1) local weapName = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 2) local weapPrice = Weapons[guiGridListGetSelectedItem (gridlist)][3] local weapAMMO = guiGridListGetItemText (gridlist, guiGridListGetSelectedItem (gridlist), 4) triggerServerEvent ("buyweapon", getLocalPlayer(), weapID, weapName, weapPrice, weapAMMO) end end end addEventHandler ("onClientGUIClick", getRootElement(), buygun) Link to comment
Hero192 Posted July 24, 2015 Author Share Posted July 24, 2015 (edited) Workings now,thank you GTX for your time EDIT:still have a problem doesn't selecte/take player money from the first ID Edited July 24, 2015 by Guest Link to comment
Hero192 Posted July 24, 2015 Author Share Posted July 24, 2015 It sends me another errors other IDs working fine,but the first ID always gives this Error ERROR: attempt to index field '?' (a nil value) it says the error is in this line local weapPrice = Weapons[guiGridListGetSelectedItem (grid)][3] 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