Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Proste AI
#1
Proste AI oparte na module przygotowanym przez Sativa. 

Click :Link<--- Wersja Modułu.

Jest to bardzo proste AI mające w założeniu, że jeżeli mob jest na daną odległość od gracza to go atakuje. A jeżeli jest troche dalej to do niego podbiega. Trzeba tu trzoche ulepszyć zwłaszcze, że nie testowałem tego w warunkach bojowych. 

Co trzeba zrobić aby wszystko działalo. Po prostu wgrać to i  w pliku G2O_Cbot. Zamienić 90 linijkę na tą onDie = function(killerID){ai_makehimDie(m_Id, killerID)};

Code:
///////////////////////
 // CC(2017-2016) //
///////////////////////

local ALL_Bots = 0;
local BOTS_MOBS = {};

local AI_Stats = [
{id = "WOLF", instance = "WOLF", str = 10, hp = 70, dex = 0, exp = 50, mindist = 230, timetorespawn = 5},
{id = "YWOLF", instance = "WOLF", str = 20, hp = 50, dex = 0, exp = 20, mindist = 230, timetorespawn = 5},
{id = "SCAN", instance = "SCAVENGER", str = 60, hp = 60, dex = 0, exp = 60, mindist = 230, timetorespawn = 50},
{id = "YSCAN", instance = "SCAVENGER", str = 30, hp = 40, dex = 0, exp = 30, mindist = 230, timetorespawn = 50}
];



class AI
{
   constructor(name, posx, posy, posz, instance)
    {
    operation_bot = createBot(name);
   focus_id = -1;
   action_id = 0;
    def_posx = posx;
   def_posy = posy;
   def_posz = posz;
   def_instance = instance;
    operation_bot.setSpawnPosition(posx, posy, posz);
    operation_bot.setPosition(posx, posy, posz);

        for(local i = 0; i < AI_Stats.len(); ++i)
        {
            if(AI_Stats[i].id == instance)
            {
            operation_bot.setStrength(AI_Stats[i].str)
            operation_bot.setInstance(AI_Stats[i].instance);
            operation_bot.setDexterity(AI_Stats[i].dex)
            operation_bot.setHealth(AI_Stats[i].hp);
            min_dist = AI_Stats[i].mindist;
            def_exp = AI_Stats[i].exp;
            time_respawn = AI_Stats[i].timetorespawn;
            }
        }
    }

   function action_mob()
   {
       switch(action_id) {    
       case 0: action_search(); break;
       case 1: action_run(); break;
       case 2: action_atack(); break;
       case 3: action_respawn(); break; }
   }        
    
    function action_search()
    {
        for(local i = 0; i < getMaxSlots(); ++i){
            if(isPlayerConnected(i) == true){
                local playerPos = getPlayerPosition(i);
               local distance = getDistance3D(operation_bot.m_PosX, operation_bot.m_PosY, operation_bot.m_PosZ, playerPos.x, playerPos.y, playerPos.z);
                if(distance < 1000)
                {
                action_id = 1;
                focus_id = i;
                operation_bot.setAngleToPos(playerPos.x, playerPos.z)
                operation_bot.playAnimation("S_FISTRUNL");
                }
            }
        }    
    }
    
    function action_run()
    {
        if(isPlayerConnected(focus_id) == true){
            local playerPos = getPlayerPosition(focus_id);
           local distance = getDistance3D(operation_bot.m_PosX, operation_bot.m_PosY, operation_bot.m_PosZ, playerPos.x, playerPos.y, playerPos.z);
            if(distance < 1000)
            {
                if(distance > min_dist)
                {
                operation_bot.setAngleToPos(playerPos.x, playerPos.z)
                operation_bot.playAnimation("S_FISTRUNL");
                }else{
                action_id =2;                
                operation_bot.hitPlayer(focus_id); operation_bot.playAnimation("S_FISTATTACK");
                }    
           }else{focus_id = -1;operation_bot.stopAnimation(); action_id =0;}            
       }else{focus_id = -1;operation_bot.stopAnimation(); action_id =0;}
    }
    
