吾爱尚玩资源基地

标题: 【千年服务端】智能怪脚本设置及设计精髓 [打印本页]

作者: admin    时间: 4 天前
标题: 【千年服务端】智能怪脚本设置及设计精髓
智能怪脚本设置及设计精髓


【设计思路】
  这次不能算是什么活动,只能说是游戏中的一段情节。做一个会说话的怪,要求这个怪在有人时说话、挨打时说话、打死别人说话、被别人打死也说话,总之这是一口水怪,能通过脚本实现这一功能。在编写这个脚本的过程中才发现,除了让它说话还可以实现其它功能,比如招怪。于是,用了两天时间反复修改测试并实现了预期的功能。
  在中央市场有一口水超级多的人形怪--小泉(名人啊,咱们邻国的领导),每当有人靠近它,它会随机说一句话。比如:“干嘛来了?想杀我啊?”、“别靠近我!死了别怪我!”等等的狂话。当你离它而去,它又会追着你的PP叫嚣:“别走啊!怕我了?!哈哈...”。甚是讨厌!怎么办?打死它!于是,你开始痛击。。。。当然了,它也打你,呵呵,就看谁的武功高了。当你砍了它几刀后,它会边说着废话边把它家的家犬--“纯一狼”叫来一起打你。你把它打死,或者不幸被它打死,它都会继续说着废话并把家犬收回去。
【情节脚本】
  看似简单的一段情节,要实现起来还真没那么容易。这个脚本费了我很大的劲,不过,通过编写这个脚本也使自己的水平有了新的提高,这就是收获,呵呵。
  在这个脚本里,判断人来了、人走了、怪死、人死都好办,有现成的例子可以参考。关键是如何解决怪招怪的地点和数量问题。还是结合着脚本说吧:
