Data Realms Fan Forums
http://45.55.195.193/

Mining AI
http://45.55.195.193/viewtopic.php?f=73&t=16867
Page 1 of 1

Author:  Kyred [ Sun Oct 18, 2009 12:31 am ]
Post subject:  Mining AI

We all know that the Gold Digging command doesn't work. I dunno if anyone has done this yet or not with Lua, but I created an Actor that will search for and mine for gold on its own, using goto waypoints. Here's some gifs of it:

Image

Be sure to watch the yellow waypoint marker on this one. Keep in mind, I'm actually in control of the brain robot, not the dummy that's digging.

Image

Here's the code I used (can cause some lag):

Code:
function Create(self)
   self.bSearch = false; --Is the AI searching for a gold spot?
   self.bLookForGold = false; --Should the AI look for a gold spot?
   
   --self.crouchTimer starts at nil, and becomes a timer when Down is held.
   --Once the timer passes self.holdTime, then the timer becomes false.
   --When Down is released, the timer goes back to nil.
   self.crouchTimer = nil;
   self.holdTime = 1500;
   
   self.searchWidth = 250;
   self.searchHeight = 250;
   self.deltay = 0;
   self.searchAcc = 2;
   
   self.LockPos = nil;
end

function Update(self)
   local controller = self:GetController();
   if controller:IsPlayerControlled(-1) then
      if controller:IsState(Controller.BODY_CROUCH) then
         if self.crouchTimer == nil then
            self.crouchTimer = Timer();
         elseif self.crouchTimer ~= false then
            if self.crouchTimer:IsPastSimMS(self.holdTime) then
                self.bLookForGold = not self.bLookForGold;
                self.bSearch = self.bLookForGold;
                self.deltay = 0;
                self.LockPos = nil;
                self.crouchTimer = false; --Taking advantage of dynamic type >:)
                self:FlashWhite(100);
            end
         end
      elseif self.crouchTimer ~= nil then
         self.crouchTimer = nil;
      end
   else --AI is running the show.
      if self.bLookForGold then
          if self:GetLastAIWaypoint() == self.Pos then
             self.bSearch = true;
          end
          if self.bSearch then
             if self.LockPos == nil then
                self.LockPos = self.Pos;
             end
             local div = self.searchWidth/2;
             if self.deltay <= self.searchHeight then
                for i = -div, div, self.searchAcc do
                    local poi = self.LockPos + Vector(i,self.deltay);
                    print(SceneMan:GetTerrMatter(poi.X,poi.Y));
                    if SceneMan:GetTerrMatter(poi.X,poi.Y) == 2 then --GOLD!
                       print(poi);
                       self.AIMode = Actor.AIMODE_GOTO;
                       self:AddAISceneWaypoint(poi);
                       self:DrawWaypoints(true);
                       self.bSearch = false;
                       break;
                    end
                end
                self.deltay = self.deltay + 1;
             else
                self.bSearch = false;
             end
          end
      end
   end
end

Author:  CaveCricket48 [ Sun Oct 18, 2009 1:51 am ]
Post subject:  Re: Mining AI

Cool. Honestly, though, if there isn't a secondary fire key the next build, I hope gold dig woud still be broken. One of my mods rely upon it's non-functionality for an alt-fire key.

Author:  Geti [ Sun Oct 18, 2009 5:48 am ]
Post subject:  Re: Mining AI

next build should bring lua on guns at least.

Author:  oliver255 [ Fri Nov 27, 2009 11:14 am ]
Post subject:  Re: Mining AI

Let us see if this code really works.

Author:  411570N3 [ Fri Nov 27, 2009 12:36 pm ]
Post subject:  Re: Mining AI

It does - it just lags a bit and has some wierdness occasionally.

Author:  TorrentHKU [ Fri Nov 27, 2009 3:54 pm ]
Post subject:  Re: Mining AI

oliver255 wrote:
Let us see if this code really works.

He posted two gifs of it working. Why do you need to confirm this yourself?

Author:  hax [ Mon Dec 07, 2009 1:34 am ]
Post subject:  Re: Mining AI

umm sorry but how do I script actors?

Author:  CaveCricket48 [ Mon Dec 07, 2009 1:39 am ]
Post subject:  Re: Mining AI

You script anything by making the Lua file and the putting "ScriptPath = mod.rte/script.lua" into the object's code that is going to be scripted.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/