Difference between revisions of "Manual:DIL Manual/experience()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bpexp"></span>
+
= experience() =
−
experience ( i : integer, u : unitptr )
+
'''Procedure.''' Gives a player experience points, or takes them away.
−
    i : A integer number of experience to gain or loose.
 
−
    u : The player to receive the experience.
 
−
    result: The integer amount of experience is added to the players
 
−
            total amount of experience (thus causing more or less
 
−
            experience). USE WITH CARE! SUGGEST THAT YOU ONLY USE
 
−
            INTEGER CONSTANTS AS THE EXPRESSION TO AVOID ERRORS.
 
  
−
---~---~---~---~---~---~---~---~---
+
  experience(amount : integer, pc : unitptr)
−
<span id="bpexp"></span>
 
−
  experience ( i : integer, u : unitptr )
 
−
    i : A integer number of experience to gain or loose.
 
−
    u : The player to receive the experience.
 
−
    result: The integer amount of experience is added to the players
 
−
            total amount of experience (thus causing more or less
 
−
            experience). USE WITH CARE! SUGGEST THAT YOU ONLY USE
 
−
            INTEGER CONSTANTS AS THE EXPRESSION TO AVOID ERRORS.
 
  
−
---~---~---~---~---~---~---~---~---
+
Adds <code>amount</code> to the player's experience (<code>pc.exp</code>); a negative amount takes experience away. The player doesn't gain a level from it: when the experience reaches the next level they are told "You can now raise a level by using the 'level' command!" and raise it themselves.
 +
 
 +
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| amount || integer || Experience to add; negative to take away.
 +
|-
 +
| pc || unitptr || The player.
 +
|}
 +
 
 +
== Notes ==
 +
* Only mortal players: on an NPC, an object, a room or null nothing happens, and a god (level <code>IMMORTAL_LEVEL</code>, 200, or more) keeps the experience they have.
 +
* Every call on a player is logged in vme.log: "''name'' gained ''amount'' experience from unit ''symname''."
 +
* Experience taken away never drops below what level 1 needs.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin quest_reward(pc : unitptr, xp : integer);
 +
code
 +
{
 +
  if (pc.type != UNIT_ST_PC)
 +
      return;
 +
  if (xp > 0)
 +
  {
 +
      experience(xp, pc);
 +
      act("You receive $2t experience points.", A_ALWAYS, pc, itoa(xp), null, TO_CHAR);
 +
  }
 +
  return;
 +
}
 +
dilend
 +
</pre>
 +
Rewards a player at the end of a quest. Adapted from quests.zon.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/exp|exp]]
 +
* [[Manual:DIL Manual/exptol|exptol]]
 +
* [[Manual:DIL Manual/level|level]]

Latest revision as of 23:23, 14 November 2026

experience()

Procedure. Gives a player experience points, or takes them away.

experience(amount : integer, pc : unitptr)

Adds amount to the player's experience (pc.exp); a negative amount takes experience away. The player doesn't gain a level from it: when the experience reaches the next level they are told "You can now raise a level by using the 'level' command!" and raise it themselves.

Parameters

Name Type Meaning
amount integer Experience to add; negative to take away.
pc unitptr The player.

Notes

  • Only mortal players: on an NPC, an object, a room or null nothing happens, and a god (level IMMORTAL_LEVEL, 200, or more) keeps the experience they have.
  • Every call on a player is logged in vme.log: "name gained amount experience from unit symname."
  • Experience taken away never drops below what level 1 needs.

Example

dilbegin quest_reward(pc : unitptr, xp : integer);
code
{
   if (pc.type != UNIT_ST_PC)
      return;
   if (xp > 0)
   {
      experience(xp, pc);
      act("You receive $2t experience points.", A_ALWAYS, pc, itoa(xp), null, TO_CHAR);
   }
   return;
}
dilend

Rewards a player at the end of a quest. Adapted from quests.zon.

See also