Jump to content

[Solved] How to deal with duplicates in table


SpecT

Recommended Posts

Hey guys!

Well the topic name says it all. I'm filling a table with serials that have more than 1 accounts registered to.

But then it inserts the same serial once, twice or more (depends on accounts count).

I tried some ways to prevent this but none of them worked.

I even used the code provided from arezu here: https://forum.multitheftauto.com/viewtopic.php?f=91&t=40652&p=412597&hilit=table+duplicated#p414513

But it removes just some duplicates and the other stay there.

So yeah .. I need help.

Thanks in advance!

Edited by Guest
Link to comment

You can check whether a value is already within the table using this function

function in_table(haystack, needle) 
  for k, v in pairs(haystack) do -- if your table has standard auto-generated keys, you can change 'pairs' to 'pairs' (it might be less CPU intensive that way, but I'm not sure) 
    if v == needle then 
      return true, k -- returns true along with the key at which the value is first found 
    end 
  end 
  return false -- not found, returns false 
end 

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