智能怪脚本设置及设计精髓
【设计思路】
这次不能算是什么活动,只能说是游戏中的一段情节。做一个会说话的怪,要求这个怪在有人时说话、挨打时说话、打死别人说话、被别人打死也说话,总之这是一口水怪,能通过脚本实现这一功能。在编写这个脚本的过程中才发现,除了让它说话还可以实现其它功能,比如招怪。于是,用了两天时间反复修改测试并实现了预期的功能。
在中央市场有一口水超级多的人形怪--小泉(名人啊,咱们邻国的领导),每当有人靠近它,它会随机说一句话。比如:“干嘛来了?想杀我啊?”、“别靠近我!死了别怪我!”等等的狂话。当你离它而去,它又会追着你的PP叫嚣:“别走啊!怕我了?!哈哈...”。甚是讨厌!怎么办?打死它!于是,你开始痛击。。。。当然了,它也打你,呵呵,就看谁的武功高了。当你砍了它几刀后,它会边说着废话边把它家的家犬--“纯一狼”叫来一起打你。你把它打死,或者不幸被它打死,它都会继续说着废话并把家犬收回去。
【情节脚本】
看似简单的一段情节,要实现起来还真没那么容易。这个脚本费了我很大的劲,不过,通过编写这个脚本也使自己的水平有了新的提高,这就是收获,呵呵。
在这个脚本里,判断人来了、人走了、怪死、人死都好办,有现成的例子可以参考。关键是如何解决怪招怪的地点和数量问题。还是结合着脚本说吧:
智能怪.txt
- unit 智能怪;
- interface
- function GetToken (aStr, aToken, aSep : String) : String;
- function CompareStr (aStr1, aStr2 : String) : Boolean;
- function callfunc (aText: string): string;
- procedure print (aText: string);
- function Random (aScope: integer): integer;
- function Length (aText: string): integer;
- procedure Inc (aInt: integer);
- procedure Dec (aInt: integer);
- function StrToInt (astr: string): integer;
- function IntToStr (aInt: integer): string;
- procedure exit;
- procedure OnDie (aStr : String);
- procedure OnChangeState (aStr : String);
- procedure OnApproach (aStr : String);
- procedure OnAway (aStr : String);
- procedure OnHit (aStr : String);
- procedure OnRegen (aStr : String);
- var
- zhuangtai : Integer = 0;
- //这一段定义招来的怪名字和数量的全局变量,可以根据自己的需要设置
- monstername : String = '狂犬1';
- monstercount : Integer = 4;
- ////////////////////////////////////////////////////////////////
- implementation
- procedure OnRegen (aStr : String);
- begin
- zhuangtai := 0;
- exit;
- end;
- //当有人靠近时,怪随机从10句话里说一句,这些话可以发挥你的想像力修改
- procedure OnApproach (aStr : String);
- var
- Str : String;
- iRandom : Integer;
- begin
- Str := callfunc ('getsenderrace');
- if Str <> '1' then exit;
- iRandom := Random (10);
- if iRandom = 0 then begin
- print ('say 干嘛来了?想杀我啊?');
- exit;
- end;
- if iRandom = 1 then begin
- print ('say 瞧你那点武功,干嘛来了?');
- exit;
- end;
- if iRandom = 2 then begin
- print ('say 想找死啊?');
- exit;
- end;
- if iRandom = 3 then begin
- print ('say 干死你舒服啊?');
- exit;
- end;
- if iRandom = 4 then begin
- print ('say 找我比武可不是容易的事啊!');
- exit;
- end;
- if iRandom = 5 then begin
- print ('say 你可想好了!让我打死不许哭啊!');
- exit;
- end;
- if iRandom = 6 then begin
- print ('say 别靠近我!死了别怪我!');
- exit;
- end;
- if iRandom = 7 then begin
- print ('say 来来来让我杀了你先?');
- exit;
- end;
- if iRandom = 8 then begin
- print ('say 本怪就是狂!不服来试试?');
- exit;
- end;
- if iRandom = 9 then begin
- print ('say 比划啥啊?过来!!');
- exit;
- end;
- end;
- //与上一段相反,这是人离开怪时怪说的话,也可以参照上段,让怪随机说
- procedure OnAway (aStr : String);
- var
- Str : String;
- begin
- Str := callfunc ('getsenderrace');
- if Str <> '1' then exit;
- print ('say 别走啊!怕我了?!哈哈...');
- exit;
- end;
- //当怪被攻击时所做的反应。此段是脚本的关键点。
- procedure OnHit (aStr : String);
- var
- Str, rdStr, xStr, yStr : String;
- x, y, i : Integer;
- ComStr : String = 'mapaddobjbyname monster ';
- begin
- Str := callfunc ('getsenderrace');
- if Str <> '1' then exit;
- Inc(zhuangtai);
- //当怪被攻击3次时说的话
- if zhuangtai = 3 then begin
- print ('say 这就开打啊?也不先通知一声!');
- exit;
- end;
- //当怪被攻击5次时说的话,并且招来其它怪一起打你
- if zhuangtai = 5 then begin
- print ('say 欺负我一个人啊?看我放家犬来咬你!');
- //判断人所在的位置,并取得附近的坐标
- Str := callfunc ('getsenderposition');
- Str := GetToken (Str, xStr, '_');
- x := StrToInt (xStr);
- Str := GetToken (Str, yStr, '_');
- y := StrToInt (yStr);
- Inc(x);
- Inc(y);
- xStr := IntToStr(x);
- yStr := IntToStr(y);
- //用一个For To循环来放相应数量的怪,如果我没记错,千年脚本里此循环的使用是没有先例的
- for i:=1 to monstercount do
- begin
- Str := ComStr + monstername;
- Str := Str + ' ';
- Str := Str + xStr;
- Str := Str + ' ';
- Str := Str + yStr;
- Str := Str + ' 3 0 true';
- print (Str);
- end;
- exit;
- end;
- //当怪被攻击20下和40下时,如果还没死,它要BS你一下了,呵呵。努力哟!
- if zhuangtai = 20 then begin
- print ('say 武功也不行啊!还跟我斗?');
- exit;
- end;
- if zhuangtai = 40 then begin
- print ('say 哈哈!你太弱了!这么长时间都杀不死我!!');
- exit;
- end;
- end;
- //如果怪死了,调整状态并收回放出来的怪
- procedure OnDie (aStr : String);
- var
- Str : String;
- begin
- Str := callfunc ('getsenderrace');
- if Str <> '1' then exit;
- zhuangtai := 0;
- print ('say 把我打死你会后悔的!我还要回来找你!');
- Str := 'mapdelobjbyname monster ' + monstername;
- print (Str);
- exit;
- end;
- //如果人死了,调整状态并收回放出来的怪,同时刺激人一句!
- procedure OnChangeState (aStr : String);
- var
- Str, Name : String;
- begin
- if aStr <> 'die' then exit;
- Str := callfunc ('getsenderrace');
- if Str <> '1' then exit;
- print ('say 瞧你这点出息!自不量力啊!!');
- zhuangtai := 0;
- Str := 'mapdelobjbyname monster ' + monstername;
- print (Str);
- exit;
- end;
- 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,
【测试要点】
情节脚本设置简单的多,只需要修改三个文件。最重要的就是注意脚本编号的正确性;其次是要准确理解掌握设置的方法,这样就可以灵活设置,变幻出多种效果来。在此范例中,智能怪是用的黑捕校外观,你也可以做出更多的智能怪来,也可以让它们做更多的事,就看你的想像力了,呵呵。
|