Jump to content

Shop system | Need help


Cronoss

Recommended Posts

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

 

  • Like 1
Link to comment

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

  • Thanks 1
Link to comment

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