Hi
I am new to scripting and looking to search all players inv to find an item and delete it from all users (online or offline). I cannot seem to figure out the Fetch side of things. Can anyone help me out on this?
Thanks
Hi
I am new to scripting and looking to search all players inv to find an item and delete it from all users (online or offline). I cannot seem to figure out the Fetch side of things. Can anyone help me out on this?
Thanks
Hey, do they have an item that u want to remove from all players inventorys? Why u dont only delete the item from the items table. But this wil give an error un f8 when they try to use it. Or you can maybe export the whole sql file and search in it with a text editor? And delete all the unwanted items.
Say if it works. Have Ă Nice day!
because i need a script to do it as a function hence the request for the coding advice. Im not going to set an alarm for myself so i can go into the DB every time my script runs. I dont need to delete it from DB nor do i want to. I want to fetch and remove the item from all inventories.
Hey ! 
Off the top of my mind, here is one of the way I would probably do it :
The following is just an algorithm (event if I used some lua), the synthax isn’t correct it’s just to point you in the direction of a potential solution.
[ server.lua ] :
--Server side script
--server.lua
--Our main Thread
Citizen.CreateThread(function()
Citizen.Wait(100)
while true do:
--Run the code every hour
Citizen.Wait(60*(60*1000))
--Fetch the inventory field in the table users for all users (hence connected or not)
MySQL.Async.fetchAll('SELECT `inventory` FROM `users` WHERE 1',
{}, function(result)
--For each line from the table that we got (one line by user)
for i, line in ipairs(result) do
--Remove the item you want from the lua table that contains our field (the synthax isn't good, it's just to give you an idea)
table.remove(line, "NameOfTheItemToRemove")
--Update each inventory of the users table one by one
MySQL.Async.execute('UPDATE `users` SET `inventory`= @inventory WHERE `identifier` = @identifier',
{
['@inventory'] = json.encode(line),
['@identifier'] = line["identifier"],
}, function(rowsChanged)
print("Item removed")
end)
end
end)
end
end
awesome, ill take a look at this.
with the below:
table.remove(line, “NameOfTheItemToRemove”)
you dont have to specify the table at all? its a function that automatically gets from the ipairs, correct? (sorry just learning about pairs/ipairs)
also:
WHERE 1
What is 1 defined as? does that just mean all? (0/1 or true/false)
Hey !
I’m pretty new in LUA too so I cannot give you too much in deepth details, especially regarding Tables (they can be a F-ing pain in the ass
).
But in the code line the table is already specified (as line is also a table) :
table.remove(line --[[the table]], "NameOfTheItemToRemove" --[[the "index" of the element to remove]])
But don’t forget that you need to replace [ “NameOfTheItemToRemove” ] by his index (3 if it’s the third item in the Table for example). As our [ line ] Table is numericaly indexed (and I just check by curiosity and the table.remove() function only works on numericaly indexed Table apparently)
For the SQL query, yep the 1 means everything 
I tried this and it kept crashing. Unsure. I am still at a loss.
okay, can you send me the code that you wrote so I can take a look and eventually tell you what’s making it crash ?
charlies_countdown.rar (2.9 KB)
It’s crashing because their is a [ Wait() ] missing after the while instruction (line 158)

Do all Cit threads require a wait or the loop creates a crash or is it just with this case?
If i’m not mistaking, you’re not required to put a [ Citizen.Wait() ] in your Thread if you don’t loop it. In the other hand when you loop your Thread the [ Citizen.Wait() ] is mandatory.
I myself have an eavy hand when it comes to pausing my code with [ Citizen.Wait() ], I find it allows me to better temporize my code and it’s very usefull when their is some code that doesn’t need to run every frame (I found that in most cases code can be run every 1s or even 2s without impacting the outcome of the script and saving processing time in the same time)