背景:
阅读新闻

Sphere 5.5i脚本学习

[日期:2006-08-18] 来源:乘风破浪网  作者:逍遥子 [字体: ]

原发:逍遥子 
BELGAR写的,很不错。E文好的鸟鸟朋友(呵呵,大家都是菜鸟拉)先看着,后天再给大家翻译翻译 

Mini tutorial for newbie scripters. 55I 

This is a small guide for people who have absolutely no idea where to begin. It gives general hints more then exhaustive information. I will try to add specific tutorials over time. Also this just adds some general info to the help section on sphereserver. It is NOT intented to replace the help section. Enjoy!! 


THE BASIC RULES 

To understand what is in most script files you need to know the following, the list is not in any way a complete list, but lets you understand what is in some of the script files. 

[xxxxxxx] Beginning of a block. Every item in sphere has a header like this. It tells sphere what information is contained in the section after the block header 

<xxxx> the values of xxxx. Eg.: test=10 ; test2=<test>. This will make test2 equal to 10 since test has the values 10 

SRC: source. The source of an event, the player initiating the action, etc. 

ACT: the active object. Could be the item the 慡RC?double clicked on, etc. the active object. 

TARG: the target. This was targeted 

CONT: container. The item I am contained in, the player who has equipped me, etc. 

LINK: every object can have a link defined to them. the object it is linked to can be acted upon by LINK 

Examples: 

SRC.ACT: the object the source of this event is acting upon 
SRC.TARG.ACT: the object the target of the source is acting upon 
SRC.TARG.ACT.LINK: the object that the object that is acted upon by the target of the source is linked to 

Etc. The last one may look a bit confusing at first. Just work back to front. These are the basic ways of addressing an object. After this you can retrieve the properties of an object. Objects can be players, NPC抯 and items. If you want to retrieve the name of something you targeted you could use <SRC.TARG.NAME>. to set the colour of an item you double clicked you could use SRC.ACT.COLOR=01. 

So how does this all work? Well, every thing in sphere has a unique number. This number is, unimaginably, called a unique identifier definition (UID). If you create two keys, they will have the same color, the same name, the same everything except for their UID抯. Even the world itself has an UID, as have all areas, all placed houses, everything. It is this number that tells the server on what (or by whom) the action is performed. So <SRC.TARG> has the same values as <SRC.TARG.UID>. However, SRC.TARG.UID.NAME will not work. 

ON=@DLICK 

This is called a trigger. Basically triggers define what will happen if the specified action is performed. In this case it defines what happens if, the object this is defined on, is double clicked. So: 

ON=@DCLICK 
SRC.MESSAGE hi 
RETURN 1 

If defined on an item, this will show 慼i?above the head of the person double clicking it. I will explain return later. 

This information should allow some basic understanding of scripts. Let抯 walk through an example. 

[ITEMDEF 04105] <-old defination style begin of block 
DEFNAME=i_SCIMITAR_FORCE <-new definition name 
ID=i_scimitar <-image 
NAME=Scimitar of Force <-name ingame 
RESOURCES=i_scimitar,3 i_enchant_weapon <-resources needed to make this 

DESCRIPTION=Scimitar of Force <-axis info 
SUBSECTION=Magic Scimitars <-axis info 
CATEGORY=Provisions - Weapons ?Magic <-axis info 

ON=@Create <- trigger. This happens when the item is created 
COLOR=color_magic_weap <-color of this item 
HITPOINTS={31 100} <- durability random between 31 and 100 
ATTR=attr_magic <-this item has the 憁agic attribute?set 
MOREY=60.0 <-morey on this weapon is set to 60.0 

THE FILES 

The only way to learn is to start small and get a feel for how the system operates. For starters you need to know what is in the files. They all have the extension ?scp?yet they are not all equal.. Most script files contain definitions of items, templates, NPC抯 etc. let me highlight a few of the special files. These special files are not just special concerning content, they also load only once. Many changes you make to these files will need a server reboot to take effect: 

Spheretables: loaded directly after sphere.ini. this file contains skill definitions, starting positions, player commands, titles and the basic skillclass. Look thru this file to get a feel for what it contains. Any changes require a server reboot. 

