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