Wiz Programming Tutorials

There are lots (and lots) of properties you can change to modify a player. We'll cover a bunch of the most common ones in these tutorials. Unlike most of the other tutorials, we're not going to provide complete examples - just code snippets that show you how to set the right properties.

Contents

Transient vs. Persistent Properties

Every game object (including Players) has two property lists: a "transient" list and a "persistent" list. The persistent properties are saved into the player file, and the transient properties are discarded when the player quits.

You have to be really careful deciding which one to use. If you want your change to be permanent, use persistent properties. This is the default, so calling setProperty, addProperty, setIntProperty, adjustIntProperty, and removeProperty performs permanent changes on a player. You'd use these, for example, to set the "qp" property (Quest Points) after the player solves a quest.

To make temporary changes, such as temporarily lowering a player's Hit Points, you use Transient properties, which have corresponding setTransientProperty, addTransientProperty, setTransientIntProperty, adjustTransientIntProperty, and removeTransientProperty methods.

Who Wins?

Because there are 2 property lists, you can have two properties with the same name and different values. You might be wondering which one gets used.

Transient properties always override the persistent values. For example, the player's title (e.g. "Human Adventurer") is stored in a "title" String property. You can override it temporarily by doing:

	player.setTransientProperty("title", "Giant Bug")

If the player quits and restarts, they get their old title back.

There's an exception to this rule, though: transient int properties are added to the persistent value, if any. This might seem a bit weird at first, but it's actually extremely useful. If you're messing with a player's int properties, you're almost always trying to make an adjustment to their normal value.

For example, you can temporarily give a player a higher (or lower) strength, hit points, spell points, move speed, melee (or any other) skill, or flying property just by calling adjustTransientIntProperty on that property name.

This is the way magic items with bonuses work - they add (or subtract) from the transient value of the property they're affecting. A Ring of the Perfect Swordsman adds +3 to the player's (transient) "sk-sword" skill, for example.

The advantage of using transient properties is that if the value gets completely screwed up because of a bug, it only lasts until the player logs out.

Old-Style Transient Properties

If you create a property whose name starts with an @-sign, it's stored in the persistent-property list, but it won't get saved to disk. However, it won't override the persistent value, either. Doing it this way is sort of a legacy - we don't do it as often anymore, although it can be more convenient to type:

	player.addProperty ( "@stuck-in-quicksand" )
than to type:

	player.addTransientProperty ( "stuck-in-quicksand" )
You can use @-properties if you want - just keep in mind they don't use the same overrides as normal transient properties do.

Some Examples

Changing Move Speeds

Let's say you're making a sticky-glue trap that slows down the player while they're moving in it.

There are two ways to change how fast a player moves:

  1. You can set their "move-speed" property directly.
  2. You can change the delay for the MoveEvent.
The first way would look like this:

	# slow them down by 200ms
	player.adjustTransientIntProperty('move-speed', 200)
(and some time later...)
	# speed them back up again
	player.adjustTransientIntProperty('move-speed', -200)
This can be a bit dangerous, though - it's hard to predict all the situations where the player could get out of your trap and be stuck with a slower move speed. They could teleport out, be summoned out, blink out, or possibly get out other ways, so you have to get on the right hooks (probably the method-hook "remove") and make sure you clean up after they leave the trap.

An easier way is to set up a map hook for "movePreHook" (see the tutorial on Hooks if this doesn't make sense) and change the event delay:

class my_class(MapObject, HookCallback):

    def setMap(self, map, x, y):
        self.super__setMap(map, x, y)
        map.registerCommand(self, "movePreHook")

    # slow down all moves in this map
    def hookEvent(self, hookName, event):
        delay = event.getDelay()
        event.setDelay(delay + 200)

Of course you could check to see if the agent doing the move is in your sticky-square, or whatever. The example is intended to show how you set the event delay.

The first method (setting the player's "move-speed") works fine if you're guaranteed to know when to undo it - for instance, a timer expires, or they take off their boots, or something along those lines.

Other Examples

Let us know if you want examples of how to set other kinds of properties, and we'll add tutorials here.

Properties You Shouldn't Mess With

There are certain properties that it's a Bad Idea to set or modify:
  • the player's location list
  • the player's appearance (don't change "image" - use player.setApperance() instead)

We'll add to this list as we think of more (or Wizards find them inadvertently for us).

<< Previous Chapter Next Chapter >>