HowToAddItemsStendhal: Difference between revisions
imported>Hendrik Brummermann point to other nav bar |
imported>Kymara m Move extendors to extenders |
||
| Line 1: | Line 1: | ||
{{Navigation for Stendhal Top}} |
{{Navigation for Stendhal Top}} |
||
{{Navigation for Stendhal |
{{Navigation for Stendhal Extenders}} |
||
You can add new item to game in a few very simple steps: |
You can add new item to game in a few very simple steps: |
||
Revision as of 22:08, 1 November 2009
You can add new item to game in a few very simple steps:
Edit items.xml
Download stendhal-0.xx-src.tar.gz from the stendhal-website and unpack it. All items.xml files are located in the /data/conf/items/ directory. They are arranged according to class (see below) such as shields, swords, keys, food, etc. The file contains all the description of the items in game. Lets start with how to do weapons, for example in swords.xml:
<item name="dagger">
<type class="sword" subclass="dagger" tileid="-1"/>
<description>You see a dagger, it is little more than decorative but you can jab pretty fast with it.</description>
<implementation class-name="games.stendhal.server.entity.item.Item"/> <attributes>
<atk value="8"/>
<rate value="3"/>
</attributes>
<weight value="0.2"/>
<value value="8533"/>
<equipable>
<slot name="bag"/>
<slot name="lhand"/>
<slot name="rhand"/>
</equipable>
</item>
It is important to understand how it works.
We must give a name to the item and it is done in the item tag. Then we specify the class and the subclass on the type tag. If you check the way sprites are structure at client you will realize that it is in a similar fashion to:
sprites/
items/
class/
subclass.png
This way we can reuse a single GFX for different items. For example: knife+1, old knife, elvish knife, ... We give the item a nice description (for when the player does Look) inside the description tag.
The implementation tag should be copied from above, unless the item is stackable, in which case use:
<implementation class-name="games.stendhal.server.entity.item.StackableItem"/>
Inside the attributes tag you can specify the attributes the weapon has:
- ATK it is a value proportional to the damage the item can do.
- DEF it is a value proportional to how much damage the item can block.
- RATE is how fast you can hit with an offensive weapon.
- RATE 1 means you can hit every turn, RATE 10 means only once every 10 turns.
- RATE must be greater than 0 but has no upper limit. (In stendhal the slowest rate weapon we have is 15)
- Only offensive weapons have a rate.
- RANGE is an attribute of attack - from - a - distance weapons like bow and arrow, or projectiles like spears.
- The larger the range the further the weapon is effective from.
- QUANTITY is an attribute for stackable weapons like arrows and spears (set to 1)
- LIFESTEAL is a special attribute for offensive weapons.
- It must be a number between -1 and 1.
- Any attack damage caused by a lifesteal weapon is 'refunded' to the player as healing HP
- A weapon with lifesteal 0.2 returns 20% HP to player of the damage they cause their enemy.
- Negative lifesteal drains the HP of a player according to the damage they cause their enemy.
For foods, drinks, potions and poisons the attributes are:
- AMOUNT - the total HP which the item restores (negative for poisonous items)
- REGEN - how much you are healed at a time (for potions this should be equal to AMOUNT, for poisons should be negative)
- FREQUENCY - how fast you are healed (lower number means faster, choose 1 for potions)
- QUANTITY - should be used (set to 1) they are all stackable items.
Note that potions and poisons (and antidotes) go in the drinks class. Antidotes have:
- AMOUNT - how long they protect you from poison (e.g. antidote is 400, greater is 800)
- REGEN equal to 0
- FREQUENCY equal to 1
- QUANTITY equal to 1
For scrolls, most of which are teleport scrolls, follow the examples in scrolls.xml for what implementation to use. The attribute INFOSTRING for marked scrolls is the destination of the scroll, e.g.
<infostring value="0_nalwor_city 40 60"/>
For summon scrolls the INFOSTRING is the creature name, but the implementation
<implementation class-name="games.stendhal.server.entity.item.scroll.SummonScroll"/>
takes care of this, so you do not set it.
That should be all the special items dealt with. Many items (e.g. herb, key, wood, money) would have no attributes, or no attributes except quantity.
Finally you need to specify where the item can be equipped:
- rhand
- lhand
- armor
- head
- legs
- cloak
- finger
- feet
- keyring
- bag
All items should be equippable in bag, unless you have a good reason that players shouldn't be allowed to carry them. All stackable items should be equippable in rhand and lhand in case the player wants to split stacks. And although in stendhal we have the drawing of where the shield and sword should go on the character window, we do allow players to equip shield, and weapon in either hand. Rings go on the finger, but also in keyring and and bag for ease of carrying.
Add GFX
Now place the 32x32 sprite in the folder data/sprites/items/<class>/<subclass>.png
See also How to know graphics specifications for items
If you want your item image animated (like money) simply make a 32N x 32 sprite. E.g. if it has 5 frames in the animation it will be a 160 x 32 sprite. It will automatically appear animated.
Register the class
Usually you need to register your item class unless it really does nothing. If you're adding an item which is like what we already have (i.e. just a new shield) it's done for you, the shield class is registered. Add your item to the rest in src/games/stendhal/client/entity/EntityMap.java
register("item",null,Item.class);
register("item","book",Book.class);
register("item","food",StackableItem.class);
register("item","drink",StackableItem.class);
register("item","money",StackableItem.class);
register("item","projectiles",StackableItem.class);
Add to game
Creatures can drop items, see HowToAddCreaturesStendhal. Perhaps you will want your NPC to equip the player with an item as part of a quest, see HowToCreateQuests or an NPC to sell the item. For the latter you will need to understand NPC seller behaviour which should be covered separately. Until that is done, look at Seller examples such as Margaret in Semos Tavern in your source code.
You may wish to add items to a map (for player to pick up or harvest). You can either add to zone by creating a java file (good for one - off items like the poison and scroll of Haizen's table in his hut) or add using tiled which is more work initially but allows you to add to the objects layer in tiled again and again in future. (Good for iron ore to collect from the ground, herbs etc). This needs a whole tutorial on spawners (also knows as growers), please see HowToAddGrowers.