Spheretable_x: loaded after spheretables, contains spell definitions and spawn groups. You can抰 add spells here, but you can change some of the spells properties. You can define new spawn groups in any file. You will notice that all spawn groups are in the 08xxx range. To make a new one, define one with the next available number. Either here or in any file. 

Spheredefs: internally the server works exclusively with numbers. To make working with these numbers easier, many have a name assigned to them. for all items and creatures these are assigned in their definition files. All the others are defined in this file. Names of colours, flags, types, etc. can be found in this file. You normally don抰 need to alter this file, but it is a GREAT source of information about the possibilities of the sphere scripting system. Look through this file carefully. I estimate that 15% of all newbie questions can be answered by looking through this file. (and like all statistics I made this up on the spot.. probably a good guess though) 

Spheremap: contains all the areas on the map. These are best modified by using AXIS. However you need to realise that the order of loading is important. Sphere loads all areas on top of each other. Areas that overlap take the information of the area that was defined last (was lower in the file). Each area that has undefined options (like resources etc.) will take these valuess from the region above it. Sphere is object oriented: if you don抰 define things on the 慶hild?it will take the values of the 憄arent? Near the top of this file you find [area %servname%]. This area is the parent layer. You抣l find that the area encompasses the entire world. Anything defined here will take effect on the entire world unless redefined in a lower area. 

Sphereregion: Not a special file as such, but it contains many region events and resource definitions. Take a look through it. 

Sphereskill: Also not a special file, except that the main menu definitions MUST exist somewhere, and this file is as good as any. It contains the options for the crafting skills and some other skill related menus. If you want someone to be able to make something with a skill add it here. It is not the only thing that must be done to make something craftable but it is the main step. Look what you see on screen and compare it with what you see in the scripts. The commands are pretty straightforward. Skillmenus can contain conditionals, if a required condition is not met the item will not appear in the skillmenu. 

The other files are just as important, but they mostly follow the same rules. Don抰 ignore them and get a feel for what they do. 

BEGINNING SCRIPTING 

Get a good text editor. The minimum feature this MUST support is 憇earch text in files?so you can search for the occurrence of a word in all the script files and possibly sub directories. This shouldn抰 prevent you from getting a feel for the different files, but it will save a lot of frustration in the long run. 
Make sure you get familiar with Hexadecimal numbers. If possible, try to get away from using decimals as soon as possible. Try to resist going back to decimals, except when you give feedback to players. It will make scripting SO much more intuitive. Hex numbers in sphere are preceded by 0 (zero). So 10=10; 16=010. Mostly you will encounter it the other way around. 02710 = 10000. Sphere stores everything in hex, so in the long run it抯 easier to get used to working with hex. The reason why I mention this, is that some people convert everything to decimal in their functions because that way they know it is 搑ight? Usually they will start making logic errors and the scripts end up on the help forum. The server takes care of any conversions needed. The statement IF (0A==10) is true since both sides are 10 decimal. No need to convert 10 to hex or 0a to decimal. 

While logged on with your client there are several important commands that can be used for debugging: 

.info ->get info about an item/player/npc 
.edit / .xedit -> get info about the 憀ayers?on a NPC/player. (what is equipped/worn) 
.show / .xshow -> show any variable. If this variable exists anywhere on the server show can retrieve it. 

Throughout the client, placing an 憍?in front of a command will bring up a targetting cursor so you can select the target for your command. 

.str 100 -> set my strength to 100 
.xstr 100 -> set targets strength to 100 (can target yourself) 

Fiddle around with these for a while. Get a feel for what is possible. Especially the show command will prove very useful once you get more experienced. 

.show str -> show my strength 
.show tag.stored -> shows the values stored in tag.stored (on me) 
.xshow link -> shows the link on target object 

but also 

.show eval (10+0a0) 
.show region.flags 
.show serv.archerymindist 
.show isgm 
.show act 

Everything that returns a values can be checked with 憇how? The values must be true, for the privileges of the user using it, though. Passwords can only be seen by admins. Admins have privilege level 6. So for an admin .xshow account.password will bring up target players password. However a GM issuing the same command will not get anything useful, as they do not have the required privilege level to see passwords. 

Which brings me to another item: any commands issued in scripts are considered to be admin level by the server. So be careful of how you write your scripts. You will find that more than half of the time spend on larger scripts goes into making them safe and unexploitable. Never rely on the goodwill of the players. If they find a way to cheat, they will cheat. 

