daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Fight(opponent)
  2.   if((opponent.cmdlevel > 0) || (opponent.serial == me.serial))
  3.     SetWarMode(0);
  4.     opponent := 0;
  5.     return;
  6.   endif
  7.  
  8.   //Knightrage) If i've been peacemade, stop fighting.
  9.   if (GetObjProperty(me,"#peacemade")) SetWarMode(0); opponent := 0; return; endif
  10.   //Knightrage) If I am fighting myself, stop.
  11.   if (opponent == me) return; endif
  12.  
  13.   var oldprio := set_priority(50);
  14.   SetOpponent(opponent);
  15.   prepare_for_fight(opponent);
  16.   TurnToward(opponent);
  17.   var loops := 0;
  18.   var ev;
  19.   var waittime := 0;
  20.   var losfails := 0;
  21.   while((opponent) && (!opponent.dead) && (!opponent.hidden) && (!opponent.concealed) && (dist(me,opponent) < 20))
  22.     if(!CloseDistance(opponent))
  23.       loops := loops + 1;
  24.       waittime := 0;
  25.     else
  26.       loops := 0;
  27.       waittime := 1;
  28.     endif
  29.  
  30.         // LOS check, if failed > 100 times, abort opponent
  31.     if(!CheckLosAt(me, opponent.x, opponent.y, opponent.z))
  32.       losfails := losfails + 1;
  33.     else
  34.       losfails := 0;
  35.     endif
  36.     if(losfails >= 100)
  37.       SetOpponent(0);
  38.           DisableCombatEvents();
  39.           EnableMainEvents();
  40.           return;
  41.     endif
  42.    
  43.     ev := wait_for_event(waittime);
  44.     process_combat_event(opponent);
  45.     if(ev.type != SYSEVENT_SPEECH)
  46.       case (ev.type)
  47.         SYSEVENT_DAMAGED: if((ev.source.npctemplate) and (CheckLineOfSight(me, ev.source)))
  48.                             opponent := ev.source;
  49.                             SetOpponent(opponent);
  50.                             TurnToward(opponent);
  51.                           elseif((dist(me, ev.source) < dist(me, opponent)) || (!CheckLineOfSight(me, opponent)) || (!opponent))
  52.                             opponent := ev.source;
  53.                             SetOpponent(opponent);
  54.                             TurnToward(opponent);
  55.                           elseif(RandomInt(3)==1)
  56.                             opponent := ev.source;
  57.                             SetOpponent(opponent);
  58.                             TurnToward(opponent);
  59.                           endif
  60.         SYSEVENT_ENGAGED: if(ev.source)
  61.                             if(RandomInt(6) == 1)
  62.                               opponent := ev.source;
  63.                               SetOpponent(opponent);
  64.                               TurnToward(opponent);
  65.                             endif
  66.                           endif
  67.         EVID_PEACEMADE:   SetWarMode(0);
  68.                           SetOpponent(0);
  69.                           sleep(1);
  70.                           DisableCombatEvents();
  71.                           EnableMainEvents();
  72.                           return;
  73.         EVID_HERDING:     Herding(ev);
  74.       endcase
  75.     endif
  76.   endwhile
  77.   post_combat();
  78. endfunction
  79.  
  80. function EnableCombatEvents()
  81.   EnableEvents(SYSEVENT_ENGAGED + SYSEVENT_DAMAGED + EVID_PEACEMADE);
  82.   DisableEvents(SYSEVENT_SPEECH);
  83. endfunction
  84.  
  85. function DisableCombatEvents()
  86.   DisableEvents(SYSEVENT_ENGAGED + SYSEVENT_DAMAGED + EVID_PEACEMADE);
  87. endfunction
  88.  
  89. function flee(opponent)
  90.   if((me.script == "immobile") || (me.script == "immobilespell"))
  91.     sleep(2);
  92.     return;
  93.   else
  94.     var numflees := GetObjProperty(me,"#flees");
  95.     if(numflees > 10)
  96.       RestartScript(me);
  97.     else
  98.       numflees := numflees + 1;
  99.     endif
  100.     SetObjProperty(me,"#flees", numflees);
  101.     var runs := 0;
  102.     var chk := 0;
  103.     var ev;
  104.     while((Distance(me, opponent) < 15) && (runs < 50) && (CheckLineOfSight(me, opponent)))
  105.       ev := wait_for_event(1);
  106.       chk := process_flee_event(opponent);
  107.       WalkAwayFrom(opponent);
  108.       runs := runs +1;
  109.       case (ev.type)
  110.         SYSEVENT_DAMAGED: if(((ev.source.npctemplate) and (CheckLineOfSight(me, ev.source))) ||(dist(me, ev.source) < dist(me, opponent)) || (!CheckLineOfSight(me, opponent)) || (!opponent) || (RandomInt(3)==1))
  111.                             opponent := ev.source;
  112.                             SetOpponent(opponent);
  113.                           endif
  114.         EVID_PEACEMADE:   chk := 1;
  115.         EVID_HERDING:     Herding(ev);
  116.       endcase
  117.       if(chk)
  118.         break;
  119.       endif
  120.     endwhile
  121.   endif
  122. endfunction
RAW Paste Data
Top