文章出处:铁资网 作者:sphinx 发布时间:2005-03-08
第三讲:脚本的基础命令与活学活用
通过前两讲的学习,相信大家已经有了很多IDEA,本讲讲一下脚本的基本组成命令以及如何活用前两讲。基本命令:这行用来开始一个脚本Begin 脚本名称这行用来结束End 脚本名称定义变量有三种写法,数值范围依次扩大Short 变量名Long 变量名Float 变量名将某一变量设为特定数值Set 变量名 to 数值得到某一变量的当前数值get 变量名条件语句If ( . . .)[elseif . . .][else . . .]endif等号和不等号这样写== != 不大于和不小于这样写<= >= 这行用来加入注释,这部分是当脚本行数较多(例如数百行)时方便编写者浏览,对脚本的运行不会有任何影响。; 内容活用实例一:Begin aaspsw1float timershort stateif ( MenuMode == 1 )returnendifif ( OnActivate == 1 )if ( State == 0 )PlaySound "Open Lock"set state to 10endifendifif ( State >= 10 )set timer to ( timer + GetSecondsPassed )if ( timer < 6 )"aasplt2"->disable"aasplt2"->Playsound "Door Stone Open"elseif ( timer > 11 )set State to 0set timer to 0elseif ( timer > 6 )if ( State == 10 )"aasplt2"->Playsound "Dwemer Door Open"Set State to 20endif"aasplt2"->enableendifendifend aaspsw1以上就是我为sphinx's blessing中的水晶开关写的脚本。功能是点击该开关后水晶消失并播放一个声音,6秒后水晶重现并播放一个声音。其中的aasplt2就是那个MOD中新建的水晶的ID。注意这一行“set timer to ( timer + GetSecondsPassed )”,定义了一个变量timer配合SET....TO命令来实现探测时间的流逝。活用实例二:begin aa_splaptopif ( menumode == 1 )returnendifshort timerIf ( OnActivate == 1 )if ( timer < 6 )aalaptop3->move y 1000aalaptop3->PlaySound "Door Stone Open"messagebox "Something move"Set timer to ( timer + 1 )endifif ( timer == 6 )aalaptop3->setpos y -772.79aalaptop3->PlaySound "conjuration hit"messagebox "Something move"set timer to 0endifendifend aa_splaptop这是我关联在墙上一幅画的脚本,玩家每点击那幅画一下,则同单元内的另一物品aalaptop3会沿Y方向移动1000个单位,每当玩家点击到第六下时aalaptop3将回复到最初的位置(y= -772.79)。这个脚本的中心思想是实现了“累计次数”的概念。本讲结束。祝大家玩的快乐,生活的快乐Sphinx于2005年2月24日发表