How to make charged items usable once a week/day/month?

For builders to discuss and ask building questions.
Post Reply
Dalvyn
Sword Grand Master
Sword Grand Master
Posts: 4708
Joined: Tue Jul 15, 2003 9:26 pm
Location: House of Wonder, Waterdeep

How to make charged items usable once a week/day/month?

Post by Dalvyn » Tue Aug 05, 2003 11:40 pm

When you describe items (in the area file), there are 6 values that need to be set (according to the type of items). For example, for weapons, you set the WEAPON_TYPE_? there; for containers, you set the container flags (can be closed? locked?) and the container capacity there. For all item types, the last value is not used for these settings and, thus, can be used to code charged items.

These six values are numbered from 0 to 5: VALUE0, VALUE1, VALUE2, VALUE3, VALUE4, and VALUE5. Therefore, the value you can use for charged items is VALUE5. There is an if-check associated to it: if objval5($o) == 3 (to check the value) and commands used to set it: mposet $o value5 1 or mpoadd $o value5 1.

Two things to remember here: if the item is on the mob who executes the program (this mob is generally the supermob, as he executes all object progs), you can use mposet $o value5 1. But, if the item is in someone else's inventory (let's say in $n's inventory), you have to use mposet on $n $o value5 1 (or mpoadd on $n $o value5 1).

Here is an example for a 'ring of fly' that can be used once per month (its vnum is iVNUM).

Code: Select all

>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.

Code: Select all

>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.
Lorelie

Post by Lorelie » Sat Oct 25, 2003 5:28 pm

I would like to make an item that adds X amount of a list of items once a day.

The item is a container. Say I have a list of items A B C D E that I want a random chance of appearing in this container to a maxium of 10 once a day.

How would a prog for something like this look in general?

And for a second question. I would also like to add a prog to an item that will allow you to cast a certain spell X times per day.

How would that look?
Dalvyn
Sword Grand Master
Sword Grand Master
Posts: 4708
Joined: Tue Jul 15, 2003 9:26 pm
Location: House of Wonder, Waterdeep

Post by Dalvyn » Sat Oct 25, 2003 6:07 pm

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.

Code: Select all

>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 
~
Dalvyn
Sword Grand Master
Sword Grand Master
Posts: 4708
Joined: Tue Jul 15, 2003 9:26 pm
Location: House of Wonder, Waterdeep

Post by Dalvyn » Sat Oct 25, 2003 6:22 pm

Lorelie wrote:The item is a container. Say I have a list of items A B C D E that I want a random chance of appearing in this container to a maxium of 10 once a day.
You will not be able to put things in a container that a PC is holding/carrying, but you can have those things appear in the PC's inventory.

In the programs above, you would need to replace 3 with 10 (the number of charges) and replace the echoes and "cast fly $n" with the following code.

Code: Select all

if rand(20)
  mpoload Avnum
  mpgive iAvnum $n
  mpechoat $n A "A" appears in your hand.
else
  if rand(25)
    mpoload Bvnum
    mpgive iBnum $n
    mpechoat $n A "B" appears in your hand.
  else
    if rand(33)
      mpoload Cvnum
      mpgive iCvnum $n
      mpechoat $n A "C" appears in your hand.
    else
      if rand(50)
        mpoload Dvnum
        mpgive iDvnum $n
        mpechoat $n A "D" appears in your hand.
      else
        mpoload Evnum
        mpgive iEvnum $n
        mpechoat $n A "E" appears in your hand.
      endif
    endif
  endif
endif
Post Reply