The affect() function applies a magical affect to a player. (The correct word would be "effect" but it's a slothmud convention to use the wrong form.) This is done without fanfare such as uttering of magic words or messages to the victim.
This function takes three arguments: a target character, a spell name (string), and a list of flags. The first string (second argument) is a spell from the lists in 'immh aff_spells' and 'immh aff_spells2'. The second string (third argument) is a space-separated list of zero or more of the following flags (shown with examples of usage):
level=31 | set the caster level to the specified level; if absent then use 41 (which means it can't be dispelled by players) |
location=dex | the attribute that is altered by this affect; taken from the lists in 'immh aff_apply'. If absent, no location is altered. |
modifier=-2 | the amount by which to modify the location. This field is not meaningful for every location, in which case it can be omitted. |
bitvector=5 | If nonzero, these bits are applied to the victim by this affect. 5 is 1 and 4, which are 'blind' and 'detect evil'. Bits are listed in 'immh aff_bitvec' |
duration=12 | Says that the affect will last for that number of ticks, give or take a few seconds. If you want the affect to be permanent, use 'seconds=-1' instead. |
seconds=720 | Says that the affect will last for that number of seconds, exactly. If -1, the affect is permanent until removed. Only one of 'seconds' and 'duration' is heeded. If you have multiple affects that should run out at the same time, you must use 'seconds' instead of 'duration'. |
Say I want an item to blind the person who eats it, non-dispellably, for 5 minutes. The raw command would be (on interception of "eat")
affect(%a,'blindness','level=45 duration=5 bitvector=1')but probably I would also want to issue some sort of message to the player and the room, so maybe the whole command would be
> setproc bread 0 on_eat ] ( msg_character( %a, 'Hey, who turned out the lights!?' ), ] affect( %a, 'blindness', 'level=45 duration=5 bitvector=1' ), ] msg_everyone_else( %a, '$n groans as $s eyes cloud over...' ) ) ] @
This particular example, interestingly, won't work right. The reason is that the victim gets blinded BEFORE the "eat" command gets processed (because always mudl procs are called before the command is executed) and then he can't find the bread. So to make it work, you would have to block the command, do your own eat message, and destroy() the bread.