Adding Consumable Items to Your World

From Multiverse

Jump to: navigation, search
The code in this article or section has not been verified with Multiverse platform version 1.5. You can help by testing it, and rewriting as necessary.

This tutorial will cover adding consumable items, for example potions, to your world.

Contents

Setup

For this tutorial we are going to modify the Sample World as provided by Multiverse. You will need access to the following files: Ability_db.py and Templates.py

Both files are located in multiverse\config\sampleworld.


Define an Ability

A consumable item is simply a way to get a single activation of an ability generally without the need of other player resources (such as mana or money). So, to create a new type of potion the first thing we need to do is define what ability the potion will perform. For this tutorial we are going to create a potion that instantly heals the player and then adds a heal over time effect for a few seconds. We shall call it: Renew.

Creating an ability to be used from an item is a two step process. First, an effect must be created. Our effect is a combination of the heal and regen effects. Add the following to ability_db.py:

effect = HealEffect("renew effect");
effect.setMinInstantHeal(40);
effect.setMaxInstantHeal(40);
effect.setMinPulseHeal(10);
effect.setMaxPulseHeal(10);
effect.isPersistent(True);
effect.isPeriodic(True);
effect.setDuration(20000);
effect.setNumPulses(10);
Mars.EffectManager.register(effect.getName(), effect); 

This will instantly heal the player for 40 hit points, followed by 10 ticks of 10 hit points each spread out over 20 seconds.

Next, in order to access the effect from a potion, a new ability needs to be created (also in ability_db.py):

ability = EffectAbility("renew potion");
ability.setTargetType(MarsAbility.TargetType.SELF);
ability.setActivationEffect(Mars.EffectManager.get("renew effect"));
ability.addCooldown(Cooldown("GLOBAL", 1500));
ability.addCooldown(Cooldown("POTION", 15000));
Mars.AbilityManager.register(ability.getName(), ability); 

This creates a new ability that lets us access the renew effect via a potion.

Define an Item

Switch to templates.py. Now we are going to create a potion item that can be used by the player to heal herself. Towards the bottom, add:

item = Template("Renew Potion")
item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
         "Interface\FantasyWorldIcons\ITEM_potion_A")
item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ACTIVATE_HOOK,
         AbilityActivateHook("renew potion"))
ObjectManagerClient.registerTemplate(item)

This adds a new consumable called the Renew Potion, which, when used, will activate the renew potion ability (note the capitalization difference – very important!).

Restart the Server and Go Pick a Fight!

But before picking a fight, let’s create for ourselves one of these new potions. In the client window:

/createitem Renew Potion

Again, note the capitalization.

If all goes well, the character will notify us that an item was created, and it will appear in her backpack (hit 'b' to access the backpack). Congrats! Now go kill some wolves with the peace of mind that if the battle starts to take a turn for the worse you’ll be able to quickly heal yourself and keep your hit points high with a single swig of this new potion.

Personal tools