Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use npc;
- use os;
- use uo;
- use cfgfile;
- include "include/eventID";
- include "include/attributes";
- include "include/sysEvent";
- include "include/NPCBackpacks";
- include "include/NPCCast";
- include "include/randName";
- include "include/dist";
- include "include/snooping";
- set_priority(5);
- const HALT_THRESHOLD := 15;
- const SYSEVENT_ALL_GUARD_CMD := 0x13;
- const EVID_WAKEUP:= 0xd001;
- const me := Self();
- var npccfgfile := ReadConfigFile("npcdesc");
- var dmgsound := npccfgfile[me.npctemplate].dmgsound;
- var hit := npccfgfile[me.npctemplate].attackhitsound;
- var idlesnd1 := npccfgfile[me.npctemplate].idlesound1;
- var idlesnd2 := npccfgfile[me.npctemplate].idlesound2;
- var FLAME_STRENGTH := npccfgfile[me.npctemplate].flamestrength;
- var controlLevel := npccfgfile[me.npctemplate].tameskill;
- var caster := 0;
- var spells;
- var firebreather;
- var mypack := FindPack(me.serial);
- var orneriness := npccfgfile[me.npctemplate].orneriness;
- var masterserial := GetObjProperty(me, "master");
- var saywords := 0;
- var master;
- var masterLevel;
- var chaseloop := 0;
- var guarding :=0;
- var following := 0;
- var nextwatch := ReadGameClock();
- var happiness := CInt(GetObjProperty(me,"happiness"));
- var waittime := 120;
- var LAST_BREATH := ReadGameClock();
- if((happiness < 11) && (GetObjProperty(me,"permtame")))
- happiness := 100;
- SetObjProperty(me,"happiness",100);
- endif
- if((!happiness)||(happiness == error))
- happiness := 100;
- SetObjProperty(me,"happiness", 100);
- endif
- program TamedAI()
- Detach();
- var time := ReadGameClock();
- SetObjProperty(me,"countercheck", time);
- var parms := {};
- parms[1] := me;
- parms[2] := time;
- start_script(":taming:happyCounter", parms);
- master := SystemFindObjectBySerial(masterserial, SYSFIND_SEARCH_OFFLINE_MOBILES);
- if(!master)
- ApplyRawDamage(me, GetHP(me)+ 1);
- return;
- endif
- masterLevel := GetEffectiveSkill(master, SKILLID_TAMING);
- if(!canControl())
- //TODO: later on this will be implemented
- //return;
- endif
- me.setmaster(master);
- if(me.name["<random>"])
- SetName(me, RandomName(me));
- endif
- if(!happiness)
- happiness := 10;
- endif
- if(!orneriness)
- orneriness := 0;
- endif
- if(!me.backpack)
- var newbackpack := CreateItemAtLocation(5288, 1176, 0, 0xe75,1);
- EquipItem(me, newbackpack);
- endif
- SetAnchor(me.x, me.y, 20, 0);
- var npccfg := ReadConfigFile("npcdesc");
- if(npccfg[me.npctemplate].spell)
- caster := 1;
- spells := GetConfigStringArray(npccfg[me.npctemplate], "spell");
- endif
- if(FLAME_STRENGTH)
- firebreather := 1;
- endif
- SetWarMode(0);
- SetObjProperty(me, "serial", me.serial);
- MainAILoop();
- endprogram
- function FindPack(myserial)
- var mybank := OpenTamedStorageAreas();
- var bank_obj_name := "Bankbox " + Hex(myserial);
- var bankbox := FindRootItemInStorageArea(mybank, bank_obj_name);
- if(!bankbox)
- if((me.graphic == 0x123)||(me.graphic == 0x124))
- bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, 0x966b);
- else
- bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, UOBJ_BANKBOX);
- endif
- else
- if(((me.graphic == 0x123)||(me.graphic == 0x124))&&((me.backpack).objtype == UOBJ_BANKBOX))
- DestroyItem(bankbox);
- bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, 0x966b);
- endif
- endif
- return bankbox;
- endfunction
- function MainAILoop()
- var ev;
- nextwatch := ReadGameClock();
- var mhp;
- EnableMainEvents();
- while(GetHp(me)> 0)
- happiness := GetObjProperty(me,"happiness");
- mhp := GetHp(me);
- if(GetObjProperty(me, "onhold"))
- HoldLoop("onhold");
- elseif(GetObjProperty(me, "stabled"))
- HoldLoop("stabled");
- elseif(GetObjProperty(me, "mounted"))
- HoldLoop("mounted");
- else
- if(happiness < 10)
- release();
- endif
- ev := os::wait_for_event(waittime);
- case(ev.type)
- SYSEVENT_SPEECH: ProcessSpeech(ev);
- SYSEVENT_ENGAGED: Fight(ev.source);
- SYSEVENT_DAMAGED: if(GetHp(me)< mhp)
- if(ev.source)
- Fight(ev.source);
- endif
- if(dmgsound) PlaySoundEffect(me, dmgsound); endif
- endif
- SYSEVENT_DOUBLECLICKED: if((ev.source == master) or (ev.source.cmdlevel > 2))
- OpenMyPack();
- else
- snoop(ev.source, me);
- endif
- SYSEVENT_ITEM_GIVEN: if(ev.source == master)
- TakeItem(ev);
- endif
- EVID_ALL_ATTACK_CMD: Fight(ev.target);
- EVID_ALL_FOLLOW_CMD: following := ev.target;
- SYSEVENT_ALL_GUARD_CMD: guarding := ev.target;
- PrintTextAbove(me,"*guarding " + guarding.name + "*");
- endcase
- if(following)
- waittime := 0;
- Follow();
- elseif(guarding)
- waittime := 7;
- Guard();
- else
- waittime := 120;
- EraseObjProperty(me,"#flees");
- endif
- endif
- endwhile
- endfunction
- function HoldLoop(type)
- disablemainevents();
- EnableTameEvents();
- EnableEvents(EVID_WAKEUP);
- var ev, happiness;
- while(GetObjProperty(me, type))
- if(type == "mounted")
- happiness := GetObjProperty(me, "happiness");
- ev := os::wait_for_event(60);
- if(happiness < 10)
- release();
- endif
- else
- ev := os::wait_for_event(300);
- endif
- if(ev.type == EVID_WAKEUP)
- EraseObjProperty(me, type);
- endif
- endwhile
- EnableMainEvents();
- endfunction
- function Fight(opponent)
- var oldfollowing := following;
- var flees := 0;
- SetDexterityMod(me, 0);
- following := 0;
- if(opponent == me)
- return;
- endif
- TurnToward(opponent);
- SetOpponent(opponent);
- var ev;
- var loops := 0;
- var waittime := 0;
- while((opponent) && (!opponent.dead || !opponent.hidden || !opponent.concealed)&&(dist(me,opponent)< 15))
- if(!CloseDistance(opponent))
- loops := loops + 1;
- waittime := 0;
- else
- if(!CheckLineOfSight(me, opponent))
- loops := loops + 1;
- endif
- waittime := 1;
- endif
- ev := wait_for_event(waittime);
- case(ev.type)
- EVID_ALL_ATTACK_CMD: opponent := ev.target;
- SetOpponent(opponent);
- EVID_ALL_FOLLOW_CMD: following := ev.target;
- SYSEVENT_ALL_GUARD_CMD: guarding := ev.target;
- PrintTextAbove(me,"*guarding " + guarding.name + "*");
- SYSEVENT_SPEECH: ProcessSpeech(ev);
- SYSEVENT_ENGAGED:
- SYSEVENT_DAMAGED: if(ev.source == opponent)
- if(dmgsound) PlaySoundEffect(me, dmgsound); endif
- endif
- if(ev.source)
- if(ev.source != opponent)
- if((!CheckLineOfSight(me, opponent))||(RandomInt(8)==1))
- opponent := ev.source;
- SetOpponent(opponent);
- endif
- endif
- TurnToward(opponent);
- endif
- EVID_PEACEMADE: SetWarMode(0);
- opponent := 0;
- following := oldfollowing;
- return;
- SYSEVENT_DOUBLECLICKED: if((ev.source == master) or (ev.source.cmdlevel > 2))
- OpenMyPack();
- else
- snoop(ev.source, me);
- endif
- endcase
- if(following)
- SetWarMode(0);
- opponent := 0;
- return;
- endif
- if(firebreather and caster)
- if(LAST_BREATH <= ReadGameClock())
- if((CheckLineOfSight(me, opponent)) and (dist(me, opponent) <= 15))
- if(RandomInt(4) == 1)
- cast_meteor(opponent);
- else
- cast_offensive_spell(me,opponent);
- endif
- LAST_BREATH := Cint(ReadGameClock() + (RandomInt(4) + 4));
- endif
- endif
- elseif(caster)
- if(LAST_BREATH <= ReadGameClock())
- if((CheckLineOfSight(me, opponent)) and (dist(me, opponent) <= 15))
- cast_offensive_spell(me, opponent);
- LAST_BREATH := Cint(ReadGameClock() + (RandomInt(4) + 4));
- endif
- endif
- elseif(firebreather)
- if(LAST_BREATH <= ReadGameClock())
- if(RandomInt(4)== 1)
- cast_meteor(opponent);
- endif
- LAST_BREATH := Cint(ReadGameClock() + (RandomInt(4) + 4));
- endif
- endif
- if(loops > 30)
- flees := flees + 1;
- if(flees > 4)
- flee(opponent);
- endif
- return;
- endif
- endwhile
- SetWarMode(0);
- opponent := 0;
- following := oldfollowing;
- endfunction
- function CloseDistance(opponent)
- case (Distance(me, opponent))
- 1:
- 0: return 1;
- default: if(!RunToward(opponent))
- return 1;
- else
- return 0;
- endif
- endcase
- endfunction
- function Transfer()
- if(GetObjProperty(me, "summoned"))
- return;
- endif
- SendSysMessage(master, "Transfer " + me.name + " to whom?");
- var whom := Target(master, TGTOPT_NOCHECK_LOS);
- if(!whom)
- SendSysMessage(master, "Canceled");
- return;
- endif
- if(!canControlTarget(whom))
- SendSysMessage(master, "That has no chance of controlling this creature");
- return;
- endif
- if ((whom.cmdlevel == 0) && (GetObjProperty(me,"permtame")))
- EraseObjProperty(me,"permtame");
- SendSysMessage(master,"Remove permtamed objprop from the animal");
- endif
- if(hit)
- PlaySoundEffect(me, hit);
- endif
- SetObjProperty(me, "master", whom.serial);
- PrintTextAbove(me, me.name + " accepts " + whom.name+ " as its new master");
- RestartScript(me);
- endfunction
- function release()
- if (GetObjProperty(me,"permtame"))
- EraseObjProperty(me,"permtame");
- endif
- if((GetObjProperty(me,"onhold")) or (GetObjProperty(me,"stabled")))
- return;
- endif
- var char;
- var mounted_char;
- var onchars := EnumerateOnlineCharacters();
- if(GetObjProperty(me,"summoned") == 1)
- if(GetObjProperty(me,"mounted") == 1)
- char := GetObjProperty(me,"mounted_on");
- foreach person in onchars
- if(person.serial == CInt(char))
- mounted_char := person;
- break;
- endif
- endforeach
- dismountme(mounted_char);
- endif
- PlayStationaryEffect(me.x, me.y, me.z, FX_SMOKE, 0xa, 0xa);
- MoveCharacterToLocation(me,5288, 1176, 0,MOVECHAR_FORCELOCATION);
- ApplyRawDamage(me, GetHp(me)+ 3);
- else
- if(GetObjProperty(me,"mounted"))
- char := GetObjProperty(me,"mounted_on");
- foreach person in onchars
- if(person.serial == CInt(char))
- mounted_char := person;
- break;
- endif
- endforeach
- dismountme(mounted_char);
- endif
- me.script := npccfgfile[me.npctemplate].script;
- PrintTextAbove(me, me.name + " has decided it is better off without a master.");
- var master := SystemFindObjectBySerial(me.master, SYSFIND_SEARCH_OFFLINE_MOBILES);
- var pet_array := GetObjProperty( master, "Pets" );
- foreach pet_serial in ( pet_array )
- if ( pet_serial == me.serial )
- pet_array.erase(_pet_serial_iter);
- SetObjProperty(master, "Pets", pet_array );
- endif
- endforeach
- me.setmaster(0);
- EraseObjProperty(me, "master");
- EraseObjProperty(me, "serial");
- EraseObjProperty(me, "script");
- EraseObjProperty(me, "happiness");
- EraseObjProperty(me, "mounted");
- EraseObjProperty(me, "mounted_on");
- SetAnchor(me.x,me.y,10,1);
- SetHpRegenRate(me ,(100)* 12);
- start_script(":taming:untamedremovehouse", {me});
- RestartScript(me);
- endif
- endfunction
- function dismountme(who)
- var mount := GetEquipmentByLayer(who, 25);
- me.facing := who.facing;
- MoveCharacterToLocation(me, master.x, who.y, who.z, MOVECHAR_FORCELOCATION);
- EraseObjProperty(me, "mounted");
- EraseObjProperty(me, "mounted_on");
- DestroyItem(mount);
- endfunction
- function Fetch()
- return;
- var tobj := Target(master);
- if(tobj.container)
- if(dmgsound)
- PlaySoundEffect(me, dmgsound);
- endif
- return;
- endif
- var times := 0;
- while((Distance(me, tobj)> 1)&&(times <= 5)&& CheckLineOfSight(me,tobj))
- if(!walktoward(tobj))
- sleepms(100);
- times := times + 1;
- else
- times := 0;
- endif
- endwhile
- if(Accessible(me,tobj))
- if(hit)
- PlaySoundEffect(me, hit);
- endif
- MoveItemToContainer(tobj, mypack);
- while((Distance(me, master)> 1)&&(times <= 5)&& CheckLineOfSight(me,master))
- if(!walktoward(master))
- sleepms(100);
- times := times + 1;
- else
- times := 0;
- endif
- endwhile
- MoveItemToLocation(tobj, me.x, me.y, me.z, MOVEITEM_FORCELOCATION);
- else
- if(dmgsound) PlaySoundEffect(me, dmgsound); endif
- endif
- endfunction
- function Get()
- return;
- var tobj := Target(master);
- if(tobj.container)
- if(dmgsound) PlaySoundEffect(me, dmgsound); endif
- return;
- endif
- var times := 0;
- while((Distance(me, tobj)> 1)&&(times <= 5)&& CheckLineOfSight(me,tobj))
- if(!walktoward(tobj))
- sleepms(100);
- times := times + 1;
- else
- times := 0;
- endif
- endwhile
- if(Accessible(me,tobj))
- if(hit) PlaySoundEffect(me, hit); endif
- MoveItemToContainer(tobj, mypack);
- else
- if(dmgsound) PlaySoundEffect(me, dmgsound); endif
- endif
- endfunction
- function drop()
- foreach myitems in EnumerateItemsInContainer(mypack)
- if(myitems.container.serial == mypack.serial)
- MoveItemToLocation(myitems, me.x, me.y, me.z,0);
- sleepms(100);
- endif
- endforeach
- endfunction
- function speak()
- if(idlesnd1) PlaySoundEffect(me, idlesnd1); endif
- endfunction
- function OpenMyPack();
- if((me.graphic == 0x123)||(me.graphic == 0x124))
- if(Distance(me, master)> 2)
- return;
- endif
- foreach item in EnumerateItemsInContainer(mypack)
- if(item.container == me.backpack)
- MoveItemToContainer(item, me.backpack);
- endif
- endforeach
- SendOpenSpecialContainer(master, mypack);
- return;
- else
- if(Distance(me, master)> 1)
- return;
- endif
- var alreadymounted := GetEquipmentByLayer(master, 25);
- if(alreadymounted)
- return;
- endif
- var mounttype := 0;
- case(me.graphic)
- 0xcc: mounttype := 0x3ea2;
- 0xc8: mounttype := 0x3e9f;
- 0xe2: mounttype := 0x3ea0;
- 0xe4: mounttype := 0x3ea1;
- 0xdc: mounttype := 0x3ea6;
- 0xd2: mounttype := 0x3ea3;
- 0xda: mounttype := 0x3ea4;
- 0xdb: mounttype := 0x3ea5;
- endcase
- // No stealthing on a horse - DeiviD
- if(master.stealthsteps)
- master.hidden := 0;
- SendSysMessage( master, "You cant stealth while riding a horse!");
- endif
- if(mounttype)
- if(MoveCharacterToLocation(master,me.x,me.y,me.z,0))
- master.facing := me.facing;
- var mount := CreateItemAtLocation(5228, 1182, 0, 0xf021,1);
- mount.color := me.color;
- MoveCharacterToLocation(me, 5228, 1182, 0, MOVECHAR_FORCELOCATION);
- mount.graphic := mounttype;
- EquipItem(master,mount);
- SetObjProperty(mount,"serial", me.serial);
- SetObjProperty(me,"mounted", 1);
- SetObjProperty(me,"mounted_on", master.serial);
- mount.decayat:= 0;
- guarding := 0;
- following := 0;
- endif
- endif
- endif
- endfunction
- function TakeItem(ev)
- var npccfg := ReadConfigFile("npcdesc");
- var foodtype := npccfg[me.npctemplate].food;
- if(!foodtype)
- foodtype := "all";
- endif
- var cfg := ReadConfigFile("::food");
- var elem := FindConfigElem(cfg,foodtype);
- var foodarray := GetConfigStringArray(elem,"food");
- if(CStr(ev.item.objtype)in foodarray)
- PlaySoundEffect(me, CInt(0x3b)+ RandomInt(3));
- DestroyItem(ev.item);
- PrintTextAbovePrivate(me,"your pet looks happier.", master);
- SetObjProperty(me,"happiness", 100);
- return;
- endif
- if((me.graphic == 0x123)||(me.graphic == 0x124))
- if(!MoveItemToContainer(ev.item, mypack))
- say("*your pet cannot hold that item*");
- return;
- else
- PlaySoundEffect(me,0x49);
- endif
- else
- var yourpack := ev.source.backpack;
- MoveItemToContainer(ev.item,yourpack);
- endif
- endfunction
- function Guard()
- if(nextwatch <= ReadGameClock())
- nextwatch := ReadGameClock()+ 7;
- if(RandomInt(8)==1)
- PrintTextAbove(me,"*guarding " + guarding.name + "*");
- endif
- foreach mob in ListHostiles(guarding, 9, 0);
- Fight(mob);
- return;
- endforeach
- endif
- if((!GetStrength(guarding))||(guarding.dead)||(dist(me,guarding)> 15))
- guarding := 0;
- endif
- endfunction
- function Follow()
- var d := Distance(me, following);
- if(d <= 2)
- waittime := 1;
- elseif(d > 15)
- following := 0;
- waittime := 120;
- elseif(d > 6)
- if(GetObjProperty(me, "Pause"))
- waittime := 2;
- else
- var ma := 200 - CInt(GetDexterity(me));
- SetDexterityMod(me, CInt(GetDexterityMod(me))+ ma);
- RunToward(following);
- SetDexterityMod(me, CInt(GetDexterityMod(me))- ma);
- waittime := 0;
- endif
- else
- if(GetObjProperty(me, "Pause"))
- waittime := 2;
- else
- var ma := 200 - CInt(GetDexterity(me));
- SetDexterityMod(me, CInt(GetDexterityMod(me))+ ma);
- walktoward(following);
- SetDexterityMod(me, CInt(GetDexterityMod(me))- ma);
- waittime := 0;
- endif
- endif
- if(guarding)
- Guard();
- endif
- endfunction
- function canControl()
- if(!controlLevel)
- controlLevel := 0;
- endif
- if(masterLevel >= controlLevel)
- return 1;
- else
- return 0;
- endif
- endfunction
- function canControlTarget(person)
- var levelPerson := GetEffectiveSkill(person, SKILLID_TAMING);
- if(!controlLevel)
- controlLevel := 0;
- endif
- if(levelPerson >= controlLevel)
- return 1;
- else
- return 0;
- endif
- endfunction
- function ProcessSpeech(ev)
- if(ev.source.serial != masterserial)
- return;
- endif
- if(!master)
- RestartScript(me);
- endif
- var evtext := lower(ev.text);
- var mename := lower(me.name);
- var skillcontrol := Geteffectiveskill (master, SKILLID_ANIMALLORE);
- var conf := ReadConfigFile("::npcdesc");
- var thecreature := Target(master);
- var elem := FindConfigElem(conf, thecreature.npctemplate);
- var tameskill := CInt(GetConfigInt(elem, "tameskill"));
- if(evtext[mename + " kill"] || evtext[mename + " attack"] || evtext["all kill"] || evtext["all attack"])
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- var what := Target(master, TGTOPT_HARMFUL + TGTOPT_CHECK_LOS);
- if(what && !what.hidden)
- if(what == ev.source)
- return;
- elseif(evtext["all kill"] || evtext["all attack"])
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- if(obediencecheck()== 0)
- return;
- endif
- AllCommand(EVID_ALL_ATTACK_CMD, what);
- else
- if(obediencecheck()== 0)
- return;
- endif
- Fight(what);
- endif
- endif
- elseif(evtext[mename + " stop"] || evtext["all stop"])
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- if(obediencecheck()== 0)
- return;
- endif
- guarding := 0;
- following := 0;
- elseif((evtext[mename + " come"])||(evtext["all come"]))
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- if(obediencecheck()== 0)
- return;
- endif
- var done := 0;
- chaseloop := 0;
- while(done == 0)
- chaseloop := chaseloop +1;
- done := CloseDistance(ev.source);
- if(chaseloop > 25)
- done :=1;
- endif
- endwhile
- elseif(evtext[mename + " follow"])
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- if(obediencecheck()== 0)
- return;
- endif
- if(evtext["follow me"])
- following := ev.source;
- else
- var what := Target(master, TGTOPT_CHECK_LOS);
- if(what)
- following := what;
- endif
- endif
- elseif(evtext["all follow"])
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- if(obediencecheck()== 0)
- return;
- endif
- if(evtext["follow me"])
- following := ev.source;
- else
- var what := Target(master, TGTOPT_CHECK_LOS);
- if(what)
- AllCommand(EVID_ALL_FOLLOW_CMD, what);
- endif
- endif
- elseif(evtext[mename + " transfer"] ||(evtext["all transfer"]))
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- Transfer();
- elseif(evtext[mename + " release"] ||(evtext["all release"]))
- if(!canControl())
- SendSysMessage(master, "You have no chance of controlling this creature");
- return;
- endif
- release();
- EraseObjProperty(me,"permtame");
- elseif(evtext[mename + " guard me"])
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- guarding := ev.source;
- PrintTextAbove(me,"Im guarding you.");
- elseif(evtext[mename + " guard"])
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- say("Who should I guard?");
- var what := Target(master, TGTOPT_HELPFUL + TGTOPT_CHECK_LOS);
- if(what.isA(POLCLASS_UOBJECT))
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- guarding := what;
- PrintTextAbove(me,"Im guarding " + guarding.name);
- endif
- elseif(evtext["all guard me"])
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- guarding := ev.source;
- PrintTextAbove(me,"Im guarding you");
- elseif(evtext["all guard"])
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- say("Who should I guard?");
- var what := Target(master, TGTOPT_HELPFUL + TGTOPT_CHECK_LOS);
- if(GetHp(what))
- if((!canControl()) || (tameskill > (skillcontrol - 10)))
- SendSysMessage(master, "You have no chance of controlling this creature");
- SendSysMessage(master, "controllevel:"+controllevel);
- SendSysMessage(master, "skillcontrol:"+skillcontrol);
- SendSysMessage(master, "tameskill:"+tameskill);
- release();
- return;
- endif
- AllCommand(SYSEVENT_ALL_GUARD_CMD, what);
- endif
- elseif(evtext[mename + " fetch"])
- if(obediencecheck()== 0)
- return;
- endif
- Fetch();
- elseif(evtext[mename + " get"])
- if(obediencecheck()== 0)
- return;
- endif
- Get();
- elseif(evtext[mename + " drop"])
- if(obediencecheck()== 0)
- return;
- endif
- drop();
- elseif(evtext[mename + " speak"] ||(evtext["all speak"]))
- if(obediencecheck()== 0)
- return;
- endif
- speak();
- endif
- endfunction
- function AllCommand(evtype,what)
- var mobs := ListMobilesNearLocation(master.x, master.y, master.z, 9);
- var eve := array;
- eve.+type := evtype;
- eve.+source := me;
- eve.+target := what;
- SendEvent(me, eve);
- foreach mob in mobs
- if(GetObjProperty(mob, "master")== me.master.serial)
- SendEvent(mob, eve);
- endif
- endforeach
- endfunction
- function cast_meteor(opponent)
- var base := Cint(((FLAME_STRENGTH * GetHp(me)) / GetMaxHp(me)) / 2);
- var dmg := RandomInt(base) + base;
- PerformAction(me,0x0c);
- PlaysoundEffect(me, 0x16b);
- sleep(3);
- PlayMovingEffect(me, opponent, 0x36d4, 10, 1, 1);
- ApplyRawDamage(opponent, dmg);
- endfunction
- function flee(opponent)
- var numflees := GetObjProperty(me,"#flees");
- if(numflees)
- if(numflees > 5)
- MoveCharacterToLocation(me,5288,1176,0,MOVECHAR_FORCELOCATION);
- SetObjProperty(me,"guardkill",1);
- ApplyRawDamage(me, GetMaxHp(me)+ 3);
- else
- numflees := numflees + 1;
- endif
- else
- numflees := 1;
- endif
- SetObjProperty(me,"#flees",numflees);
- var runs := 0;
- while((Distance(me, opponent)< 20)&&(runs < 50))
- RunAwayFrom(opponent);
- runs := runs +1;
- wait_for_event(0);
- endwhile
- RestartScript(me);
- endfunction
- function obediencecheck()
- var arry := { 0xcc, 0xc8, 0xe2, 0xe4, 0x123, 0x124, 0xd2, 0xdb };
- if(me.objtype in arry)
- return 1;
- endif
- happiness := GetObjProperty(me, "happiness");
- var defiance :=(orneriness * 20)-30;
- if(defiance < 1)
- defiance := 1;
- endif
- defiance := defiance + petcount();
- var finaldefiance := CInt(defiance + RandomInt(40));
- if(GetObjProperty(me, "summoned")== 1)
- return 1;
- elseif(finaldefiance > happiness)
- if(dmgsound) PlaySoundEffect(me, dmgsound); endif
- happiness := happiness - orneriness;
- SetObjProperty(me, "happiness",(happiness-1));
- if(happiness < 10)
- release();
- endif
- return 0;
- else
- if(hit) PlaySoundEffect(me, hit); endif
- if(happiness < 10)
- release();
- return 0;
- endif
- return 1;
- endif
- endfunction
- function petcount()
- var pets := 0;
- var mobs := ListMobilesNearLocation(me.x,me.y,me.z,8);
- foreach mob in mobs
- if((mob.script == "tamed")&&(GetObjProperty(mob,"master")==masterserial))
- if(GetObjProperty(mob, "summoned"))
- pets := pets + 0;
- else
- pets := pets+5;
- endif
- endif
- endforeach
- return pets;
- endfunction
- function EnableTameEvents()
- EnableEvents(EVID_WAKEUP);
- endfunction
- //function EnableMainEvents()
- // EnableEvents(SYSEVENT_SPEECH);
- // EnableEvents(SYSEVENT_ENGAGED);
- // EnableEvents(SYSEVENT_DAMAGED);
- // EnableEvents(SYSEVENT_DOUBLECLICKED);
- // EnableEvents(SYSEVENT_ITEM_GIVEN);
- // EnableEvents(EVID_PEACEMADE);
- //endfunction
- function EnableMainEvents()
- //RegisterForSpeechEvents(me, 15);
- EnableEvents(SYSEVENT_SPEECH, 15);
- EnableEvents(SYSEVENT_ENGAGED);
- EnableEvents(SYSEVENT_DAMAGED);
- EnableEvents(SYSEVENT_DOUBLECLICKED);
- EnableEvents(SYSEVENT_ITEM_GIVEN);
- EnableEvents(EVID_PEACEMADE);
- endfunction
- function disablemainevents()
- DisableEvents(SYSEVENT_SPEECH);
- DisableEvents(SYSEVENT_ENGAGED);
- DisableEvents(SYSEVENT_DAMAGED);
- DisableEvents(SYSEVENT_ITEM_GIVEN);
- DisableEvents(EVID_PEACEMADE);
- endfunction
Add Comment
Please, Sign In to add comment