Guest User

Untitled

a guest
Feb 21st, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.03 KB | None | 0 0
  1. use npc;
  2. use os;
  3. use uo;
  4. use cfgfile;
  5.  
  6. include "include/eventID";
  7. include "include/attributes";
  8. include "include/sysEvent";
  9. include "include/NPCBackpacks";
  10. include "include/NPCCast";
  11. include "include/randName";
  12. include "include/dist";
  13. include "include/snooping";
  14.  
  15. set_priority(5);
  16.  
  17. const HALT_THRESHOLD := 15;
  18. const SYSEVENT_ALL_GUARD_CMD := 0x13;
  19. const EVID_WAKEUP:= 0xd001;
  20.  
  21. const me := Self();
  22. var npccfgfile := ReadConfigFile("npcdesc");
  23. var dmgsound := npccfgfile[me.npctemplate].dmgsound;
  24. var hit := npccfgfile[me.npctemplate].attackhitsound;
  25. var idlesnd1 := npccfgfile[me.npctemplate].idlesound1;
  26. var idlesnd2 := npccfgfile[me.npctemplate].idlesound2;
  27. var FLAME_STRENGTH := npccfgfile[me.npctemplate].flamestrength;
  28. var controlLevel := npccfgfile[me.npctemplate].tameskill;
  29. var caster := 0;
  30. var spells;
  31. var firebreather;
  32. var mypack := FindPack(me.serial);
  33. var orneriness := npccfgfile[me.npctemplate].orneriness;
  34. var masterserial := GetObjProperty(me, "master");
  35. var saywords := 0;
  36. var master;
  37. var masterLevel;
  38. var chaseloop := 0;
  39. var guarding :=0;
  40. var following := 0;
  41. var nextwatch := ReadGameClock();
  42. var happiness := CInt(GetObjProperty(me,"happiness"));
  43. var waittime := 120;
  44. var LAST_BREATH := ReadGameClock();
  45. if((happiness < 11) && (GetObjProperty(me,"permtame")))
  46. happiness := 100;
  47. SetObjProperty(me,"happiness",100);
  48. endif
  49.  
  50. if((!happiness)||(happiness == error))
  51. happiness := 100;
  52. SetObjProperty(me,"happiness", 100);
  53. endif
  54.  
  55. program TamedAI()
  56. Detach();
  57. var time := ReadGameClock();
  58. SetObjProperty(me,"countercheck", time);
  59. var parms := {};
  60. parms[1] := me;
  61. parms[2] := time;
  62. start_script(":taming:happyCounter", parms);
  63. master := SystemFindObjectBySerial(masterserial, SYSFIND_SEARCH_OFFLINE_MOBILES);
  64. if(!master)
  65. ApplyRawDamage(me, GetHP(me)+ 1);
  66. return;
  67. endif
  68.  
  69. masterLevel := GetEffectiveSkill(master, SKILLID_TAMING);
  70. if(!canControl())
  71. //TODO: later on this will be implemented
  72. //return;
  73. endif
  74. me.setmaster(master);
  75. if(me.name["<random>"])
  76. SetName(me, RandomName(me));
  77. endif
  78. if(!happiness)
  79. happiness := 10;
  80. endif
  81. if(!orneriness)
  82. orneriness := 0;
  83. endif
  84. if(!me.backpack)
  85. var newbackpack := CreateItemAtLocation(5288, 1176, 0, 0xe75,1);
  86. EquipItem(me, newbackpack);
  87. endif
  88. SetAnchor(me.x, me.y, 20, 0);
  89. var npccfg := ReadConfigFile("npcdesc");
  90. if(npccfg[me.npctemplate].spell)
  91. caster := 1;
  92. spells := GetConfigStringArray(npccfg[me.npctemplate], "spell");
  93. endif
  94. if(FLAME_STRENGTH)
  95. firebreather := 1;
  96. endif
  97. SetWarMode(0);
  98. SetObjProperty(me, "serial", me.serial);
  99. MainAILoop();
  100. endprogram
  101.  
  102. function FindPack(myserial)
  103. var mybank := OpenTamedStorageAreas();
  104. var bank_obj_name := "Bankbox " + Hex(myserial);
  105. var bankbox := FindRootItemInStorageArea(mybank, bank_obj_name);
  106. if(!bankbox)
  107. if((me.graphic == 0x123)||(me.graphic == 0x124))
  108. bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, 0x966b);
  109. else
  110. bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, UOBJ_BANKBOX);
  111. endif
  112. else
  113. if(((me.graphic == 0x123)||(me.graphic == 0x124))&&((me.backpack).objtype == UOBJ_BANKBOX))
  114. DestroyItem(bankbox);
  115. bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, 0x966b);
  116. endif
  117. endif
  118. return bankbox;
  119. endfunction
  120.  
  121. function MainAILoop()
  122. var ev;
  123. nextwatch := ReadGameClock();
  124. var mhp;
  125. EnableMainEvents();
  126. while(GetHp(me)> 0)
  127. happiness := GetObjProperty(me,"happiness");
  128. mhp := GetHp(me);
  129. if(GetObjProperty(me, "onhold"))
  130. HoldLoop("onhold");
  131. elseif(GetObjProperty(me, "stabled"))
  132. HoldLoop("stabled");
  133. elseif(GetObjProperty(me, "mounted"))
  134. HoldLoop("mounted");
  135. else
  136. if(happiness < 10)
  137. release();
  138. endif
  139. ev := os::wait_for_event(waittime);
  140. case(ev.type)
  141. SYSEVENT_SPEECH: ProcessSpeech(ev);
  142. SYSEVENT_ENGAGED: Fight(ev.source);
  143. SYSEVENT_DAMAGED: if(GetHp(me)< mhp)
  144. if(ev.source)
  145. Fight(ev.source);
  146. endif
  147. if(dmgsound) PlaySoundEffect(me, dmgsound); endif
  148. endif
  149. SYSEVENT_DOUBLECLICKED: if((ev.source == master) or (ev.source.cmdlevel > 2))
  150. OpenMyPack();
  151. else
  152. snoop(ev.source, me);
  153. endif
  154. SYSEVENT_ITEM_GIVEN: if(ev.source == master)
  155. TakeItem(ev);
  156. endif
  157. EVID_ALL_ATTACK_CMD: Fight(ev.target);
  158. EVID_ALL_FOLLOW_CMD: following := ev.target;
  159. SYSEVENT_ALL_GUARD_CMD: guarding := ev.target;
  160. PrintTextAbove(me,"*guarding " + guarding.name + "*");
  161. endcase
  162. if(following)
  163. waittime := 0;
  164. Follow();
  165. elseif(guarding)
  166. waittime := 7;
  167. Guard();
  168. else
  169. waittime := 120;
  170. EraseObjProperty(me,"#flees");
  171. endif
  172. endif
  173. endwhile
  174. endfunction
  175.  
  176. function HoldLoop(type)
  177. disablemainevents();
  178. EnableTameEvents();
  179. EnableEvents(EVID_WAKEUP);
  180. var ev, happiness;
  181. while(GetObjProperty(me, type))
  182. if(type == "mounted")
  183. happiness := GetObjProperty(me, "happiness");
  184. ev := os::wait_for_event(60);
  185. if(happiness < 10)
  186. release();
  187. endif
  188. else
  189. ev := os::wait_for_event(300);
  190. endif
  191. if(ev.type == EVID_WAKEUP)
  192. EraseObjProperty(me, type);
  193. endif
  194. endwhile
  195. EnableMainEvents();
  196. endfunction
  197.  
  198. function Fight(opponent)
  199. var oldfollowing := following;
  200. var flees := 0;
  201. SetDexterityMod(me, 0);
  202. following := 0;
  203. if(opponent == me)
  204. return;
  205. endif
  206. TurnToward(opponent);
  207. SetOpponent(opponent);
  208. var ev;
  209. var loops := 0;
  210. var waittime := 0;
  211. while((opponent) && (!opponent.dead || !opponent.hidden || !opponent.concealed)&&(dist(me,opponent)< 15))
  212. if(!CloseDistance(opponent))
  213. loops := loops + 1;
  214. waittime := 0;
  215. else
  216. if(!CheckLineOfSight(me, opponent))
  217. loops := loops + 1;
  218. endif
  219. waittime := 1;
  220. endif
  221. ev := wait_for_event(waittime);
  222. case(ev.type)
  223. EVID_ALL_ATTACK_CMD: opponent := ev.target;
  224. SetOpponent(opponent);
  225. EVID_ALL_FOLLOW_CMD: following := ev.target;
  226. SYSEVENT_ALL_GUARD_CMD: guarding := ev.target;
  227. PrintTextAbove(me,"*guarding " + guarding.name + "*");
  228. SYSEVENT_SPEECH: ProcessSpeech(ev);
  229. SYSEVENT_ENGAGED:
  230. SYSEVENT_DAMAGED: if(ev.source == opponent)
  231. if(dmgsound) PlaySoundEffect(me, dmgsound); endif
  232. endif
  233. if(ev.source)
  234. if(ev.source != opponent)
  235. if((!CheckLineOfSight(me, opponent))||(RandomInt(8)==1))
  236. opponent := ev.source;
  237. SetOpponent(opponent);
  238. endif
  239. endif
  240. TurnToward(opponent);
  241. endif
  242. EVID_PEACEMADE: SetWarMode(0);
  243. opponent := 0;
  244. following := oldfollowing;
  245. return;
  246. SYSEVENT_DOUBLECLICKED: if((ev.source == master) or (ev.source.cmdlevel > 2))
  247. OpenMyPack();
  248. else
  249. snoop(ev.source, me);
  250. endif
  251. endcase
  252. if(following)
  253. SetWarMode(0);
  254. opponent := 0;
  255. return;
  256. endif
  257. if(firebreather and caster)
  258. if(LAST_BREATH <= ReadGameClock())
  259. if((CheckLineOfSight(me, opponent)) and (dist(me, opponent) <= 15))
  260. if(RandomInt(4) == 1)
  261. cast_meteor(opponent);
  262. else
  263. cast_offensive_spell(me,opponent);
  264. endif
  265. LAST_BREATH := Cint(ReadGameClock() + (RandomInt(4) + 4));
  266. endif
  267. endif
  268. elseif(caster)
  269. if(LAST_BREATH <= ReadGameClock())
  270. if((CheckLineOfSight(me, opponent)) and (dist(me, opponent) <= 15))
  271. cast_offensive_spell(me, opponent);
  272. LAST_BREATH := Cint(ReadGameClock() + (RandomInt(4) + 4));
  273. endif
  274. endif
  275. elseif(firebreather)
  276. if(LAST_BREATH <= ReadGameClock())
  277. if(RandomInt(4)== 1)
  278. cast_meteor(opponent);
  279. endif
  280. LAST_BREATH := Cint(ReadGameClock() + (RandomInt(4) + 4));
  281. endif
  282. endif
  283. if(loops > 30)
  284. flees := flees + 1;
  285. if(flees > 4)
  286. flee(opponent);
  287. endif
  288. return;
  289. endif
  290. endwhile
  291. SetWarMode(0);
  292. opponent := 0;
  293. following := oldfollowing;
  294. endfunction
  295.  
  296. function CloseDistance(opponent)
  297. case (Distance(me, opponent))
  298. 1:
  299. 0: return 1;
  300. default: if(!RunToward(opponent))
  301. return 1;
  302. else
  303. return 0;
  304. endif
  305. endcase
  306. endfunction
  307.  
  308. function Transfer()
  309. if(GetObjProperty(me, "summoned"))
  310. return;
  311. endif
  312. SendSysMessage(master, "Transfer " + me.name + " to whom?");
  313. var whom := Target(master, TGTOPT_NOCHECK_LOS);
  314. if(!whom)
  315. SendSysMessage(master, "Canceled");
  316. return;
  317. endif
  318. if(!canControlTarget(whom))
  319. SendSysMessage(master, "That has no chance of controlling this creature");
  320. return;
  321. endif
  322. if ((whom.cmdlevel == 0) && (GetObjProperty(me,"permtame")))
  323. EraseObjProperty(me,"permtame");
  324. SendSysMessage(master,"Remove permtamed objprop from the animal");
  325. endif
  326. if(hit)
  327. PlaySoundEffect(me, hit);
  328. endif
  329. SetObjProperty(me, "master", whom.serial);
  330. PrintTextAbove(me, me.name + " accepts " + whom.name+ " as its new master");
  331. RestartScript(me);
  332. endfunction
  333.  
  334. function release()
  335. if (GetObjProperty(me,"permtame"))
  336. EraseObjProperty(me,"permtame");
  337. endif
  338. if((GetObjProperty(me,"onhold")) or (GetObjProperty(me,"stabled")))
  339. return;
  340. endif
  341. var char;
  342. var mounted_char;
  343. var onchars := EnumerateOnlineCharacters();
  344. if(GetObjProperty(me,"summoned") == 1)
  345. if(GetObjProperty(me,"mounted") == 1)
  346. char := GetObjProperty(me,"mounted_on");
  347. foreach person in onchars
  348. if(person.serial == CInt(char))
  349. mounted_char := person;
  350. break;
  351. endif
  352. endforeach
  353. dismountme(mounted_char);
  354. endif
  355. PlayStationaryEffect(me.x, me.y, me.z, FX_SMOKE, 0xa, 0xa);
  356. MoveCharacterToLocation(me,5288, 1176, 0,MOVECHAR_FORCELOCATION);
  357. ApplyRawDamage(me, GetHp(me)+ 3);
  358. else
  359. if(GetObjProperty(me,"mounted"))
  360. char := GetObjProperty(me,"mounted_on");
  361. foreach person in onchars
  362. if(person.serial == CInt(char))
  363. mounted_char := person;
  364. break;
  365. endif
  366. endforeach
  367. dismountme(mounted_char);
  368. endif
  369. me.script := npccfgfile[me.npctemplate].script;
  370. PrintTextAbove(me, me.name + " has decided it is better off without a master.");
  371.  
  372. var master := SystemFindObjectBySerial(me.master, SYSFIND_SEARCH_OFFLINE_MOBILES);
  373. var pet_array := GetObjProperty( master, "Pets" );
  374. foreach pet_serial in ( pet_array )
  375. if ( pet_serial == me.serial )
  376. pet_array.erase(_pet_serial_iter);
  377. SetObjProperty(master, "Pets", pet_array );
  378. endif
  379. endforeach
  380. me.setmaster(0);
  381. EraseObjProperty(me, "master");
  382. EraseObjProperty(me, "serial");
  383. EraseObjProperty(me, "script");
  384. EraseObjProperty(me, "happiness");
  385. EraseObjProperty(me, "mounted");
  386. EraseObjProperty(me, "mounted_on");
  387. SetAnchor(me.x,me.y,10,1);
  388. SetHpRegenRate(me ,(100)* 12);
  389. start_script(":taming:untamedremovehouse", {me});
  390. RestartScript(me);
  391. endif
  392. endfunction
  393.  
  394. function dismountme(who)
  395. var mount := GetEquipmentByLayer(who, 25);
  396. me.facing := who.facing;
  397. MoveCharacterToLocation(me, master.x, who.y, who.z, MOVECHAR_FORCELOCATION);
  398. EraseObjProperty(me, "mounted");
  399. EraseObjProperty(me, "mounted_on");
  400. DestroyItem(mount);
  401. endfunction
  402.  
  403. function Fetch()
  404. return;
  405. var tobj := Target(master);
  406. if(tobj.container)
  407. if(dmgsound)
  408. PlaySoundEffect(me, dmgsound);
  409. endif
  410. return;
  411. endif
  412. var times := 0;
  413. while((Distance(me, tobj)> 1)&&(times <= 5)&& CheckLineOfSight(me,tobj))
  414. if(!walktoward(tobj))
  415. sleepms(100);
  416. times := times + 1;
  417. else
  418. times := 0;
  419. endif
  420. endwhile
  421. if(Accessible(me,tobj))
  422. if(hit)
  423. PlaySoundEffect(me, hit);
  424. endif
  425. MoveItemToContainer(tobj, mypack);
  426. while((Distance(me, master)> 1)&&(times <= 5)&& CheckLineOfSight(me,master))
  427. if(!walktoward(master))
  428. sleepms(100);
  429. times := times + 1;
  430. else
  431. times := 0;
  432. endif
  433. endwhile
  434. MoveItemToLocation(tobj, me.x, me.y, me.z, MOVEITEM_FORCELOCATION);
  435. else
  436. if(dmgsound) PlaySoundEffect(me, dmgsound); endif
  437. endif
  438. endfunction
  439.  
  440. function Get()
  441. return;
  442. var tobj := Target(master);
  443. if(tobj.container)
  444. if(dmgsound) PlaySoundEffect(me, dmgsound); endif
  445. return;
  446. endif
  447. var times := 0;
  448. while((Distance(me, tobj)> 1)&&(times <= 5)&& CheckLineOfSight(me,tobj))
  449. if(!walktoward(tobj))
  450. sleepms(100);
  451. times := times + 1;
  452. else
  453. times := 0;
  454. endif
  455. endwhile
  456. if(Accessible(me,tobj))
  457. if(hit) PlaySoundEffect(me, hit); endif
  458. MoveItemToContainer(tobj, mypack);
  459. else
  460. if(dmgsound) PlaySoundEffect(me, dmgsound); endif
  461. endif
  462. endfunction
  463.  
  464. function drop()
  465. foreach myitems in EnumerateItemsInContainer(mypack)
  466. if(myitems.container.serial == mypack.serial)
  467. MoveItemToLocation(myitems, me.x, me.y, me.z,0);
  468. sleepms(100);
  469. endif
  470. endforeach
  471. endfunction
  472.  
  473. function speak()
  474. if(idlesnd1) PlaySoundEffect(me, idlesnd1); endif
  475. endfunction
  476.  
  477. function OpenMyPack();
  478. if((me.graphic == 0x123)||(me.graphic == 0x124))
  479. if(Distance(me, master)> 2)
  480. return;
  481. endif
  482. foreach item in EnumerateItemsInContainer(mypack)
  483. if(item.container == me.backpack)
  484. MoveItemToContainer(item, me.backpack);
  485. endif
  486. endforeach
  487. SendOpenSpecialContainer(master, mypack);
  488. return;
  489. else
  490. if(Distance(me, master)> 1)
  491. return;
  492. endif
  493. var alreadymounted := GetEquipmentByLayer(master, 25);
  494. if(alreadymounted)
  495. return;
  496. endif
  497. var mounttype := 0;
  498. case(me.graphic)
  499. 0xcc: mounttype := 0x3ea2;
  500. 0xc8: mounttype := 0x3e9f;
  501. 0xe2: mounttype := 0x3ea0;
  502. 0xe4: mounttype := 0x3ea1;
  503. 0xdc: mounttype := 0x3ea6;
  504. 0xd2: mounttype := 0x3ea3;
  505. 0xda: mounttype := 0x3ea4;
  506. 0xdb: mounttype := 0x3ea5;
  507. endcase
  508.  
  509. // No stealthing on a horse - DeiviD
  510.  
  511. if(master.stealthsteps)
  512. master.hidden := 0;
  513. SendSysMessage( master, "You cant stealth while riding a horse!");
  514. endif
  515.  
  516. if(mounttype)
  517. if(MoveCharacterToLocation(master,me.x,me.y,me.z,0))
  518. master.facing := me.facing;
  519. var mount := CreateItemAtLocation(5228, 1182, 0, 0xf021,1);
  520. mount.color := me.color;
  521. MoveCharacterToLocation(me, 5228, 1182, 0, MOVECHAR_FORCELOCATION);
  522. mount.graphic := mounttype;
  523. EquipItem(master,mount);
  524. SetObjProperty(mount,"serial", me.serial);
  525. SetObjProperty(me,"mounted", 1);
  526. SetObjProperty(me,"mounted_on", master.serial);
  527. mount.decayat:= 0;
  528. guarding := 0;
  529. following := 0;
  530. endif
  531. endif
  532. endif
  533. endfunction
  534.  
  535. function TakeItem(ev)
  536. var npccfg := ReadConfigFile("npcdesc");
  537. var foodtype := npccfg[me.npctemplate].food;
  538. if(!foodtype)
  539. foodtype := "all";
  540. endif
  541. var cfg := ReadConfigFile("::food");
  542. var elem := FindConfigElem(cfg,foodtype);
  543. var foodarray := GetConfigStringArray(elem,"food");
  544. if(CStr(ev.item.objtype)in foodarray)
  545. PlaySoundEffect(me, CInt(0x3b)+ RandomInt(3));
  546. DestroyItem(ev.item);
  547. PrintTextAbovePrivate(me,"your pet looks happier.", master);
  548. SetObjProperty(me,"happiness", 100);
  549. return;
  550. endif
  551. if((me.graphic == 0x123)||(me.graphic == 0x124))
  552. if(!MoveItemToContainer(ev.item, mypack))
  553. say("*your pet cannot hold that item*");
  554. return;
  555. else
  556. PlaySoundEffect(me,0x49);
  557. endif
  558. else
  559. var yourpack := ev.source.backpack;
  560. MoveItemToContainer(ev.item,yourpack);
  561. endif
  562. endfunction
  563.  
  564. function Guard()
  565. if(nextwatch <= ReadGameClock())
  566. nextwatch := ReadGameClock()+ 7;
  567. if(RandomInt(8)==1)
  568. PrintTextAbove(me,"*guarding " + guarding.name + "*");
  569. endif
  570. foreach mob in ListHostiles(guarding, 9, 0);
  571. Fight(mob);
  572. return;
  573. endforeach
  574. endif
  575. if((!GetStrength(guarding))||(guarding.dead)||(dist(me,guarding)> 15))
  576. guarding := 0;
  577. endif
  578. endfunction
  579.  
  580. function Follow()
  581. var d := Distance(me, following);
  582. if(d <= 2)
  583. waittime := 1;
  584. elseif(d > 15)
  585. following := 0;
  586. waittime := 120;
  587. elseif(d > 6)
  588. if(GetObjProperty(me, "Pause"))
  589. waittime := 2;
  590. else
  591. var ma := 200 - CInt(GetDexterity(me));
  592. SetDexterityMod(me, CInt(GetDexterityMod(me))+ ma);
  593. RunToward(following);
  594. SetDexterityMod(me, CInt(GetDexterityMod(me))- ma);
  595. waittime := 0;
  596. endif
  597. else
  598. if(GetObjProperty(me, "Pause"))
  599. waittime := 2;
  600. else
  601. var ma := 200 - CInt(GetDexterity(me));
  602. SetDexterityMod(me, CInt(GetDexterityMod(me))+ ma);
  603. walktoward(following);
  604. SetDexterityMod(me, CInt(GetDexterityMod(me))- ma);
  605. waittime := 0;
  606. endif
  607. endif
  608. if(guarding)
  609. Guard();
  610. endif
  611. endfunction
  612.  
  613. function canControl()
  614. if(!controlLevel)
  615. controlLevel := 0;
  616. endif
  617.  
  618. if(masterLevel >= controlLevel)
  619. return 1;
  620. else
  621. return 0;
  622. endif
  623. endfunction
  624.  
  625. function canControlTarget(person)
  626. var levelPerson := GetEffectiveSkill(person, SKILLID_TAMING);
  627. if(!controlLevel)
  628. controlLevel := 0;
  629. endif
  630.  
  631. if(levelPerson >= controlLevel)
  632. return 1;
  633. else
  634. return 0;
  635. endif
  636. endfunction
  637.  
  638. function ProcessSpeech(ev)
  639. if(ev.source.serial != masterserial)
  640. return;
  641. endif
  642.  
  643. if(!master)
  644. RestartScript(me);
  645. endif
  646. var evtext := lower(ev.text);
  647. var mename := lower(me.name);
  648. var skillcontrol := Geteffectiveskill (master, SKILLID_ANIMALLORE);
  649. var conf := ReadConfigFile("::npcdesc");
  650. var thecreature := Target(master);
  651. var elem := FindConfigElem(conf, thecreature.npctemplate);
  652. var tameskill := CInt(GetConfigInt(elem, "tameskill"));
  653.  
  654. if(evtext[mename + " kill"] || evtext[mename + " attack"] || evtext["all kill"] || evtext["all attack"])
  655. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  656. SendSysMessage(master, "You have no chance of controlling this creature");
  657. SendSysMessage(master, "controllevel:"+controllevel);
  658. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  659. SendSysMessage(master, "tameskill:"+tameskill);
  660. release();
  661. return;
  662. endif
  663. var what := Target(master, TGTOPT_HARMFUL + TGTOPT_CHECK_LOS);
  664. if(what && !what.hidden)
  665. if(what == ev.source)
  666. return;
  667. elseif(evtext["all kill"] || evtext["all attack"])
  668. if(!canControl())
  669. SendSysMessage(master, "You have no chance of controlling this creature");
  670. return;
  671. endif
  672. if(obediencecheck()== 0)
  673. return;
  674. endif
  675. AllCommand(EVID_ALL_ATTACK_CMD, what);
  676. else
  677. if(obediencecheck()== 0)
  678. return;
  679. endif
  680. Fight(what);
  681. endif
  682. endif
  683. elseif(evtext[mename + " stop"] || evtext["all stop"])
  684. if(!canControl())
  685. SendSysMessage(master, "You have no chance of controlling this creature");
  686. return;
  687. endif
  688. if(obediencecheck()== 0)
  689. return;
  690. endif
  691. guarding := 0;
  692. following := 0;
  693. elseif((evtext[mename + " come"])||(evtext["all come"]))
  694. if(!canControl())
  695. SendSysMessage(master, "You have no chance of controlling this creature");
  696. return;
  697. endif
  698. if(obediencecheck()== 0)
  699. return;
  700. endif
  701. var done := 0;
  702. chaseloop := 0;
  703. while(done == 0)
  704. chaseloop := chaseloop +1;
  705. done := CloseDistance(ev.source);
  706. if(chaseloop > 25)
  707. done :=1;
  708. endif
  709. endwhile
  710. elseif(evtext[mename + " follow"])
  711. if(!canControl())
  712. SendSysMessage(master, "You have no chance of controlling this creature");
  713. return;
  714. endif
  715. if(obediencecheck()== 0)
  716. return;
  717. endif
  718. if(evtext["follow me"])
  719. following := ev.source;
  720. else
  721. var what := Target(master, TGTOPT_CHECK_LOS);
  722. if(what)
  723. following := what;
  724. endif
  725. endif
  726. elseif(evtext["all follow"])
  727. if(!canControl())
  728. SendSysMessage(master, "You have no chance of controlling this creature");
  729. return;
  730. endif
  731. if(obediencecheck()== 0)
  732. return;
  733. endif
  734. if(evtext["follow me"])
  735. following := ev.source;
  736. else
  737. var what := Target(master, TGTOPT_CHECK_LOS);
  738. if(what)
  739. AllCommand(EVID_ALL_FOLLOW_CMD, what);
  740. endif
  741. endif
  742. elseif(evtext[mename + " transfer"] ||(evtext["all transfer"]))
  743. if(!canControl())
  744. SendSysMessage(master, "You have no chance of controlling this creature");
  745. return;
  746. endif
  747. Transfer();
  748. elseif(evtext[mename + " release"] ||(evtext["all release"]))
  749. if(!canControl())
  750. SendSysMessage(master, "You have no chance of controlling this creature");
  751. return;
  752. endif
  753. release();
  754. EraseObjProperty(me,"permtame");
  755. elseif(evtext[mename + " guard me"])
  756. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  757. SendSysMessage(master, "You have no chance of controlling this creature");
  758. SendSysMessage(master, "controllevel:"+controllevel);
  759. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  760. SendSysMessage(master, "tameskill:"+tameskill);
  761. release();
  762. return;
  763. endif
  764. guarding := ev.source;
  765. PrintTextAbove(me,"Im guarding you.");
  766. elseif(evtext[mename + " guard"])
  767. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  768. SendSysMessage(master, "You have no chance of controlling this creature");
  769. SendSysMessage(master, "controllevel:"+controllevel);
  770. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  771. SendSysMessage(master, "tameskill:"+tameskill);
  772. release();
  773. return;
  774. endif
  775. say("Who should I guard?");
  776. var what := Target(master, TGTOPT_HELPFUL + TGTOPT_CHECK_LOS);
  777. if(what.isA(POLCLASS_UOBJECT))
  778. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  779. SendSysMessage(master, "You have no chance of controlling this creature");
  780. SendSysMessage(master, "controllevel:"+controllevel);
  781. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  782. SendSysMessage(master, "tameskill:"+tameskill);
  783. release();
  784. return;
  785. endif
  786. guarding := what;
  787. PrintTextAbove(me,"Im guarding " + guarding.name);
  788. endif
  789. elseif(evtext["all guard me"])
  790. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  791. SendSysMessage(master, "You have no chance of controlling this creature");
  792. SendSysMessage(master, "controllevel:"+controllevel);
  793. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  794. SendSysMessage(master, "tameskill:"+tameskill);
  795. release();
  796. return;
  797. endif
  798. guarding := ev.source;
  799. PrintTextAbove(me,"Im guarding you");
  800. elseif(evtext["all guard"])
  801. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  802. SendSysMessage(master, "You have no chance of controlling this creature");
  803. SendSysMessage(master, "controllevel:"+controllevel);
  804. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  805. SendSysMessage(master, "tameskill:"+tameskill);
  806. release();
  807. return;
  808. endif
  809. say("Who should I guard?");
  810. var what := Target(master, TGTOPT_HELPFUL + TGTOPT_CHECK_LOS);
  811. if(GetHp(what))
  812. if((!canControl()) || (tameskill > (skillcontrol - 10)))
  813. SendSysMessage(master, "You have no chance of controlling this creature");
  814. SendSysMessage(master, "controllevel:"+controllevel);
  815. SendSysMessage(master, "skillcontrol:"+skillcontrol);
  816. SendSysMessage(master, "tameskill:"+tameskill);
  817. release();
  818. return;
  819. endif
  820. AllCommand(SYSEVENT_ALL_GUARD_CMD, what);
  821. endif
  822. elseif(evtext[mename + " fetch"])
  823. if(obediencecheck()== 0)
  824. return;
  825. endif
  826. Fetch();
  827. elseif(evtext[mename + " get"])
  828. if(obediencecheck()== 0)
  829. return;
  830. endif
  831. Get();
  832. elseif(evtext[mename + " drop"])
  833. if(obediencecheck()== 0)
  834. return;
  835. endif
  836. drop();
  837. elseif(evtext[mename + " speak"] ||(evtext["all speak"]))
  838. if(obediencecheck()== 0)
  839. return;
  840. endif
  841. speak();
  842. endif
  843. endfunction
  844.  
  845. function AllCommand(evtype,what)
  846. var mobs := ListMobilesNearLocation(master.x, master.y, master.z, 9);
  847. var eve := array;
  848. eve.+type := evtype;
  849. eve.+source := me;
  850. eve.+target := what;
  851. SendEvent(me, eve);
  852. foreach mob in mobs
  853. if(GetObjProperty(mob, "master")== me.master.serial)
  854. SendEvent(mob, eve);
  855. endif
  856. endforeach
  857. endfunction
  858.  
  859. function cast_meteor(opponent)
  860. var base := Cint(((FLAME_STRENGTH * GetHp(me)) / GetMaxHp(me)) / 2);
  861. var dmg := RandomInt(base) + base;
  862. PerformAction(me,0x0c);
  863. PlaysoundEffect(me, 0x16b);
  864. sleep(3);
  865. PlayMovingEffect(me, opponent, 0x36d4, 10, 1, 1);
  866. ApplyRawDamage(opponent, dmg);
  867. endfunction
  868.  
  869. function flee(opponent)
  870. var numflees := GetObjProperty(me,"#flees");
  871. if(numflees)
  872. if(numflees > 5)
  873. MoveCharacterToLocation(me,5288,1176,0,MOVECHAR_FORCELOCATION);
  874. SetObjProperty(me,"guardkill",1);
  875. ApplyRawDamage(me, GetMaxHp(me)+ 3);
  876. else
  877. numflees := numflees + 1;
  878. endif
  879. else
  880. numflees := 1;
  881. endif
  882. SetObjProperty(me,"#flees",numflees);
  883. var runs := 0;
  884. while((Distance(me, opponent)< 20)&&(runs < 50))
  885. RunAwayFrom(opponent);
  886. runs := runs +1;
  887. wait_for_event(0);
  888. endwhile
  889. RestartScript(me);
  890. endfunction
  891.  
  892. function obediencecheck()
  893. var arry := { 0xcc, 0xc8, 0xe2, 0xe4, 0x123, 0x124, 0xd2, 0xdb };
  894. if(me.objtype in arry)
  895. return 1;
  896. endif
  897. happiness := GetObjProperty(me, "happiness");
  898. var defiance :=(orneriness * 20)-30;
  899. if(defiance < 1)
  900. defiance := 1;
  901. endif
  902. defiance := defiance + petcount();
  903. var finaldefiance := CInt(defiance + RandomInt(40));
  904. if(GetObjProperty(me, "summoned")== 1)
  905. return 1;
  906. elseif(finaldefiance > happiness)
  907. if(dmgsound) PlaySoundEffect(me, dmgsound); endif
  908. happiness := happiness - orneriness;
  909. SetObjProperty(me, "happiness",(happiness-1));
  910. if(happiness < 10)
  911. release();
  912. endif
  913. return 0;
  914. else
  915. if(hit) PlaySoundEffect(me, hit); endif
  916. if(happiness < 10)
  917. release();
  918. return 0;
  919. endif
  920. return 1;
  921. endif
  922. endfunction
  923.  
  924. function petcount()
  925. var pets := 0;
  926. var mobs := ListMobilesNearLocation(me.x,me.y,me.z,8);
  927. foreach mob in mobs
  928. if((mob.script == "tamed")&&(GetObjProperty(mob,"master")==masterserial))
  929. if(GetObjProperty(mob, "summoned"))
  930. pets := pets + 0;
  931. else
  932. pets := pets+5;
  933. endif
  934. endif
  935. endforeach
  936. return pets;
  937. endfunction
  938.  
  939. function EnableTameEvents()
  940. EnableEvents(EVID_WAKEUP);
  941. endfunction
  942.  
  943. //function EnableMainEvents()
  944. // EnableEvents(SYSEVENT_SPEECH);
  945. // EnableEvents(SYSEVENT_ENGAGED);
  946. // EnableEvents(SYSEVENT_DAMAGED);
  947. // EnableEvents(SYSEVENT_DOUBLECLICKED);
  948. // EnableEvents(SYSEVENT_ITEM_GIVEN);
  949. // EnableEvents(EVID_PEACEMADE);
  950. //endfunction
  951.  
  952. function EnableMainEvents()
  953. //RegisterForSpeechEvents(me, 15);
  954. EnableEvents(SYSEVENT_SPEECH, 15);
  955. EnableEvents(SYSEVENT_ENGAGED);
  956. EnableEvents(SYSEVENT_DAMAGED);
  957. EnableEvents(SYSEVENT_DOUBLECLICKED);
  958. EnableEvents(SYSEVENT_ITEM_GIVEN);
  959. EnableEvents(EVID_PEACEMADE);
  960. endfunction
  961.  
  962. function disablemainevents()
  963. DisableEvents(SYSEVENT_SPEECH);
  964. DisableEvents(SYSEVENT_ENGAGED);
  965. DisableEvents(SYSEVENT_DAMAGED);
  966. DisableEvents(SYSEVENT_ITEM_GIVEN);
  967. DisableEvents(EVID_PEACEMADE);
  968. endfunction
Add Comment
Please, Sign In to add comment