builder's lessons » charged magical objects
Charged magical objects
Value5 on an object is not used by any of the objects to set the fields specific to the ITEM_TYPE's. This makes it ideal to use in magical objects that you want to have a limited life or limited charges. You can modify value5 with each use of the object, and then when value5 of the object reaches a certain point, then the item has run out of magical charges, or it is destroyed. This allows builders to be able to put some rather powerful magical items into the game without unbalancing it.
Below is a sample of a ring, that when a command word is typed by the PC allows the PC to fly. If the ring has charges then the PC will fly.
>intercept_prog ringcommandword~ if wear_loc($o) != -1 if objval5($o) == 0 cast 'fly' $n mposet on $n iVNUM value5 1 mpechoat $n You rise in the air. mpechoaround $n $N rises in the air. else mpechoat $n Nothing happens. mpechoat $n Perhaps the ring needs to be recharged? endif else mpechoat $n You should wear the ring first. endif ~ >time_prog 10~ if day() == 20 if objval5($o) != 0 mpechoat $n Your ring glows briefly as it is recharged. mposet on $n iVNUM value5 0 endif endif ~
If you want the user to know whether the ring is charged or not, you could add an exa_prog to the ring.
>exa_prog 100~ if objval5($o) == 0 mpechoat $n The ring glows faintly. else mpechoat $n The ring does not glow. endif ~
The echoes in the exa_prog will appear after the extra description of the ring, if it has any.
Here is an example for a ring that would enable the user to cast fly three times per day.
In this case, value5 is the number of charges left on the ring (it needs to be set to 3 in the object description if you want the ring to be fully charged when it is loaded). The object is recharged each day at 10am.
>intercept_prog ringcommandword~ if wear_loc($o) != -1 if objval5($o) == 0 mpechoat $n Nothing happens. mpechoat $n Perhaps the ring needs to be recharged? else cast 'fly' $n mpoadd on $n iVNUM value5 -1 mpechoat $n You rise in the air. mpechoaround $n $N rises in the air. endif else mpechoat $n You should wear the ring first. endif ~ >time_prog 10~ if objval5($o) < 3 mpechoat $n Your ring glows briefly as it is recharged. mposet on $n iVNUM value5 3 endif ~
Note that if the PC has the item in a container, then the time prog will not trigger for the object and the item will never recharge.