Chapter 8

From SphereWiki
Revision as of 07:49, 2 June 2009 by MrSugarCube (talk | contribs)
Jump to: navigation, search

(WIP)

Skill Menus

One of the most common requests by newbie admins is the ability to create new things via the craft skills. I've noticed that it is also one of the first things that players check out about a shard. If your shard has awesome craftable items, chances are the player will stick around longer and gain skill so he can see them. Craftable houses are the ultimate in cool. And this section will show you how to make one. First, we'll just look at how the crafting system works.


There are about 9 built-in section names, for each of the various crafting skills. This script is called from within the server, and if those sections don't exist, you will receive many scary errors. Here is the list, which I grabbed from the top of sphereskill.scp.


// Hard coded ref names: (called directly form server)
// sm_alchemy = dclick on alch tools
// sm_summon
// sm_polymorph = polymorph menus
// sm_cartography = dclick on blank map
// sm_bowcraft = knife on wood
// sm_bolts = dclick on arrows or shafts
// sm_blacksmith = dclick on tool
// sm_carpentry = dclick on carp tool
// sm_tailor_leather = dclick on sewing kit
// sm_tailor_cloth
// sm_tinker = dclick on tinker tools.
// sm_inscription = dclick on blank scroll
// sm_cook = ??? NOT USED YET


Here is the syntax of a SKILLMENU section, like every other section in a SPHERE script:


[SKILLMENU sm_alchemy]


Now, a skill menu is the little box that pops up that contains the pictures of the items that you can scroll through and select. There are several attributes of this box which obviously need defined. The first is the title. It goes immediately underneath the [SKILLMENU] tag.


[SKILLMENU sm_alchemy]
What sort of potion do you want to make?


That line will be displayed across the top of the menu, as the title. In the case of the alchemy skill, we simply want to ask the user what type of potion he wishes to make. The next parts of the script are a little shaky, and contain some new constructs that you may or may not recognize. In reality, it's just a series of events, which occur depending on which menu item the user picks. Here's the part of the rest of the alchemy script:


[SKILLMENU sm_alchemy]
What sort of potion do you want to make?

ON=i_potion_Agility <name> (<resmake>)
    MAKEITEM=i_potion_Agility
    
ON=i_potion_AgilityGreat <name> (<resmake>)
    MAKEITEM=i_potion_AgilityGreat
    
ON=i_potion_CureLess <name> (<resmake>)
    MAKEITEM=i_potion_CureLess
    
ON=i_potion_Cure <name> (<resmake>)
    MAKEITEM=i_potion_Cure
    
ON=i_potion_CureGreat <name> (<resmake>)
    MAKEITEM=i_potion_CureGreat
    
ON=i_potion_ExplosionLess <name> (<resmake>)
    MAKEITEM=i_potion_ExplosionLess
    
ON=i_potion_Explosion <name> (<resmake>)
    MAKEITEM=i_potion_Explosion
    
ON=i_potion_ExplosionGreat <name> (<resmake>)
    MAKEITEM=i_potion_ExplosionGreat
    
ON=i_potion_HealLess <name> (<resmake>)
    MAKEITEM=i_potion_HealLess


As you can see, we still use the ON= event construction for these menus as well. The different is what follows. Let's dissect it:


ON=i_potion_HealLess <name> (<resmake>)


This line tells the server a number of things. The first parameter, immediately following the = sign, is the ID of the item to display. So, what will be displayed here is the DISPID of the i_potion_HealLess item. It happens to be a yellow potion. As soon as you specify this item, it becomes the default item for the rest of that line. The server knows that <NAME> refers to the name of the potion item, and that <RESMAKE> is a string which tells what it takes to make that item. Both of those are specified in the script for i_potion_HealLess (which is in sphere_item_provisions_potions.scp) and can easily be changed there (looks for NAME= to change the name and SKILLMAKE= to change the skill and difficulty).


MAKEITEM=i_potion_HealLess


Well if this isn't obvious, you shouldn't be reading this chapter. It simply begins the construction of the specific item. Wait, you may be asking, how does the server know which skill to use or how much skill is required, or even what to consume (1 empty bottle) when creating this item. Well, I'm glad you asked. To answer that, we need to look at the script for the item we're constructing. Ah, here it is....


[ITEMDEF i_potion_HealLess]
NAME=Lesser Heal
ID=i_bottle_YELLOW
RESOURCES=i_reag_ginseng, i_bottle_EMPTY
SKILLMAKE=ALCHEMY 0.1
TYPE=T_POTION
TDATA1=i_bottle_empty

ON=@Create
    MORE1 = s_heal
    MORE2 = 50.0


