Cronoss Posted February 4, 2022 Share Posted February 4, 2022 Well, I'm trying to make a simple shop-system, but the thing is that I don't know how to send the table "data" to the serverside: (client-side) function comprarGUI() local item = guiGridListGetSelectedItem(lista) if (item>=0)then local precio = guiGridListGetItemText(lista, guiGridListGetSelectedItem (lista), 2) local dinero = getPlayerMoney(localPlayer) if(dinero >= tonumber(precio)) then item = item + 1 cerrarGUI() triggerServerEvent("Dar", resourceRoot, localPlayer, Productos[item] [1], precio) --<----------- else outputChatBox("Test 1", 255, 0, 0) end else outputChatBox("Test 2", 255, 0, 0) Server side: function darcosas(source, item, precio) local cuenta = getPlayerAccount(source) if (cuenta) and not isGuestAccount (cuenta) then if (item==1) then outputChatBox("Test", source) elseif (item==2) then outputChatBox("Test 2", source) elseif (item==3) then outputChatBox("Test 3", source) end end end addEvent("Dar", true) addEventHandler("Dar", getRootElement(), darcosas) I knew it wouldn't work, but this is what I'm trying to make, send the position of the table and if is it 1, or 2, or 3, make different actions Link to comment
βurak Posted February 5, 2022 Share Posted February 5, 2022 Quote I don't know how to send the table "data" to the serverside I'm not sure if you want to send the whole table but you can use events for that example: server: addEvent("sendTableToServer", true) addEventHandler("sendTableToServer", root, function(theTable) --the table we will get for i,_ in ipairs(theTable) do outputDebugString(theTable[i]) --Output: Banana Cucumber Eggplant end end ) client: local clientTable = {"Banana", "Cucumber", "Eggplant"} addCommandHandler("sendtable", function() triggerServerEvent("sendTableToServer", localPlayer, clientTable) -- send the whole table as it is end ) 1 Link to comment
Cronoss Posted February 5, 2022 Author Share Posted February 5, 2022 Just to clarify, I want to send wich item the player is selecting, so the shop can give a different "action", if he chooses "apple" then his health increases, but if he buy a "cigarrete" his health decrease Link to comment
βurak Posted February 5, 2022 Share Posted February 5, 2022 server: function darcosas(precio) local cuenta = getPlayerAccount(source) if (cuenta) and not isGuestAccount (cuenta) then outputDebugString("You selected "..precio) end end addEvent("Dar", true) addEventHandler("Dar", getRootElement(), darcosas) client: function comprarGUI() local item = guiGridListGetSelectedItem(lista) if (item>=0)then local precio = guiGridListGetItemText(lista, guiGridListGetSelectedItem (lista), 2) local dinero = getPlayerMoney(localPlayer) if(dinero >= tonumber(precio)) then item = item + 1 cerrarGUI() triggerServerEvent("Dar", localPlayer, precio) --<----------- else outputChatBox("Test 1", 255, 0, 0) end else outputChatBox("Test 2", 255, 0, 0) can you try this code, it will output according to the column selected by the player 1 Link to comment
Cronoss Posted February 5, 2022 Author Share Posted February 5, 2022 Actually, precio means price $$$ , but you gave me an idea how to solve it, thank you! Link to comment
βurak Posted February 5, 2022 Share Posted February 5, 2022 I did not know that. You're welcome. anytime 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