智能怪.txt
  1. unit 智能怪;
  2. interface
  3. function  GetToken (aStr, aToken, aSep : String) : String;
  4. function  CompareStr (aStr1, aStr2 : String) : Boolean;
  5. function  callfunc (aText: string): string;
  6. procedure print (aText: string);
  7. function  Random (aScope: integer): integer;
  8. function  Length (aText: string): integer;
  9. procedure Inc (aInt: integer);
  10. procedure Dec (aInt: integer);
  11. function  StrToInt (astr: string): integer;
  12. function  IntToStr (aInt: integer): string;
  13. procedure exit;
  14. procedure OnDie (aStr : String);
  15. procedure OnChangeState (aStr : String);
  16. procedure OnApproach (aStr : String);
  17. procedure OnAway (aStr : String);
  18. procedure OnHit (aStr : String);
  19. procedure OnRegen (aStr : String);
  20. var
  21.    zhuangtai : Integer = 0;
  22. //这一段定义招来的怪名字和数量的全局变量,可以根据自己的需要设置  
  23.    monstername : String = '狂犬1';
  24.    monstercount : Integer = 4;
  25. ////////////////////////////////////////////////////////////////
  26. implementation
  27. procedure OnRegen (aStr : String);
  28. begin
  29.    zhuangtai := 0;
  30.    exit;
  31. end;
  32. //当有人靠近时,怪随机从10句话里说一句,这些话可以发挥你的想像力修改
  33. procedure OnApproach (aStr : String);
  34. var
  35.    Str : String;
  36.    iRandom : Integer;
  37. begin
  38.    Str := callfunc ('getsenderrace');
  39.    if Str <> '1' then exit;
  40.       iRandom := Random (10);
  41.       if iRandom = 0 then begin
  42.          print ('say 干嘛来了?想杀我啊?');
  43.          exit;
  44.       end;
  45.       if iRandom = 1 then begin
  46.          print ('say 瞧你那点武功,干嘛来了?');
  47.          exit;
  48.       end;
  49.       if iRandom = 2 then begin
  50.          print ('say 想找死啊?');
  51.          exit;
  52.       end;
  53.       if iRandom = 3 then begin
  54.          print ('say 干死你舒服啊?');
  55.          exit;
  56.       end;
  57.       if iRandom = 4 then begin
  58.          print ('say 找我比武可不是容易的事啊!');
  59.          exit;
  60.       end;
  61.       if iRandom = 5 then begin
  62.          print ('say 你可想好了!让我打死不许哭啊!');
  63.          exit;
  64.       end;
  65.       if iRandom = 6 then begin
  66.          print ('say 别靠近我!死了别怪我!');
  67.          exit;
  68.       end;
  69.       if iRandom = 7 then begin
  70.          print ('say 来来来让我杀了你先?');
  71.          exit;
  72.       end;
  73.       if iRandom = 8 then begin
  74.          print ('say 本怪就是狂!不服来试试?');
  75.          exit;
  76.       end;
  77.       if iRandom = 9 then begin
  78.          print ('say 比划啥啊?过来!!');
  79.          exit;
  80.       end;
  81. end;
  82. //与上一段相反,这是人离开怪时怪说的话,也可以参照上段,让怪随机说
  83. procedure OnAway (aStr : String);
  84. var
  85.    Str : String;
  86. begin
  87.    Str := callfunc ('getsenderrace');
  88.    if Str <> '1' then exit;
  89.    print ('say 别走啊!怕我了?!哈哈...');
  90.    exit;
  91. end;
  92. //当怪被攻击时所做的反应。此段是脚本的关键点。
  93. procedure OnHit (aStr : String);
  94. var
  95.    Str, rdStr, xStr, yStr : String;
  96.    x, y, i : Integer;
  97.    ComStr : String = 'mapaddobjbyname monster ';
  98. begin
  99.    Str := callfunc ('getsenderrace');
  100.    if Str <> '1' then exit;
  101.    Inc(zhuangtai);
  102. //当怪被攻击3次时说的话
  103.    if zhuangtai = 3 then begin
  104.       print ('say 这就开打啊?也不先通知一声!');
  105.       exit;
  106.    end;
  107. //当怪被攻击5次时说的话,并且招来其它怪一起打你
  108.    if zhuangtai = 5 then begin
  109.       print ('say 欺负我一个人啊?看我放家犬来咬你!');
  110. //判断人所在的位置,并取得附近的坐标
  111.       Str := callfunc ('getsenderposition');
  112.       Str := GetToken (Str, xStr, '_');
  113.       x := StrToInt (xStr);
  114.       Str := GetToken (Str, yStr, '_');
  115.       y := StrToInt (yStr);
  116.       Inc(x);
  117.       Inc(y);
  118.       xStr := IntToStr(x);
  119.       yStr := IntToStr(y);
  120. //用一个For To循环来放相应数量的怪,如果我没记错,千年脚本里此循环的使用是没有先例的
  121.       for i:=1 to monstercount do
  122.       begin
  123.       Str := ComStr + monstername;
  124.       Str := Str + ' ';
  125.       Str := Str + xStr;
  126.       Str := Str + ' ';
  127.       Str := Str + yStr;
  128.       Str := Str + ' 3 0 true';
  129.       print (Str);
  130.       end;
  131.       exit;
  132.    end;
  133. //当怪被攻击20下和40下时,如果还没死,它要BS你一下了,呵呵。努力哟!
  134.    if zhuangtai = 20 then begin
  135.       print ('say 武功也不行啊!还跟我斗?');
  136.       exit;
  137.    end;
  138.    if zhuangtai = 40 then begin
  139.       print ('say 哈哈!你太弱了!这么长时间都杀不死我!!');
  140.       exit;
  141.    end;
  142. end;
  143. //如果怪死了,调整状态并收回放出来的怪
  144. procedure OnDie (aStr : String);
  145. var
  146.    Str : String;
  147. begin
  148.    Str := callfunc ('getsenderrace');
  149.    if Str <> '1' then exit;
  150.    zhuangtai := 0;
  151.    print ('say 把我打死你会后悔的!我还要回来找你!');
  152.    Str := 'mapdelobjbyname monster ' + monstername;
  153.    print (Str);
  154.    exit;
  155. end;
  156. //如果人死了,调整状态并收回放出来的怪,同时刺激人一句!
  157. procedure OnChangeState (aStr : String);
  158. var
  159.    Str, Name : String;
  160. begin
  161.    if aStr <> 'die' then exit;
  162.    Str := callfunc ('getsenderrace');
  163.    if Str <> '1' then exit;
  164.    print ('say 瞧你这点出息!自不量力啊!!');
  165.    zhuangtai := 0;
  166.    Str := 'mapdelobjbyname monster ' + monstername;
  167.    print (Str);
  168.    exit;
  169. end;
  170. end.
