Aardwolf MUD Home Page Link

Location: Home / Lua Coding / Object Progs

Object progs are the first to use the type of scripts the v3 mobprog system was truly designed for. Unlike all other trigger types, the Lua scripts called by object progs can return a value back to the MUD telling the MUD how to proceed with the requested action.

Compare this to a mobprog exit trigger. If the trigger fires at all, the standard MUD code to move the char is bypassed. If the trigger is not going to actually block the player's movement, the builder is left responsible for manualtimerly completing the movement - usually via a transfer call. It was necessary to convert this method for mobprogs because we had so many existing scripting relying on it - with object progs we get a fresh start.

From within any object prog, if the lua script returns a 'true' value to the MUD, the requested action is blocked. This leaves the actual task of dropping/getting/sacrificing an item in the core of the MUD code, where it belongs.

A couple of simple examples:

-- Require 300 strength before player can pick up the sword.
-- Trigger: a get test-1 100   (100% chance to fire).
if ch.str < 300 then
   send(ch,"You are not strong enough to wield "..obj.name..".")
   return true
end

-- Only a priest can sacrifice the orb.
--- Trigger: a sacrifice test-2 100
if ch.subclass ~= SUBCLASS_PRIEST
   send(ch,"You are not a priest of this temple. Your offering is refused.")
   return true
end

Returning true tells the MUD code itself to exit, do not complete the get or wield operation. If true is not returned, false is implied. Using the first prog above, if the player does have 300 or more str, the prog ends, false is returned and the MUD continues with the wear operation as usual.


Object Trigger Types

The actual syntax to add triggers to objects is the same as for rooms and mobs:

add type prog-id percent_chance [actor key]

All object trigger types so far take a percentage chance as their argument. If a mob key is included as an actor key, that mob must be present for the program to trigger. One example use of this is a more efficient way of having a guard mob preventing the player from taking a gem - put a "get" trigger on the gem requiring the guard as the actor. Have the guard perform the specific action, then return true to block the get operation.

The object trigger types available at the time of writing are listed below. This is just a small sample of the overall set for testing purposes. Note also that many luaprog commands still require an actor and do not work with object or room progs - these are being updated on the functions page as they are cleaned up. If you have a specific need for one in the meantime, contact Lasher.

Get:
Fires whenever the player tries to get an item from the floor. The trigger will not affect getting items from a container or a corpse. If the luaprog returns true, the get fails.
Drop:
Fires when a player attempts to drop an item. This will not fire if the item is inside a container that is dropped. If the lua prog returns true, the drop fails.
Expire:
Fires when a timed item is ready to expire, just before the item itself is removed from the game. See example below. If the item is extracted during the prog using 'purgeobj', there will be no 'crumbles to dust' message to the user.
Identify:
Fires when the item is identified using the spell, lore, or the identify command. Does not fire from appraise/auction/rauct identify. If the lua prog returns true, the identify does not happen.
Wear:
Fires when the item is worn. If the lua prog returns true, the player cannot wear the item.Although we don't really want to see race/class only eq without a very good reason, this is perfect for that.
Remove:
Fires when the item is removed. If the lua prog returns true, the remove fails.
Sacrifice:
Fires when the item is sacrificed. If the lua prog returns true, the sacrifice fails.


Expire trigger example:
Using two triggers to create a trap in the room - exploding pot pies! The first trigger is a drop trigger on the item that simply adds a timer.

-- Add timer to a dropped item
--- Make sure we dont already have a timer.
if obj.timer == -1
   obj.timer = 10
end

The second trigger is the expire trigger itself. The program makes sure that the item is still in a room and if so damages everyone in the room. See the item properties page for more information on some of the code below.

-- Expire trigger on item.
--- Make sure item is still on the ground
if obj.loctype == OBJ_LOC_ROOM then 
   echo("The "..obj.name.." explodes violently, searing everyone in the room!")
   rawdamage(nil,1000,2000,3,0,nil,obj,nil,"Exploding pie power",LP_LETHAL+LP_ALL)
end
--- Note: No need to purge the item - it is already expiring.