01. Make healing potion So to make healing potin you need just to create new item in editor. Assign him some icon (flashblue is ok) and Enter code to onUse event. If you want to heal Hitpoints you will use parameter HP of beeing. (Magic points MP, Stamina SP).
Entered code will be something like this:
actor.add("HP",rnd2(10));
It's easy, but how it works? actor is root value, which points to acting beeing. When you call onUse, it's allways after Use action so there is always some actor. add is function of class beeing, which adds some points to this beeing and handle all visual updates.
ok. So we used item, but when we use this code it dosn't disapear. So we created fountain of life and player can heal with this item forever. That's probably not waht we wants. So we must destroy item. When we look in
item.class
, there is function drop. Good, but how to find out which item it's? It's easy. It's this item, that means that there is parameter this, which is setted for every event to existing object, which is owning this event. In our case, we can do this : actor.add("HP",rnd2(10));
this.drop();
And it will work. From version 1.2 of dd2lang is this one of default roots to try find function, so you can call only drop(); and it will also work. Life is internaly calledone of parameters o
see
02. Create spell & declare function Ok, you want to create spell named Tara. This spell will have some special effect. Let's start from this.
$tar=fight.target;
if (rnd2($tar.getResists("EARTH"))>rnd2(spell.might)) {
$tar.hurt(spell.power*5);
$tar.addEffect('TARA','ACU-5',spell.power*10,'tara.gif');
}
This will try to get through beeings EARTH resistance with spell.might. If it's success, it hurts beeing and add effect, names TARA, which decrease Accuracy for some time. If you want to have this effect on group of monsters it will be better to make function Tara. function doTara(beeing $tar,var $might, var $power) {
if (rnd2($tar.getResists("EARTH"))>rnd2($might)) {
$tar.hurt($power*5);
$tar.addEffect('TARA','ACU-5',$power*10,'tara.gif');
return (@true);
}
return (@false);
}
if (! doTara(spell.target,spell.might,spell.power))
doTara(spell.caster,spell.might,spell.power);
So we have function doTara which must be called with there parameters, where first must be class beeing and two rest must be some text of numbers. When some one cast this spell and it dosn't hurt mosnter, it's casted back to castor. Ugly spell. But when we place all this code to onCast for spell named "Tara's ray", function doTara can't be accessed by any other spell, because it's only local function, which disappear after process of onCast our spell. And if we want to create spell "Tara's cloud", it will be nice to have this function globally defined. For this we can place all code of doTara to file <game dir>/def/functions.dd2 or we can add it to global functions in dd2editor.
Related classes
spell.class
see
Generated by Hideoshi's Documentation Tool on 28.10.2003 20:08:52