By now you should be able to: 
- understand basic scripts 
- know how sphere addresses items, players and NPC抯 
- tell in which file sphere stores what information 
- retrieve basic information with client commands 

The Next Step 

Get Axis. Simple as that. Maybe you downloaded it when you downloaded the server, maybe you didn抰. It is a VERY useful tool for beginning scripters and a handy tool for more experienced scripters. I rarely use it myself, except for the colors tool, but that is a matter of preference. 

Get InsideUO. This tool gives you all the graphics available in UO. Once you get up to writing dialogs this tool is invaluable. 

To make your own script files (highly recommended) just create a file called myname.scp. If you place this file in the same directory as sphereserver.exe it should automatically load it when you resync your server. If not, or if you want to place it in a subdir, open up spheretables.scp and add it to the [resources] section. 

Your first few scripts should be item scripts. Mainly, because they are Very easy to make. Also make good use of inheritance or at least be aware of it. If you give an item the ID of another item, it will basically make a complete copy of it. Anything you don抰 change on your own item will be the same as the original item. So: 

[itemdef I_my_bottle] 
id=I_bottle_empty 

Will make an exact copy of the normal empty potion bottle. This isn抰 very useful of course. However maybe you want these to weigh less than normal bottles: 

[itemdef I_my_bottle] 
id=I_bottle_empty 
weight=0.1 

Important here is that these new bottles can still be used for alchemy, since they 慽nherited?this from the original. However, if you wanted to use this item as a forge (silly but possible) you could do: 

[itemdef I_my_bottle] 
id=I_bottle_empty 
weight=0.1 
type=t_forge //find this in spheredefs 

Not all properties can go under the itemdef itself. You will find that 慳ttr=04?to make it a newbie item, will return 憉nknown command 慳ttr拻. Put these commands under the 慜N=@CREATE?trigger. Like so: 

[itemdef I_my_bottle] 
ID=I_bottle_empty 
WEIGHT=0.1 
NAME=my test object 

ON=@CREATE 
ATTR=04 

Of course you will start scripting the usual lightning, flamestrike and poison weapons. Have fun with those until you feel more confident. Some people never get beyond this stage, get bored and give up. I personally like a challenge. I learned 95% of what I know by looking at scripts and pages explaining commands. Oh, and NEVER EVER believe anything until you try it yourself. Sure, most of the time people will be right, but the times they will not be right could turn out to be very profitable. Added to that, you get some experience in trying different things. If you got an idea and can抰 get it to work immediately, don抰 scrap it, but put in a list somewhere. For many problems there are workarounds. Sometimes you will have to wait for a completely new release of sphere, but it may work some day. 

Designing NPC抯 

There is only one good way to learn scripting NPC抯: look at existing ones. I guess I could go through every possibility, but it is really not worth it. However I will go into events a bit. An event in sphere is something that 慼appens?to a player or NPC. You get hit, you cast a spell, you target something, etc etc. These events can be caught in triggers again. A group of these can be added to an event definition. It will look something like: TEVENTS= or EVENTS=. A very famous one is the TEVENTS=E_UNDEAD. Basically this causes undead to die at a single hit when in sunlight. Which is good for about 200 posts on the subject per year. An alternative to using events is putting the triggers directly on the NPC. This you would normally only do when you design a unique NPC. 

This should be enough info to get you started and get a feel for scripting. In the coming weeks I抣l be working on more advanced scripting tutorials. 

Gr, 

Belgar 
www.virtual-paradise.org (under reconstruction at the moment) 

-------------------------------------------------------------------------------- 
"I don't care if you're a Viking - get that axe out of the dartboard!" 

一级鸟鸟篇 

想学写脚本了啊?先看看以下这些内容吧。虽然不够完整,也够的你们这些鸟鸟学的拉(哈,我也是是个菜鸟了) 
To understand what is in most script files you need to know the following, the list is not in any way a complete list, but lets you understand what is in some of the script files. 

[xxxxxxx] 脚本里一个事物的开头,有了它,服务器才晓得你要写个东东 

<xxxx> xxxx的值。 举例: test=10 ; test2=<test>. 那么test2就等于10了 

