Adiidas

How to remove an element from the table?

Recommended Posts

Hello, I am creating a PIN system on my server and wanted to ask you for help in my code. When I send the client to the server a trigger wanted to validate if the pin sent from the client to the server is an element of my table if yes setElementData will work and the Pin used will be unable to use again but in my script when it uses a pin all The others are disabled, can you help me?
Note: I'm Brazilian, I'm sorry for English.

 

local pins15k = {"UAIFKAJDKEFC15K", "KYJFKAJDEFKC15K", "BESFKSLLKEFC15K"}

function PinEdit(Pin)
	if validatePin(Pin) then
		if getElementData(source, "Diamond") then
			setElementData(source, "Diamond", getElementData(source, "Diamond")+10000)
		else
			setElementData(source, "Diamond", 10000)
		end
		for k, v in ipairs(pins15k) do
			outputChatBox("["..k.."] = "..v)
		end
	else
		outputChatBox("Pin invalido", source)
		outputChatBox(tostring(pins15k))
	end
end
addEvent("PinEdit", true)
addEventHandler("PinEdit", getRootElement(), PinEdit)

function validatePin(pin)
	local result = false
	for k, v in ipairs(pins15k) do
		if (pin == v) then
			pins15k[k] = nil
			result = true
			break
		end
	end
	return result
end

 

Share this post


Link to post

You could use table.remove easily tho.

Share this post


Link to post
2 hours ago, Patrik91 said:

You could use table.remove easily tho.

Would you help me? How's the code? I do not know how to work with table.remove
Thank you in advance

Share this post


Link to post

Setting the value to nil will remove that data from the table. If you want to use table.remove, you will need to specify the index rather than the value.

Share this post


Link to post

Thank you all. They helped me a lot in using the table.remove, I did not know how to apply inside my script my friend (Banex) helped me

Share this post


Link to post

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.