• 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)

Short tutorial

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?
Um?
Varchar size limit 255 letters [default] (can be set higher. but use much more space on HDD, empty attributes = 257 bytes)
BLOB - ~65.000 letters (use number of letters + 2 bytes on HDD, empty attributes = 2 bytes)
MySQL :: MySQL 5.0 Reference Manual :: 10.5 Data Type Storage Requirements
I think that save time can be much higher if you save for example 20.000 items (~200 players online) ... if they store many items in depot then.....

IT IS POSSIBLE TO SET ANY ATTRIBUTE ON ITEM. YOU CAN SET IN DESCRIPTION 'Owner is Nick OF Player' and set attribute itemowner = GUID and/or transactionid = xxx
For tests use on GOD this:
/attr set itemowner 33

How to read attributes with PHP:
PHP:
$a = $SQL->query('SELECT `attributes` FROM `player_items` WHERE `player_id` = 20 AND `itemtype` = 2050')->fetch();
// select item with some attributes for test
for($l = 0; $l < strlen($a['attributes']); $l++)
	if(ord($a['attributes'][$l]) >= 32 && ord($a['attributes'][$l]) <= 126)
		echo htmlspecialchars($a['attributes'][$l]);
	else
		echo '- ' . htmlspecialchars(ord($a['attributes'][$l])) . ' -';