复制代码

【其它设置】
  为了配合此情节,需要修改以下几个相关文件的内容:
  1、虽然这个口水怪和它招来的怪可以利用已有的任何一种怪来做,但最好还是新添加怪物,这样不会与原服务端发生冲突。尤其是那狗,如果你直接用狂犬,而且在长城以南这个地图里用,你会发现,当怪死或者人死收回放出来的狗时,整个长城以南的狂犬都被收了。所以,我是按照狂犬的数据重新添加了新怪物,它的ViewName是“纯一狼”,呵呵。打开Init/Monster.sdb,在其后添加两条新数据:
Name,ViewName,Shape,Animate,Kind,HaveItem,virtue,VirtueLevel,RegenInterval,boSeller,SpellResistRate,ActionWidth,WalkSpeed,Damage,DamageHead,DamageArm,DamageLeg,Armor,Life,AttackSpeed,Avoid,Recovery,Accuracy,SpendLife,HitArmor,boViewHuman,boAutoAttack,boGoodHeart,boHit,boNotBowHit,boIce,boControl,boRightRemove,EscapeLife,ViewWidth,boAttack,boBoss,boVassal,VassalCount,AttackType,AttackMagic,HaveMagic,boChangeTarget,SoundStart,SoundAttack,SoundDie,SoundNormal,SoundStructed,EffectStart,EffectStructed,EffectEnd,FallItem,FallItemRandomCount,XControl,YControl,boRandom,boPK,EventType,ArmorWHPercent,ShortExp,LongExp,RiseShortExp,RiseLongExp,HandExp,LimitSkill,MonType,sex,arr_body,arr_gloves,arr_upunderwear,arr_shoes,arr_downunderwear,arr_upoverwear,arr_hair,arr_cap,arr_weapon,Guild,GroupKey,FirstDir,ExtraExp,boOnlyOnce,Calllnterval,Hidelnteral,BestShortExp,BestShortExp2,BestShortExp3,3HitExp,QuestNum,QuestHaveItem,
小泉,小泉,22,7,,金元:3:1,6360,7500,300,,0,8,50,4000,,,,1000,65000,-20,30,-70,,10,,TRUE,TRUE,,TRUE,,,,,0,10,TRUE,,,,,,,TRUE,,9114,9115,,9136,,,,,,,,,,,15,,,,,,,,,,,,,,,,,,,,,12720,,,,,,,572,,,
狂犬1,纯一狼,8,3,,肉:5:1:皮:5:1:风云戒指:1:30,105,2900,,,0,8,180,1000,,,,1000,8000,-20,-20,0,,10,,TRUE,TRUE,,TRUE,,,,,0,7,TRUE,,,,,,,,,2400,2401,2402,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,10,,,,,,,,,,

  2、注册脚本,打开Script/Script.sdb,在最后一行添加新数据,并记住新数据的编号(注意,那个编号136是我的服务端此文件里顺着编下来的号,你的不一定就是此数):
Name,FileName,Desc,
136,
智能怪.txt,,
  3、打算把这个口水怪放到哪个地图里,就把相应的Setting/CreateMonsterXXX.sdb打开,添加一条新数据(注意,Script字段一定要与上步注册时的编号一至):
Name,MonsterName,X,Y,Count,Width,Member,Script,
175,小泉,500,500,1,6,,136,
【测试要点】
  情节脚本设置简单的多,只需要修改三个文件。最重要的就是注意脚本编号的正确性;其次是要准确理解掌握设置的方法,这样就可以灵活设置,变幻出多种效果来。在此范例中,智能怪是用的黑捕校外观,你也可以做出更多的智能怪来,也可以让它们做更多的事,就看你的想像力了,呵呵。
(, 下载次数: 0)






欢迎光临 吾爱尚玩资源基地 (http://bbs.523play.com/) Powered by Discuz! X3.4