View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:16 am



Reply to topic  [ 8 posts ] 
 Mining AI 
Author Message
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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


Sun Oct 18, 2009 12:31 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Sun Oct 18, 2009 1:51 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Mining AI
next build should bring lua on guns at least.


Sun Oct 18, 2009 5:48 am
Profile WWW

Joined: Sat Oct 17, 2009 10:18 am
Posts: 10
Location: Right behind you...
Reply with quote
Post Re: Mining AI
Let us see if this code really works.


Fri Nov 27, 2009 11:14 am
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Mining AI
It does - it just lags a bit and has some wierdness occasionally.


Fri Nov 27, 2009 12:36 pm
Profile WWW
Loose Canon
User avatar

Joined: Sun Mar 29, 2009 11:07 pm
Posts: 2992
Location: --------------->
Reply with quote
Post 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?


Fri Nov 27, 2009 3:54 pm
Profile WWW
User avatar

Joined: Tue Aug 11, 2009 2:42 am
Posts: 321
Location: On an iceberg typing away...
Reply with quote
Post Re: Mining AI
umm sorry but how do I script actors?


Mon Dec 07, 2009 1:34 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Mon Dec 07, 2009 1:39 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.044s | 13 Queries | GZIP : Off ]