|
Location: Home / Lua Coding / Lua Mud Howtos 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:
How to use the date/time/timer features Before working with times and dates in the MUD, an important thing to know is that, internally, all dates and times in the MUD are stored as "Unixtime" which is the number of seconds since Jan 1st 1971. We can use this number to manipulate dates to add/remove/check times. There are three Luaprog commands that can be used to manipulate dates and times:
There is also a new trigger type TIMER that works like RANDOM but is a fixed time in seconds so you can predict exactly when a prog will run. This is not like adddelay() because it will constantly run once the trigger is set. As this is intended to be used for longer term timers, you cannot set an interval of less than 60 seconds but if you *really* need one we can discuss it as high level imms can set them. Here are some examples of using these commands: Converting a human readable date to internal time then back again so you can see that it worked correctly:
Getting the current MUD time and adding a week to it:
Setting a timer on a mob then checking it periodically. The program to do the checking would be in a TIMER trigger. This is just for example, in this case if we wanted the program to run every 2 hours unconditionally we'd set a 7200 second TIMER trigger. This logic would only be needed for a longer term trigger (assume daily reboots) or if the two hours needed to be exact and should not reset over a reboot, which means the timer would have to be saved:
All three of these examples run together in a single program would return this if the timer has already been set:
| |||
|