A new version for this script is here http://otland.net/f82/anti-dupe-delete-all-duplicated-items-your-database-136899/#post1317307
Hello, here i finished a Basic Anti-dupe System, it can help to detect duped items.
First of all, i'm using the attribute 'serial' that gives to items an "unique serial code".
You need to paste this at your lib/functions.lua:
Now, everytime that do you want to set a serial to an item, just use
With this command, you'll get info about all items with serial and you can get info about items with duplicated serials (Cloned items)
Create a file called trackitems.lua and paste this:
This will delete items with duplicated serial when serer starts:
Create a file of globalevents/scripts called trackitems.lua and paste:
Also you can see items with serial from phpMyAdmin with this command:
And you can see items with duplicated serials with the following commands:
Note that you can change the table 'player_items' to 'player_depotitems' to get info about items on depot
Please, comment with constructive criticism !
Rep++ is appreciated!
Hello, here i finished a Basic Anti-dupe System, it can help to detect duped items.
First of all, i'm using the attribute 'serial' that gives to items an "unique serial code".
You need to paste this at your lib/functions.lua:
Lua:
function generateSerial()
local strings = "ABCDEFGHIJKLMOPQRSTUVWXYZ"
local newSerialStr, newSerialInt = "", 0
local newSerial = ""
local query
repeat
for k = 1, math.random(1, 10) do
local l = math.random(1, string.len(strings))
newSerialStr = newSerialStr .. string.sub(strings, l, l)
end
newSerialInt = math.random(999999)
newSerial = newSerialStr .. "-" .. newSerialInt
query = db.getResult("select * from player_items where substring(convert(attributes using latin1) from 18) = " .. db.escapeString(newSerial))
until query:getID() == -1
return "!" .. newSerial
end
Now, everytime that do you want to set a serial to an item, just use
Lua:
doItemSetAttribute(uid, "serial", generateSerial())
With this command, you'll get info about all items with serial and you can get info about items with duplicated serials (Cloned items)
Create a file called trackitems.lua and paste this:
Lua:
function onSay(cid, words, param, channel)
if(param ~= "duplicated") then
local query = db.getResult("select *, substring(convert(attributes using latin1) from 18) as 'track' from player_items where convert(attributes using latin1) like '%serial%'")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of all items with serial.\nOwner Name - ItemID - Count - Serial")
if query:getID() ~= -1 then
while(true) do
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getPlayerNameByGUID(query:getDataInt("player_id")) .. " - " .. query:getDataInt("itemtype") .. " - " .. query:getDataInt("count") .. " - " .. query:getDataString("track"))
if not query:next() then break end
end
end
else
local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM player_items WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM player_items WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 1)")
if query:getID() ~= -1 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of all items with duplicated serial.\nOwner Name - ItemID - Count - Serial")
while(true) do
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getPlayerNameByGUID(query:getDataInt("player_id")) .. " - " .. query:getDataInt("itemtype") .. " - " .. query:getDataInt("count") .. " - " .. query:getDataString("track"))
if not query:next() then break end
end
else
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "No items with duplicated serial.")
end
end
return true
end
XML:
<talkaction words="/track" access="5" event="script" value="trackitems.lua"/>
This will delete items with duplicated serial when serer starts:
Create a file of globalevents/scripts called trackitems.lua and paste:
Lua:
tablesToCheck = {"player_items", "player_depotitems"}
function onStartup()
local text, final = "", ""
local filex = "data/logs/duplicated.txt"
local f = io.open(filex, "a+")
for i = 1, table.maxn(tablesToCheck) do
local query = db.getResult("SELECT *, SUBSTRING(CONVERT(attributes USING latin1) FROM 18) AS 'track' FROM " .. tablesToCheck[i] .. " WHERE SUBSTRING(CONVERT(attributes USING latin1) FROM 18) IN (SELECT SUBSTRING(CONVERT(attributes USING latin1) FROM 18) FROM " .. tablesToCheck[i] .. " WHERE CONVERT(attributes USING latin1) LIKE '%serial%' GROUP BY SUBSTRING(CONVERT(attributes USING latin1) FROM 18) HAVING COUNT(*) > 1)")
local duplicated = {}
if query:getID() ~= -1 then
while(true) do
text = "[!] -> Deleting item with duplicated serial: [Player: " .. getPlayerNameByGUID(query:getDataInt("player_id")) .. ", Item: " .. query:getDataInt("itemtype") .. ", Count: " .. query:getDataInt("count") .. ", Serial: " .. query:getDataString("track") .."]... "
local delete = db.executeQuery("delete from " .. tablesToCheck[i] .. " where SUBSTRING(CONVERT(attributes USING latin1) FROM 18) = " .. db.escapeString(query:getDataString("track")) .. ";")
if delete then
text = text .. "Success!"
else
text = text .. "Failed!"
end
final = final .. (final ~= "" and "\n" or "") .. text
print(text)
if not query:next() then break end
end
if f ~= nil then
f:write(os.date() .. "\n" .. final .. "\n\n")
f:close()
else
print("[!] -> Cannot save info to file!")
end
else
print("[!] -> Cannot get info, table is empty, there are not items with duplicated serial or you have a problem on the query syntax: " .. tablesToCheck[i] .. ".")
end
end
return true
end
XML:
<globalevent name="trackitems" type="start" event="script" value="trackitems.lua"/>
SQL:
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'serial'
FROM player_items
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
And you can see items with duplicated serials with the following commands:
SQL:
--Use this command to see duplicated items on players inventory
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'duplicated serials'
FROM player_items
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (
SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_items
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >1
)
--Use this command to see duplicated items on players inventory or depot items
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'duplicated serials'
FROM player_items
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (
SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_depotitems
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >1
)
--Use this command to see duplicated items on players depots
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 ) AS 'duplicated serials'
FROM player_depotitems
WHERE SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
IN (
SELECT SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
FROM player_depotitems
WHERE CONVERT( attributes
USING latin1 ) LIKE '%serial%'
GROUP BY SUBSTRING( CONVERT( attributes
USING latin1 )
FROM 18 )
HAVING COUNT( * ) >1
)
Note that you can change the table 'player_items' to 'player_depotitems' to get info about items on depot
Please, comment with constructive criticism !
Rep++ is appreciated!
Last edited: