Jump to content

Recommended Posts

table = {}

function table.contains(table, element)
	for _, value in pairs(table) do
		if value == element then
			return true
		end
	end
	return false
end

function tablefind(tab,el)
	for index, value in pairs(tab) do
		if value == el then
			return index
		end
	end
end

function OnClientGuiButton()
  if not table.contains(BedwarsEQ, "P1") then 
      table.insert(table, "P1") -- Insert to a table string "P1" (Player1)
  end

  if tablefind(table, "P1")==1 then -- check index, if is Item in index(1) then == true
    AdxItem1 = 255 -- dxDrawImage, drawing image to effect

    SLOT1 = SLOT1 + 1 -- type how many items is in P1
  end
  if tablefind(table, "P1")==2 then -- if is Item in index(1) then check "if is Item in Index(2)" == true
    BdxItem1 = 255 --second dxDrawImage, drawing image to effect

    SLOT2 = SLOT2 + 1 --type how many items is in P1
  end
end

addEvenetHandler("onClientGUIClick", button, OnClientGuiButton
  

I will explain the problem. The problem is that when I press the button that gives me to the table "P1", it checks in which index it is. There is a problem that if I click on another button that gives me "P2", it doesn't prove that "P2" is in the table. Debugscript writes to me that the wrong first argument is given in the tableFind function, and that's strange because I checked twice and gave the right one. What's wrong with that?

Link to comment
18 hours ago, Master_MTA said:

i don't get the problem please explain more to be able to help u

i upload how to look like and upload my code again


here is there link to see how it look like 

https://imgur.com/a/ZzGGRcX

 


there is a code 

function tablecontains(tabl, element)
	for index, value in pairs(tabl) do
		if value == element then
			return index
		end
	end
	return false
end
function tablecheck(tabl, element)
	for index, value in pairs(tabl) do
		if value == element then
			return true
		end
	end
	return false
end

button1 = createButton(etc)
button2 = createButton(etc)

money = 100

EQ = {}

function buttonpress1()
	if money>=2 then
		outputChatBox("Here, there is ITEM1", 255, 255, 0)
		money = money-2
		
		if not tablecontains(EQ, "P1") then
			table.insert(EQ, "P1")
		end
		
		if tablecheck(EQ, "P1") then
			local variable = tablecontains(EQ, "P1")
			
			if variable==1 then
				AdxItem1 = 255
				
				SLOT1 = SLOT1 + 1
			elseif variable==2 then
				BdxItem1 = 255
				
				SLOT2 = SLOT2 + 1
			elseif variable==3 then
				CdxItem1 = 255
				
				SLOT3 = SLOT3 + 1
			elseif variable==4 then
				DdxItem1 = 255
				
				SLOT4 = SLOT4 + 1
			elseif variable==5 then
				EdxItem1 = 255
				
				SLOT5 = SLOT5 + 1
			elseif variable==6 then
				FdxItem1 = 255
				
				SLOT6 = SLOT6 + 1
			elseif variable==7 then
				GdxItem1 = 255
				
				SLOT7 = SLOT7 + 1
			elseif variable==8 then
				HdxItem1 = 255
				
				SLOT8 = SLOT8 + 1
			end
		end
	else
		outputChatBox("u dont have money", 255, 0, 0)
	end
end

addEventHandler("onClientGUIClick", button1, buttonpress1)

function buttonpress2()
	if money>=4 then
		outputChatBox("Here, there is ITEM2", 255, 255, 0)
		money = money-4
		
		if not tablecontains(EQ, "P2") then
			table.insert(EQ, "P2")
		end
		
		if tablecheck(EQ, "P2") then
			local variable = tablecontains(EQ, "P2")
			
			if variable==1 then
				AdxItem1 = 255
				
				SLOT1 = SLOT1 + 1
			elseif variable==2 then
				BdxItem1 = 255
				
				SLOT2 = SLOT2 + 1
			elseif variable==3 then
				CdxItem1 = 255
				
				SLOT3 = SLOT3 + 1
			elseif variable==4 then
				DdxItem1 = 255
				
				SLOT4 = SLOT4 + 1
			elseif variable==5 then
				EdxItem1 = 255
				
				SLOT5 = SLOT5 + 1
			elseif variable==6 then
				FdxItem1 = 255
				
				SLOT6 = SLOT6 + 1
			elseif variable==7 then
				GdxItem1 = 255
				
				SLOT7 = SLOT7 + 1
			elseif variable==8 then
				HdxItem1 = 255
				
				SLOT8 = SLOT8 + 1
			end
		end
	else
		outputChatBox("u dont have money", 255, 0, 0)
	end
end

addEventHandler("onClientGUIClick", button2, buttonpress2)

 

Link to comment
24 minutes ago, redditing said:

Okay, I know where this problem comes from, because I gave the eventhandler when when I click the "i" button on the keyboard, he checked when this Event was firing up and then he didn't, but thank you for helping me

u r welcome sorry for being late 

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