Guest User

freeplay.lua

a guest
Feb 18th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. require "util"
  2. require "story"
  3. require "defines"
  4.  
  5. game.oninit = function()
  6. glob.player = game.getplayer()
  7. gt = game.gettext
  8.  
  9. end
  10.  
  11. game.onevent = function(event)
  12.   if event.name == "ontick" then
  13.    
  14.     if glob.introduction == nil then
  15.       glob.introduction = true
  16.       game.getplayer().insert{name="iron-plate", count=8}
  17.       game.getplayer().insert{name="pistol", count=1}
  18.       game.getplayer().insert{name="basic-bullet-magazine", count=10}
  19.      
  20.     end
  21.     if game.getplayer().getshiplandinginprogress() then
  22.       local timeleft = game.getplayer().gettimetoland()
  23.       if timeleft == 0 then
  24.         game.setgamestate{gamefinished=true, playerwon=true}
  25.       end
  26.       if glob.untilnextattack == nil then
  27.         glob.untilnextattack = 1
  28.       end
  29.       local secondsleft = math.floor(timeleft / 60)
  30.       local minutes = math.floor((secondsleft)/60)
  31.       local seconds = math.floor(secondsleft - 60*minutes)
  32.       game.getplayer().setgoaldescription("Time until the fleet lands: " .. string.format("%d:%02d", minutes, seconds), true)
  33.       glob.untilnextattack = glob.untilnextattack - 1
  34.       if glob.untilnextattack == 0 then
  35.         game.setmulticommand({type=defines.command.attack,
  36.                              target=game.getplayer(),
  37.                              distraction=defines.distraction.byenemy},
  38.                              10)
  39.         glob.untilnextattack = 60 * 10
  40.       end
  41.     end
  42.     if glob.untilnextattacknormal == nil then
  43.    
  44.      
  45.      
  46.       glob.untilnextattacknormal = 60 * 60 * 4 + (game.getrandomnumber() * 2)
  47.       glob.attackcount = 1
  48.     end
  49.     glob.untilnextattacknormal = glob.untilnextattacknormal - 1
  50.     if glob.untilnextattacknormal <= 0 then
  51.       glob.untilnextattacknormal = 60 * 60 * 3 + game.getrandomnumber() * 60 * 60 * 9
  52.      
  53.       game.setmulticommand({type=defines.command.attack,
  54.                              target=game.getplayer(),
  55.                              distraction=defines.distraction.byenemy},
  56.                              glob.attackcount)
  57.       glob.attackcount = glob.attackcount + 1 + (game.getrandomnumber() * 3)
  58.     end
  59.      
  60.      
  61.      
  62.      
  63.      
  64.      
  65.   end
  66.   if event.name == "onsectorscanned" then
  67.         local secondsleft = math.floor(glob.untilnextattacknormal/ 60)
  68.       local minutes = math.floor((secondsleft)/60)
  69.       local seconds = math.floor(secondsleft - 60*minutes)
  70.   glob.player.print("Estimated time until next attack: " .. string.format("%d:%02d", minutes, seconds))
  71.   randomizer = game.getrandomnumber()
  72.  
  73.   if(randomizer >= .75) then
  74.   report = math.floor(glob.attackcount + (3 * game.getrandomnumber()) - (3 * game.getrandomnumber()))
  75.   glob.player.print("Reports are coming in that the enemy forces will number around: " .. report)
  76.   end
  77.   end
  78. end
Add Comment
Please, Sign In to add comment