The two important lines are the RESOURCES and SKILLMAKE lines. These two lines work with the skill system to tell SPHERE what items are used to make this item. Basically, it says that when you create the item, you need 1 i_reag_ginseng and 1 i_bottle_empty. Incidentally, if you don't have the resources to make an item, it won't even appear on the list when you look at the SKILLMENU in-game. The next line tells the server which and how much skill is required to make this item. In this case, it says we need 0.1 in the alchemy skill. It IS just a lesser heal, after all.


Take your new i_potion_HealLess to a store and try to sell it. Magically, it seems to have a price. Where did that price come from? Well, it came from the RESOURCES. The value of a lesser heal potion is the combined value of the i_reag_ginseng and the i_bottle_EMPTY. Both of these are defined in sphere_item_resources.scp. This brings us to a point so important, I am going to put it in bold: An item MUST have either a VALUE or resources with a VALUE, or it will not appear in a SKILLMENU! Many newbie scripters ask on the boards about why their item is not appearing in an otherwise perfect SKILLMENU section. It has nothing to do with the SKILLMENU. Look at your item scripts before whining to us on the boards.


Another important point is this: You may have any number of lines between ON= events in a [SKILLMENU] section. It just happens that MAKEITEM does everything for us that we need it to do, so most scripts only have one line. However, you could print out a SYSMESSAGE or KILL a player within a SKILLMENU, just as easily as you could do it in any other event.


Now that we know this fact, let's build that craftable house I was referring to! First, we need to figure out what sort of RESOURCES we might want to use to craft a house. I would say a large amount of wood, maybe some metal for a doorknob, a deed to write on, and some magic just for the heck of it. We'll take a resources like that looks like this:


RESOURCES=1000 i_board, 100 i_ingot_iron, 5 i_reag_garlic, i_deed


We also need a SKILLMAKE definition, and for this we'll use the Carpentry skill. Say, 95.0. Then we'll put those lines into the ITEMDEF for the deed we want to make craftable:


[ITEMDEF i_craftable_deed]
ID=i_deed
NAME=Deed to a Small Stone House
RESOURCES=1000 i_board, 100 i_ingot_iron, 5 i_reag_garlic, i_deed
SKILLMAKE=CARPENTRY 95.0

CATEGORY=Provisions - Deeds
SUBSECTION=House Deeds
DESCRIPTION=Small Stone House

ON=@Create
    MORE1 = i_multi_house_stone_small


This, if you haven't figured it out, is a copy of item 04202, which has been renamed and edited. You can find the original script in sphere_item_deed.scp. Now, our item has a SKILLMAKE definition, and a VALUE definition (through the RESOURCES). It is craftable. We need to stick it into one of the existing Carpentry [SKILLMENU] sections now. Let's look at one of them:


[SKILLMENU sm_carpentry]
Carpentry

ON=i_board boards
    MAKEITEM=i_board
    
ON=i_chair_throne Chairs
    SKILLMENU=sm_wood_chairs
    
ON=i_chest_wooden_brass Containers & Shields
    SKILLMENU=sm_wood_containers_shields
    
ON=i_table_nightstand Table
    SKILLMENU=sm_wood_tables
    
ON=i_staff_gnarled Weapons & Tools
    SKILLMENU=sm_wood_weapons_tools
    
ON=i_armoir_dk Furniture
    SKILLMENU=sm_wood_furniture
    
ON=i_portrait_7 Paintings
    SKILLMENU=sm_wood_paintings
    
ON=i_trophy_deerhead Trophies
    SKILLMENU=sm_wood_trophies
    
ON=i_saddle Rancher Types
    SKILLMENU=sm_wood_rancher
    
ON=i_BED_9 Beds
    SKILLMENU=sm_wood_beds
    
ON=i_bulletin_board Miscellaneous
    SKILLMENU=sm_wood_misc


Like I said earlier, you can have any lines after an ON= section. In this case, it just happens to be a SKILLMENU line which opens up another menu. This is a hierarchical menu, because you choose from upper menu options like these, and go through lower menus, until you finally reach an item you can craft. Now, we're going to add the following two lines to the end of this script:


ON=i_craftable_deed <name> (<resmake>)
    MAKEITEM=i_craftable_deed


Guess what? We're done. That's all you need to do. Now, in most cases, you would make a new [SKILLMENU sm_houses] or something similar, and then add all of your items to that. In that case, the line you'd add to the main Carpentry menu (or one of the submenus) is the following:


ON=i_deed Craftable Houses
    SKILLMENU=sm_houses


That's all. Easy, isn't it? It's one of the easiest things to script, and one of the coolest. Unfortunately, it is so easy and repetitive that it takes FOREVER to make a good crafting system. If you are going to create one for your shard, start now. You should be finished in about a month. :)