Page 1 of 1

[WIP] Radar Mod

Posted: Mon Feb 18, 2013 2:23 pm
by kalapixie
Hey, guys!

So, I was playing Factorio, and noticed aliens weren't attacking much, at all. So I checked the freeplay script....and I couldn't find anything wrong with it. After some dabbling, I found out that on that specific save, the alien wave countdown timer was...counting up. Alas, I didn't keep the save and I can't reproduce the bug. But since I was in the script anyways, I decided to mod the game to make alien waves a lot harder, and to give user to the Radar in freeplay mode.

Changes/Features:
Makes creepers spawn in much higher frequencies faster, and adds a little more variability and randomness to how much they spawn, and how often.
Makes radars tell you when the next wave is incoming, and occasionally how many enemies are incoming. The more radars you have, the more you'll get the information you need.

Code: Select all

require "util"
require "story"
require "defines"

game.oninit = function()
glob.player = game.getplayer()
gt = game.gettext

end

game.onevent = function(event)
  if event.name == "ontick" then
	
    if glob.introduction == nil then
      glob.introduction = true
      game.getplayer().insert{name="iron-plate", count=8}
      game.getplayer().insert{name="pistol", count=1}
      game.getplayer().insert{name="basic-bullet-magazine", count=10}
	  
    end
    if game.getplayer().getshiplandinginprogress() then
      local timeleft = game.getplayer().gettimetoland()
      if timeleft == 0 then
        game.setgamestate{gamefinished=true, playerwon=true}
      end
      if glob.untilnextattack == nil then
        glob.untilnextattack = 1
      end
      local secondsleft = math.floor(timeleft / 60)
      local minutes = math.floor((secondsleft)/60)
      local seconds = math.floor(secondsleft - 60*minutes)
      game.getplayer().setgoaldescription("Time until the fleet lands: " .. string.format("%d:%02d", minutes, seconds), true)
      glob.untilnextattack = glob.untilnextattack - 1
      if glob.untilnextattack == 0 then
        game.setmulticommand({type=defines.command.attack,
                             target=game.getplayer(),
                             distraction=defines.distraction.byenemy},
                             10)
        glob.untilnextattack = 60 * 10
      end
    end
    if glob.untilnextattacknormal == nil then
	
	  
	 
      glob.untilnextattacknormal = 60 * 60 * 4 + (game.getrandomnumber() * 2)
      glob.attackcount = 1
    end
    glob.untilnextattacknormal = glob.untilnextattacknormal - 1
    if glob.untilnextattacknormal <= 0 then
      glob.untilnextattacknormal = 60 * 60 * 3 + game.getrandomnumber() * 60 * 60 * 9
	  
      game.setmulticommand({type=defines.command.attack,
                             target=game.getplayer(),
                             distraction=defines.distraction.byenemy},
                             glob.attackcount)
      glob.attackcount = glob.attackcount + 1 + (game.getrandomnumber() * 3)
    end
	  
	  
	  
	  
	  
	  
  end
  if event.name == "onsectorscanned" then
		local secondsleft = math.floor(glob.untilnextattacknormal/ 60)
      local minutes = math.floor((secondsleft)/60)
      local seconds = math.floor(secondsleft - 60*minutes)
  glob.player.print("Estimated time until next attack: " .. string.format("%d:%02d", minutes, seconds))
  randomizer = game.getrandomnumber()
  
  if(randomizer >= .75) then
  report = math.floor(glob.attackcount + (3 * game.getrandomnumber()) - (3 * game.getrandomnumber()))
  glob.player.print("Reports are coming in that the enemy forces will number around: " .. report)
  end
  end
end
http://pastebin.com/kZW1Qv5W

All you have to do is find your rawbots install directory, go into data/lualib, make a copy of your freeplay.lua, and then copy/paste inside the current one with that.

- Mel

Re: Radar Mod

Posted: Mon Feb 18, 2013 2:32 pm
by kovarex
Congratulations on making the first mod :)

Re: Radar Mod

Posted: Mon Feb 18, 2013 2:58 pm
by rk84
Nice mod.
kalapixie wrote:Hey, guys!
So, I was playing Factorio, and noticed aliens weren't attacking much, at all. So I checked the freeplay script....and I couldn't find anything wrong with it. After some dabbling, I found out that on that specific save, the alien wave countdown timer was...counting up. Alas, I didn't keep the save and I can't reproduce the bug...
I think same happen once to me too. Only one attacking wave and then no attacks. I think I have the save, but it is in different computer. Also it was in 0.2.6

Re: Radar Mod

Posted: Tue Feb 19, 2013 10:43 am
by slpwnd
That was fast. The mods are already coming :)

I like the usage of the Radar. Pretty original. We thought of having it actually help you to discover the map somehow later on. But this is simple and already useful.

Re: Radar Mod

Posted: Tue Feb 19, 2013 9:42 pm
by rk84
I edited the report part little bit. I made error marginal 10% instead static 3.

Code: Select all

report = math.floor( glob.attackcount + glob.attackcount * (game.getrandomnumber() - game.getrandomnumber()) / 10 )

Re: Radar Mod

Posted: Wed Feb 20, 2013 2:02 am
by Shocker
Good idea, simple yet useful, can't go wrong there. Thanks for the mod!