POT
POT
POT
Main menu

Download

Forum

SVN

Prev Next

Players

Tutorial for player-specific mechanisms.

Table of Contents

Players extras

Players are essential part of OTServ. They have the most additional things from all kind of objects and are connected with many other resources. Players belongs to accounts, groups, might belongs to guilds.

Skills

OTS_Player class contains everything you need to work with skills. You can get and set both skill values and skill advance tries. It is done with four methods:

Storage

There are also methods to manage custom storage values: getStorage() and setStorage(). Sotrage values are custom integer values that are assigned to player - they act like flags.

Items managing

POT provides also objective way for browsing/editing player items (body slots and depot items with all containers). You have OTS_Item and OTS_Container classes for that. OTS_Item represents single item, OTS_Container can contain sub-items (either OTS_Item objects, or next level OTS_Container objects).

There is important thing to mention - you have to have global items list resource loaded. POT reads item info for every item loaded from player.

Detailed API for managing items tree you will find in documentation of those classes. Here are examples of how you use slot and depot items fetching and saving:

  1. <?php
  2.  
  3. // to not repeat all that stuff
  4. include('quickstart.php');
  5.  
  6. // loads item typing information
  7. POT::getInstance()->loadItems('/path/to/your/ots/data/items');
  8.  
  9. // creates new player object
  10. $player new OTS_Player();
  11. $player->find('Wrzasq');
  12.  
  13. /*
  14.     Items loading example.
  15. */
  16.  
  17. // loading item from ammunition slot
  18. $item $player->getSlot(POT::SLOT_AMMO);
  19.  
  20. echo $player->getName()' has item with id '$item->getId()' in his/her ammo slot.'"\n";
  21.  
  22. // checks if item is a container
  23. if($item instanceof OTS_Container)
  24. {
  25.     // list backpack content
  26.     foreach($item as $inside)
  27.     {
  28.         echo 'Container contains item with id '$inside->getId()'.'"\n";
  29.     }
  30. }
  31.  
  32. /*
  33.     Items tree composing example.
  34. */
  35.  
  36. // creates container - here it would be a depot locker (we pass ID of item to create)
  37. $container new OTS_Container(2590);
  38.  
  39. // now let's create depot chest
  40. $chest new OTS_Container(2594);
  41.  
  42. // let's put chest inside locker
  43. $container->addItem($chest);
  44.  
  45. // now let's put something deeper - into the chest
  46. $item1 new OTS_Item(3015);
  47. $chest->addItem($item1);
  48.  
  49. // and more...
  50. $item2 new OTS_Item(3013);
  51. $chest->addItem($item2);
  52.  
  53. // let's set count for an item
  54. $item2->setCount(2);
  55.  
  56. /*
  57. Here is a tree of items which we created:
  58.  
  59. $container [depot locker]
  60. `-- $chest [depot chest]
  61.     |-- $item1 [first item inserted into chest]
  62.     `-- $item2 [second item inserted into chest] count=2
  63. */
  64.  
  65. /*
  66.     Items saving example.
  67. */
  68.  
  69. // now we simply put those items into players depot (2 is depot ID)
  70. $player->setDepot(2$container);
  71.  
  72. ?>

Important thing - OTS_Container class is subclass of OTS_Item. Each container is also an item.

Deleting

One part that is important to describe separately is deleting items from tree. If you wan't to delete item from container you have to pass it's instance to removeItem() method. It's instance! It means a reference to exacly same object - there might be more then one similar objects within container, you must point exacly which one you want to remove.


Prev Up Next
Accounts DAO objects Guilds