• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent shop.lua with player name in item description (for website shop)

PhoOwned

^_^
Joined
Nov 11, 2010
Messages
375
Reaction score
66
Maybe someone else need it. It can be useful if you want find cloned items.
It add in description of all items (also in containers) name of player that buy item and unique ID of shop system transaction ^_^
example said:
22:13 You see an earthborn titan armor (Arm:15, axe fighting +2, protection physical +5%, earth +3%).
It can only be wielded properly by knights of level 90 or higher.
It weighs 120.00 oz.
Bought by [Owner] Ohyeah [ID:334].
../data/globalevents/scripts/shop.lua
Lua:
-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 19
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###
function onThink(interval, lastExecution)
    local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
    if(result_plr:getID() ~= -1) then
        while(true) do
            id = tonumber(result_plr:getDataInt("id"))
            action = tostring(result_plr:getDataString("action"))
            delete = tonumber(result_plr:getDataInt("delete_it"))
            cid = getCreatureByName(tostring(result_plr:getDataString("name")))
            if isPlayer(cid) == TRUE then
                local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
                local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
                local container_id = tonumber(result_plr:getDataInt("param3"))
                local container_count = tonumber(result_plr:getDataInt("param4"))
                local add_item_type = tostring(result_plr:getDataString("param5"))
                local add_item_name = tostring(result_plr:getDataString("param6"))
                local received_item = 0
                local full_weight = 0
                if add_item_type == 'container' then
                    container_weight = getItemWeightById(container_id, 1)
                    if isItemRune(itemtogive_id) == TRUE then
                        items_weight = container_count * getItemWeightById(itemtogive_id, 1)
                    else
                        items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                    full_weight = items_weight + container_weight
                else
                    full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    if isItemRune(itemtogive_id) == TRUE then
                        full_weight = getItemWeightById(itemtogive_id, 1)
                    else
                        full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                end
                local free_cap = getPlayerFreeCap(cid)
                if full_weight <= free_cap then
                    if add_item_type == 'container' then
                        local new_container = doCreateItemEx(container_id, 1)
						doItemSetAttribute(new_container, "description", 'Bought by ' .. getCreatureName(cid) .. ' [ID:' .. id .. '].')
                        local iter = 0
                        while iter ~= container_count do
							local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
							doItemSetAttribute(new_item, "description", 'Bought by ' .. getCreatureName(cid) .. ' [ID:' .. id .. '].')
							doAddContainerItemEx(new_container, new_item)
                            iter = iter + 1
                        end
                        received_item = doPlayerAddItemEx(cid, new_container)
                    else
                        local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
						doItemSetAttribute(new_item, "description", 'Bought by ' .. getCreatureName(cid) .. ' [ID:' .. id .. '].')
                        received_item = doPlayerAddItemEx(cid, new_item)
                    end
                    if received_item == RETURNVALUE_NOERROR then
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
						doPlayerSave(cid)
                        db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                        db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                    else
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
                    end
                else
                    doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
                end
            end
            if not(result_plr:next()) then
                break
            end
        end
        result_plr:free()
    end
    return TRUE
end
 
Last edited:
So how do we detect duped items? It isn't possible via query(BLOB)
 
Read all items from database
PHP:
, unpack attributes, get special description and get duplicated IDs of transaction xD
 
Read all items from database
PHP:
, unpack attributes, get special description and get duplicated IDs of transaction xD[/QUOTE]
 They're stored in a BLOB in db, elf never told me how to unpack them ;|
 
My uncle Google told me what to do when I asked him 'blob to string php':
PHP:
SELECT CONVERT(`attributes` USING latin1) FROM `player_items` WHERE CONVERT(`attributes` USING latin1) LIKE '%description%'
It will return items with special description.
On my dedic it took 0.0553 sec on 66k items database and 0.3184 sec on 350k items.
example result said:
€armor  description2Helmet of everlutions.net dominator! Won in event.namehorned helmet +6
Now simple preg math and you get items with same [ID: x]
 
mind showing a screenshot? I might release an antidupe system them
 
Screenshot like this?
bloblresult.PNG

Of course you have to use query like:
PHP:
SELECT `player_id`,`pid`,`sid`,CONVERT(  `attributes` USING latin1 ) FROM  `player_items` WHERE CONVERT(  `attributes` USING latin1 ) LIKE '%description%'
to get informations what items you should remove.
 