SRC: 源. 事件的起源, 比如说做了某个玩家做了某件事,这个玩家就是这件事的SRC. 

ACT: 作用物. 可以是一个被双击的猪头,等等等等 

TARG: 目标. 某个被瞄准的东东 

CONT: 容器. 一个放在包里的东东,这个包就是这个东东的容器;或者,一个玩家穿上了某件东东(衣服、盔甲、马 

LINK: 每一个东东都可以定义一个连接。有什么用?以后就可以对他采取行动了啥 

举几个例子: 

SRC.ACT: 对某件事情的起源物采取行动 
SRC.TARG.ACT: 对某件事情的起源物的目标采取行动 
SRC.TARG.ACT.LINK: 某个源东东A,选择了一个目标东东B,小B呢对一个东东C施加了作用,而这个小C连接到的东东小D,就是这一句的意思拉 

晕了晕了(我先晕的哟),搞混了哈,呵呵。这最后一句的作用呢,就是可以让你找到你在那个C东东身上连接的东东,可以是一个玩家、NPC、物品啊什么什么的。要你想搞到你指向的目标的名字呢,你可以用<SRC.TARG.NAME>,要设置他的颜色呢,就用SRC.ACT.COLOR=01 

怎么样?再给你们说一点,在一个世界上的每个东东都有一个唯一的标签,叫做uid,记住,唯一的!所以呢,<SRC.TARG> 和 <SRC.TARG.UID> 是一模一样的。但是, SRC.TARG.UID.NAME 是没用的哟 

ON=@DLICK 

引发一个trigger. triggers是定义在发生了某件特定事情后所要做的事。这一句的意思呢就是当一个东东被双击后所要发身的事情(把你变成猪头,哈哈) 

ON=@DCLICK 
SRC.MESSAGE hi 
RETURN 1 

这一段的作用呢,就是当你双击这个东东,你的猪头上就会冒出hi这个字……HI,猪猪你好 

This information should allow some basic understanding of scripts. Let抯 walk through an example. 

[ITEMDEF 04105] <-以前的老式定义格式 
DEFNAME=i_SCIMITAR_FORCE <-换新的拉 
ID=i_scimitar <-映像 
NAME=Scimitar of Force <-在游戏里的名字 
RESOURCES=i_scimitar,3 i_enchant_weapon <-制造这个东东需要的材料 

DESCRIPTION=Scimitar of Force <-axis资料(一个GM工具) 
SUBSECTION=Magic Scimitars <-axis资料 
CATEGORY=Provisions - Weapons ?Magic <-axis资料 

ON=@Create <- trigger. 当这个东东诞生时触发 
COLOR=color_magic_weap <-颜色 
HITPOINTS={31 100} <- 31到100之间的一个随机决定的HP 
ATTR=attr_magic <-设置为魔法属性 
MOREY=60.0 <-把morey设成60.0 

THE FILES 

来看看这些脚本文件有什么用吧。(以下的是按系统读取文件顺序排列的) 

Spheretables: 里面有技能设置、开始的位置、角色命令、称号、起始等级、 

Spheretable_x: 设置了魔法和衍生点. 

Spheredefs: 服务器默认的一些设置 

Spheremap: 所有地区的地图 

Sphereregion: 地区、增援的设置 

Sphereskill: 魔法的设置 

不行了不行了睡觉去了明天再给大家翻 

 

the object(link) that the object(act) that is acted upon by the target(targ) of the source(src) is linked to 

举个例子呢,实现往被target者包里弹入一个有某种用途的东西: 

on=@targon_char 
src.targ.newitem xxxx 
src.targ.act.link=<src.uid> 
src.targ.act.bounce 
return 0 

现在,这个xxxx的link就是src的serial了,以后可以在脚本里用<src.targ.act.link>调出这个serial 

这个教程是老外belgar(在sphereserver论坛频繁出现)写的,看看觉得应该比较适合才学写脚本的朋友,就翻了翻,口吻也用了自己觉得以前自己比较容易看懂的口吻,所以相当的不严肃,而且因为懒也没有坚持下去,到是让各位见笑了 

不过现在有clane翻译的文章,相当系统的,这篇教程也就失去翻译的意义了,真的很佩服clane啊! 

收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