N1E7R4V

mobs

Dec 29th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.85 KB | None | 0 0
  1. ///////////////////////
  2.  // CC(2017-2016) //
  3. ///////////////////////
  4.  
  5. local ALL_Bots = 0;
  6. local BOTS_MOBS = {};
  7.  
  8. local AI_Stats = [
  9. {id = "WOLF", instance = "WOLF", str = 10, hp = 70, dex = 0, exp = 50, mindist = 230, timetorespawn = 5},
  10. {id = "YWOLF", instance = "WOLF", str = 20, hp = 50, dex = 0, exp = 20, mindist = 230, timetorespawn = 5},
  11. {id = "SCAN", instance = "SCAVENGER", str = 60, hp = 60, dex = 0, exp = 60, mindist = 230, timetorespawn = 50},
  12. {id = "YSCAN", instance = "SCAVENGER", str = 30, hp = 40, dex = 0, exp = 30, mindist = 230, timetorespawn = 50}
  13. ];
  14.  
  15.  
  16.  
  17. class AI
  18. {
  19.    constructor(name, posx, posy, posz, instance)
  20.     {
  21.     operation_bot = createBot(name);
  22.    focus_id = -1;
  23.    action_id = 0;
  24.     def_posx = posx;
  25.    def_posy = posy;
  26.    def_posz = posz;
  27.    def_instance = instance;
  28.     operation_bot.setSpawnPosition(posx, posy, posz);
  29.     operation_bot.setPosition(posx, posy, posz);
  30.  
  31.         for(local i = 0; i < AI_Stats.len(); ++i)
  32.         {
  33.             if(AI_Stats[i].id == instance)
  34.             {
  35.             operation_bot.setStrength(AI_Stats[i].str)
  36.             operation_bot.setInstance(AI_Stats[i].instance);
  37.             operation_bot.setDexterity(AI_Stats[i].dex)
  38.             operation_bot.setHealth(AI_Stats[i].hp);
  39.             min_dist = AI_Stats[i].mindist;
  40.             def_exp = AI_Stats[i].exp;
  41.             time_respawn = AI_Stats[i].timetorespawn;
  42.             }
  43.         }
  44.     }
  45.  
  46.    function action_mob()
  47.    {
  48.        switch(action_id) {    
  49.        case 0: action_search(); break;
  50.        case 1: action_run(); break;
  51.        case 2: action_atack(); break;
  52.        case 3: action_respawn(); break; }
  53.    }        
  54.    
  55.     function action_search()
  56.     {
  57.         for(local i = 0; i < getMaxSlots(); ++i){
  58.             if(isPlayerConnected(i) == true){
  59.                 local playerPos = getPlayerPosition(i);
  60.                local distance = getDistance3D(operation_bot.m_PosX, operation_bot.m_PosY, operation_bot.m_PosZ, playerPos.x, playerPos.y, playerPos.z);
  61.                 if(distance < 1000)
  62.                 {
  63.                 action_id = 1;
  64.                 focus_id = i;
  65.                 operation_bot.setAngleToPos(playerPos.x, playerPos.z)
  66.                 operation_bot.playAnimation("S_FISTRUNL");
  67.                 }
  68.             }
  69.         }    
  70.     }
  71.    
  72.     function action_run()
  73.     {
  74.         if(isPlayerConnected(focus_id) == true){
  75.             local playerPos = getPlayerPosition(focus_id);
  76.            local distance = getDistance3D(operation_bot.m_PosX, operation_bot.m_PosY, operation_bot.m_PosZ, playerPos.x, playerPos.y, playerPos.z);
  77.             if(distance < 1000)
  78.             {
  79.                 if(distance > min_dist)
  80.                 {
  81.                 operation_bot.setAngleToPos(playerPos.x, playerPos.z)
  82.                 operation_bot.playAnimation("S_FISTRUNL");
  83.                 }else{
  84.                 action_id =2;                
  85.                 operation_bot.hitPlayer(focus_id); operation_bot.playAnimation("S_FISTATTACK");
  86.                 }    
  87.            }else{focus_id = -1;operation_bot.stopAnimation(); action_id =0;}            
  88.        }else{focus_id = -1;operation_bot.stopAnimation(); action_id =0;}
  89.     }
  90.    
  91.     function action_atack()
  92.     {
  93.         if(isPlayerConnected(focus_id) == true){
  94.            
  95.             local playerPos = getPlayerPosition(focus_id);
  96.            local distance = getDistance3D(operation_bot.m_PosX, operation_bot.m_PosY, operation_bot.m_PosZ, playerPos.x, playerPos.y, playerPos.z);
  97.             if(distance < min_dist + 1)
  98.             {
  99.                 def_warn += 1;
  100.                 operation_bot.setAngleToPos(playerPos.x, playerPos.z)  
  101.                 local rand = irand(2)+1;
  102.                 if(def_warn == 3){
  103.                     def_warn = 0;
  104.                      switch(rand)
  105.                     {
  106.                     case 1:
  107.                     operation_bot.hitPlayer(focus_id); operation_bot.playAnimation("S_FISTATTACK"); break;
  108.                     case 3:
  109.                      operation_bot.hitPlayer(focus_id); operation_bot.playAnimation("S_FISTATTACK"); break;
  110.                     case 2:
  111.                      operation_bot.playAnimation("T_FISTPARADEJUMPB"); break;
  112.                     }
  113.                 }
  114.            }else{operation_bot.stopAnimation(); action_id =1;def_warn = 0;}            
  115.        }else{focus_id = -1;operation_bot.stopAnimation(); action_id =0;def_warn=0;}    
  116.     };
  117.    
  118.     function action_respawn()
  119.     {
  120.    def_warn += 1;
  121.     if(def_warn == time_respawn*2)
  122.         {
  123.         def_warn = 0;
  124.         action_id = 0;
  125.         operation_bot.setPosition(def_posx, def_posy, def_posz);
  126.         operation_bot.setHealth(operation_bot.m_HealthMax);
  127.         operation_bot.stopAnimation();
  128.         }
  129.     };
  130.  
  131.    
  132.    function irand(max) {
  133.    // Generate a pseudo-random integer between 0 and max
  134.    local roll = (1.0 * rand() / RAND_MAX) * (max + 1);
  135.    return roll.tointeger();
  136.    }
  137.  
  138.     function onDie(killerID)
  139.     {
  140.     operation_bot.playAnimation("T_DEAD");
  141.     focus_id = -1;
  142.    action_id = 3;
  143.     def_warn = 0;
  144.     callClientFunc(killerID, RELIABLE, "addEXP", def_exp);
  145.     }
  146.  
  147. operation_bot = null;
  148. focus_id = -1;
  149. action_id = 0;
  150. def_warn = 0;
  151. def_posx = -1;
  152. def_posy = -1;
  153. def_posz = -1;
  154. min_dist = -1;
  155. def_exp = -1;
  156. def_instance = "NULL";
  157. time_respawn = 0;
  158. };
  159.  
  160. function addMonster(name, posx, posy, posz, instance)
  161. {
  162. BOTS_MOBS[ALL_Bots] <- AI(name, posx, posy, posz, instance);
  163. ALL_Bots = ALL_Bots + 1;
  164. };
  165.  
  166. function ai_makehimDie(id, killerID)
  167. {
  168. BOTS_MOBS[id].onDie(killerID);
  169. };
  170.  
  171. addEvent("onInit", function()
  172. {
  173.    addMonster("Wilk", 11000, 0 ,0, "WOLF");
  174.     addMonster("Wilku", 0, 0, 0, "YWOLF");
  175.     //Update bots
  176.     setTimer(function()
  177.     {
  178.         for(local i = 0; i < ALL_Bots; ++i)
  179.         {
  180.                 BOTS_MOBS[i].action_mob();
  181.         }
  182.     }, 500, true);
  183. });
Add Comment
Please, Sign In to add comment