(list of ascii chars: ASCII – Wikipedia, wolna encyklopedia , some of them script shows as number, because they are not possible to display)
With my item it shows:
- 128 -- 8 -- 0 -- 1 -- 0 -- a -- 1 -- 0 -- 0 -- 0 -- 0 -- 2 -- 0 -- a -- a -- 1 -- 18 -- 0 -- 0 -- 0 -- f -- g -- h -- g -- f -- h -- f -- g -- h -- 2 -- 3 -- d -- f -- g -- d -- f -- g -- j -- " -- 0 -- a -- d -- s -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- d -- 1 -- 3 -- 0 -- 0 -- 0 -- s -- d -- s -- 3 -- 0 -- a -- i -- d -- 2 -- 220 -- 5 -- 0 -- 0 -- 2 -- 0 -- b -- b -- 1 -- 17 -- 0 -- 0 -- 0 -- f -- g -- h -- g -- f -- h -- f -- g -- h -- 2 -- 3 -- d -- f -- g -- d -- f -- g -- 8 -- 0 -- d -- e -- c -- a -- y -- i -- n -- g -- 2 -- 0 -- 0 -- 0 -- 0 -- 8 -- 0 -- d -- u -- r -- a -- t -- i -- o -- n -- 2 -- 160 -- 140 -- 0 -- 0 -- 9 -- 0 -- i -- t -- e -- m -- o -- w -- n -- e -- r -- 2 -- ! -- 0 -- 0 -- 0 -
How to read [you must read it letter by letter]:
128 - skip it, start attributes
-----
8 - number of attributes
0 - number of attributes [ 8 and 0 should be read as one 16 bit number ]
-----
1 - next number of letters
0 - next number of letter [ 1 and 0 should be read as one 16 bit number ]
--
a - this is this '1 letter', it's 'odd' attribute, so it define name of attribute, after it is value
--
1 - value of attribute will be text [if 2 then value is number], now read 4 letters to get number of value letters
18 - number of value letters [18 *1]
0 - number of value letters [0 * 256]
0 - number of value letters [0 * 65536]
0 - number of value letters [0 * 16777216]
--
Now we read next 18 character - this is value of attribute 'a':
- f -- g -- h -- g -- f -- h -- f -- g -- h -- 2 -- 3 -- d -- f -- g -- d -- f -- g -- j -
-----
(" - it's character number 34 in ascii, to read values valid, you should use in php function 'ord' on each letter, i didn't do it to show you some 'human letters')
" - number of letters
0 - number of attributes [ " and 0 should be read as one 16 bit number ]
adsddddddddddddddddddddddddddddddd - these are our 34 letter, it's attribute name [odd attribute]
--
1 - attribute value is text
3 - 3 letters
0 - number of letters [should read 3 * 1 + 0 * 256 + 0 * 65536 + 0 * 16777216]
0 - number of letters [should read 3 * 1 + 0 * 256 + 0 * 65536 + 0 * 16777216]
0 - number of letters [should read 3 * 1 + 0 * 256 + 0 * 65536 + 0 * 16777216]
sds - our letters, value of attritube 'adsddddddddddddddddddddddddddddddd'
-----
3 - number of letters
0 - number of letters
aid - our letters, attribute name
--
2 - attribute value IS NUMBER (32 bit)
220 - our number, not number of 'number letters'!
5 - our number, not number of 'number letters'!
0 - our number, not number of 'number letters'!
0 - our number, not number of 'number letters'!
(Action id of this item is 1500, how to read from database? 220 * 1 + 5 * 256 + 0 * 65536 + 0 * 16777216 = 1500, wow! ;) )


.........
I hope some of you will understand how to read binary data. If not, it's not a problem, because in my new acc. maker will be classes to load items and their attributes ($item->getAttribute('decay') etc.), but they will be not optimized to load duplicated items, so you need own script to find them in few seconds (not few hours, PHP sort functions are hundreds times slower they mysql 'order' and 'where' functions).

EDIT:
I forgot to post that 1 letter = 8 bits, letter 'number value' can be 0 - 255, so when we read 32 bit number, we read 4 letters (4 x 8 bits).
 
Last edited:
If you don't know how to read attributes of items you can use my class:
PHP:
$attributes = new ItemAttributes($itemAttributesFromDatabaseQuery);
if($attributes->hasAttribute('name'))
    echo $attributes->getAttribute('name');
Class:
PHP:
class ItemAttributes
{
	public $attributes = array();
	public $attributesCount = 0;
	public $attrString = '';

	public function __construct($attributes)
	{
		$this->loadAttributes($attributes);
	}

	private function getByte()
	{
		$ret = ord($this->attrString[0]);
		$this->attrString = substr($this->attrString, 1);
		return $ret;
	}

	private function getU16()
	{
		$ret = ord($this->attrString[0]) + ord($this->attrString[1]) * 256;
		$this->attrString = substr($this->attrString, 2);
		return $ret;
	}

	private function getU32()
	{
		$ret = ord($this->attrString[0]) + ord($this->attrString[1]) * 256 + ord($this->attrString[2]) * 65536 + ord($this->attrString[3]) * 16777216;
		$this->attrString = substr($this->attrString, 4);
		return $ret;
	}

	private function getString($length)
	{
		$ret = substr($this->attrString, 0, $length);
		$this->attrString = substr($this->attrString, $length);
		return $ret;
	}

	public function loadAttributes($attributes)
	{
		$this->attrString = $attributes;
		if(!empty($this->attrString) && $this->getByte() == 128)
		{
			$this->attributesCount = $this->getU16();
			$s = array();
			while(!empty($this->attrString))
			{
				$key = $this->getString($this->getU16());
				$dataType = $this->getByte();
				if($dataType == 1)
					$value = $this->getString($this->getU32());
				elseif($dataType == 2)
					$value = $this->getU32();
				$this->attributes[$key] = $value;
			}
		}
	}

	public function getAttributes()
	{
		return $this->attributes;
	}

	public function getAttributesList()
	{
		return array_keys($this->attributes);
	}

	public function hasAttribute($attributeName)
	{
		return isset($this->attributes[$attributeName]);
	}

	public function getAttribute($attributeName)
	{
		if(!$this->hasAttribute($attributeName))
			throw new Exception(__METHOD__ . ' - Attribute: ' . htmlspecialchars($attributeName) . ' - does not exist!');

		return $this->attributes[$attributeName];
	}
}
 
Last edited:
Sorry for reliving the old topic, but i need some help.
In my server, boots vip, for sample, is ID 2641, and to delete all cloned boots vip, i want to use a mysql code that delete the items 2641 that has attributes = [BLOB - 0Bytes]
i made a script like this:
DELETE FROM player_items WHERE itemtype = 2641 AND 'attributes' = '[BLOB - 0Bytes]'
but it doesn't work, (deletes 0 lines)
can anybody help me to make a script to do that?
and, if i'm not abusing, the script may delete from player_items, player_depotitems, tile_items ?
 
Sorry for reliving the old topic, but i need some help.
In my server, boots vip, for sample, is ID 2641, and to delete all cloned boots vip, i want to use a mysql code that delete the items 2641 that has attributes = [BLOB - 0Bytes]
i made a script like this:

but it doesn't work, (deletes 0 lines)
can anybody help me to make a script to do that?
and, if i'm not abusing, the script may delete from player_items, player_depotitems, tile_items ?
Query:
DELETE FROM player_items WHERE itemtype = 2641 AND length(`attributes`) = 0
 
If you don't know how to read attributes of items you can use my class:
PHP:
$attributes = new ItemAttributes($itemAttributesFromDatabaseQuery);
if($attributes->hasAttribute('name'))
    echo $attributes->getAttribute('name');
Class:
PHP:
class ItemAttributes
{
	public $attributes = array();
	public $attributesCount = 0;
	public $attrString = '';

	public function __construct($attributes)
	{
		$this->loadAttributes($attributes);
	}

	private function getByte()
	{
		$ret = ord($this->attrString[0]);
		$this->attrString = substr($this->attrString, 1);
		return $ret;
	}

	private function getU16()
	{
		$ret = ord($this->attrString[0]) + ord($this->attrString[1]) * 256;
		$this->attrString = substr($this->attrString, 2);
		return $ret;
	}

	private function getU32()
	{
		$ret = ord($this->attrString[0]) + ord($this->attrString[1]) * 256 + ord($this->attrString[2]) * 65536 + ord($this->attrString[3]) * 16777216;
		$this->attrString = substr($this->attrString, 4);
		return $ret;
	}

	private function getString($length)
	{
		$ret = substr($this->attrString, 0, $length);
		$this->attrString = substr($this->attrString, $length);
		return $ret;
	}

	public function loadAttributes($attributes)
	{
		$this->attrString = $attributes;
		if(!empty($this->attrString) && $this->getByte() == 128)
		{
			$this->attributesCount = $this->getU16();
			$s = array();
			while(!empty($this->attrString))
			{
				$key = $this->getString($this->getU16());
				$dataType = $this->getByte();
				if($dataType == 1)
					$value = $this->getString($this->getU32());
				elseif($dataType == 2)
					$value = $this->getU32();
				$this->attributes[$key] = $value;
			}
		}
	}

	public function getAttributes()
	{
		return $this->attributes;
	}

	public function getAttributesList()
	{
		return array_keys($this->attributes);
	}

	public function hasAttribute($attributeName)
	{
		return isset($this->attributes[$attributeName]);
	}

	public function getAttribute($attributeName)
	{
		if(!$this->hasAttribute($attributeName))
			throw new Exception(__METHOD__ . ' - Attribute: ' . htmlspecialchars($attributeName) . ' - does not exist!');

		return $this->attributes[$attributeName];
	}
}

Really it's perfect :D:D
 
Sorry for reliving the old topic, but i need some help.
In my server, boots vip, for sample, is ID 2641, and to delete all cloned boots vip, i want to use a mysql code that delete the items 2641 that has attributes = [BLOB - 0Bytes]
i made a script like this:

but it doesn't work, (deletes 0 lines)
can anybody help me to make a script to do that?
and, if i'm not abusing, the script may delete from player_items, player_depotitems, tile_items ?

I think that the cloned items will heave the same description of the original items, so this is not a way to delete cloned items, u heave to list all items with teh same description, and u never will know waht item is the original and what is the clone.
 
When I put
Code:
SELECT `player_id`,`pid`,`sid`,CONVERT(  `attributes` USING latin1 ) FROM  `player_items` WHERE CONVERT(  `attributes` USING latin1 ) LIKE '%description%'
, some symbols appear mad as I can fix this?
 
[Error - LuaScriptInterface::loadFile] data/globalevents/scripts/shop.lua:76: 'end' expected (to close 'function' at line 7) near '<eof>'
[Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/shop.lua)
data/globalevents/scripts/shop.lua:76: 'end' expected (to close 'function' at line 7) near '<eof>'

How to fix it?
 
SELECT `player_id`,`pid`,`sid`,CONVERT( `attributes` USING latin1 ) FROM `player_items` WHERE CONVERT( `attributes` USING latin1 ) LIKE '%description%'

i have problem too , i need help

only see symbols
 
I get this error when, it's gives item but not with name nor ID

07:36 You see an Archers Necklace (distance fighting +2).
It weighs 12.20 oz.
1613306202764.png
 
Back
Top