|
|
|||
Discworld Documentation:LPC for DummiesWritten by Drakkos WyrmstalkerN.B - This is a work in progress... a living document if you like. If it appears to be dead when you view it, don't worry. It's most likely just playing possum. Comments on these chapters and tutorials can be e-mailed to Drakkos. Tutorial Answers
Add plural can be used in the same way we've already seen with add_adjective. We simply pass in the plural, or an array containing multiple plurals, in the setup of our npc. So if we wanted to add, say, porridges and greys as plurals (which we wouldn't, unless we speak like Gollum, my preciousss), we would use the line:
We would mainly use add_plural when we're coding an item that may have several correct pluralisations. Since the MUD will only add one plural as standard, we use add_plural() to make sure all the bases are covered.
Set_aggressive takes a single integer argument of one, two or zero. If we pass in one as an argument, then the NPC becomes aggressive and will attack all players who enter its environment. If we pass it in as two, then the NPC will attack all players, and all NPCs who enter the environment. Passing in zero as an argument will make the NPC passive. So to make our NPC attack players, we use the line:
In the setup of the NPC.
Adjust money allows us to modify the NPC's purse. It takes two arguments, the first being the number of coins, and the second being the type of coins. We can get a list of valid types of coin by doing 'call query_valid_types() /obj/handlers/money_handler'. Somewhere in the list that appears are the two types of coin we're interested in: "Ankh-Morpork pence", "Ankh-Morpork dollar", So, we want to give our NPC two dollars:
And fifty pence:
We put this wherever we want our NPC to get the money. In most cases, we'll put it into the setup() of our NPC.
The function set_background_enchant takes a single integer as an argument, and sets the ambient background magic of the room as that value. The line in setup would look like:
Which would give the background magic level to those who can sense octarine as: There is the residual taste of magic in this place Higher values, obviously, mean a greater level of background magic.
Add_alias takes two arguments. The first being the alias, or aliases to apply to an exit, the second being the exit itself. For example:
We can then allow people to go north by typing 'Bing' or 'Bong' by using:
Or combining the two into one call by passing in an array as the first argument:
We can use add_alias to make odd exits somewhat more forgiving, as well as to be flexible with regards to conventional exits.
Inside rooms have a default size of ten cubic units, a unit being roughly equivalent to a foot. So a normal inside room will be 10' by 10' by 10'. We can change the size of a room by using the set_room_size() function. This takes a single argument, which may either be an integer specifying the size of the room, or an array consisting of the three dimensions. If the argument is a single value, then the dimensions are assumed to be equal in all directions... in other words, the room is cubic. If we pass in an array, it takes the form ({north-south radius, east-west radius, up-down radius}). So we could use:
To make a room of twenty cubic units, or:
To make a room that has a radius of 20 going north to south, a radius of 10 going from east to west, and a radius of 10 going up and down.
We enclose our special case string between two $ symbols. This indicates to the output processing code that we want to treat the text between the symbols as special. The first character after the first dollar determines which object we're referring to:
We then follow this immediately with the information we want to access about the object: name - We want the name of the object
We also have ashort, possshort, theshort, and oneshort, and these call the relevant short() function on the NPC. So, for the cases we have above, we want:
These functions can be used in load_chat and load_a_chat in place of a specific reference, for example:
When the action to be performed as a result of an add_respond_to_with is an array, then the NPC will randomly pick one of the elements of the array to execute. Again, these elements take the form of commands to be executed by the NPC, so we'd have:
Which would give two random reactions to a player saying hello.
Again, we can achieve this simply by passing in the command as an array. Unlike add_respond_to_with, the load_chat() will execute each of these commands in turn, at intervals dictated by the chat frequency. So if we had:
And our leetle NPC executed the first action (the story array), we'd get:
Each element of the story array would be executed before the NPC performed any other random chats.
Add_hidden_object() adds an object as hidden to a room. Pretty obvious stuff, yes! But it still bears some further explanation. It takes a single object argument, the argument being the object reference we want to add to the room. It moves the object to the room and makes it invisible with regards to the inventory line of the room. It can still be looked at, touched, smelled, kissed, fondled, etc, etc, as normal. Any commands associated with the item can still be used as if the item was there normally. The only difference is that the item will not be shown along with any other physical objects in the room. To take an example, let's say we have an item located at /w/your_name/clever_item. We want to move this into our room, so we do:
And then we enter our room, to see:
But say we don't want that... we want our item to be invisible. So instead, we do:
And we get:
So although our item does not appear in the inventory line, it is still in the room.
We've already discussed modify exit a little in tutorial four. This is just an expansion of what we discussed there. In this case, for the first we use the "exit mess" type. The value we pass in after that uses the special character code $N, which is replaced by the name of the object taking the exit. $F and $T are replaced with the from direction, and the to direction respectively. So we'd use a modify exit that looks like:
Remember the stagger$s thing is a pluralisation code... it will appear as 'staggers' for one object taking the exit, and 'stagger' if two objects take the exit:
The second part of this exercise is achieved by using the "obvious" type. Again, we use it as above. We pass in a 1 if we want the exit to be obvious... in other words, we want it to appear in the list of obvious exits. We pass in a 0 if we want it to be hidden:
Remember that we can combine all of our modify_exit statements into a single line of code, like so:
Which is equivalent to both of the previous modify_exits.
Add_known_command takes a single string as an argument, and that string is the name of the command. The command must exist as a part of /cmds/guild-race, however, or it will not be added. In our setup(), we would have the following lines to provide our NPC with access to the crush and strike commands:
Then, we add a combat action to our NPC as we've done before:
And then a function to handle the actual crushing or striking:
Then, we give our NPC an appropriate weapon in its setup(), and tell it to hold it:
And voila! We have an NPC ready to beat some excrement out of its foes wif a big hammer. Whee! |
||||
|
Brought to you by CMOT Dibbler's Sensational Sausages; buy one while they're hot. |