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