    function action_atack()
    {
        if(isPlayerConnected(focus_id) == true){
            
            local playerPos = getPlayerPosition(focus_id);
           local distance = getDistance3D(operation_bot.m_PosX, operation_bot.m_PosY, operation_bot.m_PosZ, playerPos.x, playerPos.y, playerPos.z);
            if(distance < min_dist + 1)
            {
                def_warn += 1;
                operation_bot.setAngleToPos(playerPos.x, playerPos.z)  
                local rand = irand(2)+1;
                if(def_warn == 3){
                    def_warn = 0;
                     switch(rand)
                    {
                    case 1:
                    operation_bot.hitPlayer(focus_id); operation_bot.playAnimation("S_FISTATTACK"); break;
                    case 3:
                     operation_bot.hitPlayer(focus_id); operation_bot.playAnimation("S_FISTATTACK"); break;
                    case 2:
                     operation_bot.playAnimation("T_FISTPARADEJUMPB"); break;
                    }
                }
           }else{operation_bot.stopAnimation(); action_id =1;def_warn = 0;}            
       }else{focus_id = -1;operation_bot.stopAnimation(); action_id =0;def_warn=0;}    
    };
    
    function action_respawn()
    {
   def_warn += 1;
    if(def_warn == time_respawn*2)
        {
        def_warn = 0;
        action_id = 0;
        operation_bot.setPosition(def_posx, def_posy, def_posz);
        operation_bot.setHealth(operation_bot.m_HealthMax);
        operation_bot.stopAnimation();
        }
    };

    
   function irand(max) {
   // Generate a pseudo-random integer between 0 and max
   local roll = (1.0 * rand() / RAND_MAX) * (max + 1);
   return roll.tointeger();
   }

    function onDie(killerID)
    {
    operation_bot.playAnimation("T_DEAD");
    focus_id = -1;
   action_id = 3;
    def_warn = 0;
    callClientFunc(killerID, RELIABLE, "addEXP", def_exp);
    }

operation_bot = null;
focus_id = -1;
action_id = 0;
def_warn = 0;
def_posx = -1;
def_posy = -1;
def_posz = -1;
min_dist = -1;
def_exp = -1;
def_instance = "NULL";
time_respawn = 0;
};

function addMonster(name, posx, posy, posz, instance)
{
BOTS_MOBS[ALL_Bots] <- AI(name, posx, posy, posz, instance);
ALL_Bots = ALL_Bots + 1;
};

function ai_makehimDie(id, killerID)
{
BOTS_MOBS[id].onDie(killerID);
};

addEvent("onInit", function()
{
   addMonster("Wilk", 11000, 0 ,0, "WOLF");
    addMonster("Wilku", 0, 0, 0, "YWOLF");
    //Update bots
    setTimer(function()
    {
        for(local i = 0; i < ALL_Bots; ++i)
        {
                BOTS_MOBS[i].action_mob();
        }
    }, 500, true);
});
[Image: Quarchodr_sheqnnr.png]
Reply
#2
Twoje zrozumienie obiektowości mnie powaliło.
Reply
#3
I chuj i cześć.
[Image: Quarchodr_sheqnnr.png]
Reply
#4
Pozamiatał.

28379221 moje gg czekam na Ceibie Quarchodronie <3
Reply
#5
O w kurwę jegoż mać!
Wilk Morski Klanu Espadre
Reply
#6
Fajny skrypt oraz moduł, szkoda że nikt nie przepisze wszystko na najnowszą wersję.
Reply
#7
Niedługo boty doda Bimbol w aktualizacji G2O. Wtedy można pomyśleć o napisaniu nowego AI.
[Image: Quarchodr_sheqnnr.png]
Reply
#8
does it work with the new version of GO?
Reply
#9
nope.
[Image: Quarchodr_sheqnnr.png]
Reply
#10
Sad
damn...
Thanks for the replySmile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)