Last edited:
@CyberM
Care, because some items in sms shop may have 'duration' which will be stored in attributes too [isn't there when you add item, it appear when player use item first time], so there can appear new attributes.
 
Yes, anti-dupe system only detects items after they get the id attribute and if there is more than 1 item with same id.
I'm thinking in adding unix os.time as attr but I guess that can be duplicated too(to detect the really duped items with an newer time)
 
Last edited:
People only copy donation items (i think). Every shop transaction has unique ID in database, so it's easy to detect. You can check item owner ID and nick of player that bought it and remove if duplicated item has other player ^^
 
People only copy donation items (i think). Every shop transaction has unique ID in database, so it's easy to detect. You can check item owner ID and nick of player that bought it and remove if duplicated item has other player ^^
Player can sell or give away donated items, and in most donation systems players can donate and make other player to receive the item. But with two items with same ID, how to detect which is duped and which is the original since both have same attributes?
 
If player set other player as 'receiver' in shop system, then on item will be his name, not name of player that paid for item.

In most cases both items are on one player (backpack) or one in depot and second in backpack, so you only have to remove one duplicated item.
 
If player set other player as 'receiver' in shop system, then on item will be his name, not name of player that paid for item.

In most cases both items are on one player (backpack) or one in depot and second in backpack, so you only have to remove one duplicated item.
That's ok, but duped items can be stored in player's houses too, I'm just looking for an efficient and direct way to auto-detect and delete duped items with a globalevent, check this pic) But I guess it's enough with detecting duped items and deleting ALL(original and duped ones)
 
Can someone release this script for modernaac plax.

Here my shop.lua
Lua:
function onThink(interval, lastExecution, thinkInterval)

	local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
	
		if(result:getID() ~= -1) then
			while(true) do
				cid = getCreatureByName(tostring(result:getDataString("player")))
				product = tonumber(result:getDataInt("product"))
				itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
					if isPlayer(cid) then
						local id = tonumber(itemr:getDataInt("item"))
						local tid = tonumber(result:getDataInt("id"))
						local count = tonumber(itemr:getDataInt("count"))
						local tipe = tonumber(itemr:getDataInt("type"))
						local productn = tostring(itemr:getDataString("name"))
							if isInArray({5,8},tipe) then
								if getPlayerFreeCap(cid) >= getItemWeightById(id, count) then
									if isContainer(getPlayerSlotItem(cid, 3).uid) then
										received = doAddContainerItem(getPlayerSlotItem(cid, 3).uid, id,count)
										if received then
											doPlayerSendTextMessage(cid,19, "You have received >> "..productn.." << from our shop system")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										else
											doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space on container to receive >> "..productn.." <<")
										end
									else
										doPlayerSendTextMessage(cid,19, "Sorry, you don't have a container to receive >> "..productn.." <<")
									end
								else
									doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
								end
							elseif isInArray({6,7},tipe) then
									if tipe == 6 then
										bcap = 8
										bid = 1987
									elseif tipe == 7 then
										bcap = 20
										bid = 1988
									end
									if isItemRune(id) then
										count = 1
									end
									if getPlayerFreeCap(cid) >= (getItemWeightById(1987, 1) + getItemWeightById(id,count * bcap)) then
										local bag = doCreateItemEx(bid, 1)
											for i = 1,bcap do
												doAddContainerItem(bag, id, count)
											end
										received = doPlayerAddItemEx(getPlayerSlotItem(cid, 3).uid, bag)
										if received == RETURNVALUE_NOERROR then
											doPlayerSendTextMessage(cid,19, "You have received >> "..productn.." << from our shop system")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										else
											doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space to receive >> "..productn.." <<")
										end
									else
										doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
									end
							end
					end
				itemr:free()
				if not(result:next()) then
					break
				end
			end
			result:free()
		end
	return true
end
 
CyberM try to make the item equipable only to the owner, is not the owner, can't equip, this will be a lot of help with dupe items (one reason less to player do dupe items)

in other case, duplicated items with same id will be more easy to find

another example if a player buy an armor for give to another player, the armor will belong to the receiver player, and only that player can use or equip it
 
well, i changed my attributes table structure in player_items and player_depotitems from BLOB to VARCHAR 255 and it it showing the new description of itens with serial number and other infos ive added (like hour and day) without needing to run the queries. May i have problem with this or its a good solution?
 
Back
Top