This page contains snippets of code to frequently asked questions when working with the Lua / Mud system. As builders become familiar with the code, useful hints and answers will be added to this page.
How to test for good, evil, neutral?
The old mobprog system had 3 commands for isgood, isevil and isneutral. The Lua based system allows you to be more specific and test the character alignment number. To get the equivalents of the old commands use:
How to test for a non-player?The 'isplayer(CH)' function tests if a character variable is a player. The old mobprog system had no concept of not. In Lua, you would just wrap a 'not' around it:
How to do equivalent of 'mob force mob oload aylor-321' etc?
In the old mobprog system, 'mob force' forces the target to execute a MUD command. This works fine in the Lua force also. The exception is 'mob force mob ...' - In the old system this causes the mob being forced to execute an arbitrary line of mobprog code within its own space. Because Lua is a completely separate environment integrated back in to the mud, you cannot simply force a mob to execute a lua statement.
The workaround for this is more flexible, but a little more complex. Using the v2 mobprog example below, the mob loads a new mob, then forces it to load and wield a sword:
Because the Lua call allows you to change the actors (including self), and because mload returns a CH variable for the mob created, you can combine these to achieve the same results.
You would split this into two progs, then call the second prog changing the 'self' actor to the mob that was just loaded:
How to restrict a wandering mob by sector
This mostly came up because of mobs wandering on the continents - being able to restrict a fish to river only sectors or a mountain lion to the mountains etc
The solution for this involves using the new 'lastroom' character property along with an entry trigger. If the mob tries to enter a sector type you don't want it to be in, transfer it back to its last room.
The trigger for this is: