Guest User

[Training Mission] Alternate Script for Basic Bazooka Traini

a guest
May 30th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.21 KB | None | 0 0
  1. -- Hedgewars Bazooka Training
  2.  
  3.  
  4. -- Lines such as this one are comments - they are ignored
  5. -- by the game, no matter what kind of text is in there.
  6. -- It's also possible to place a comment after some real
  7. -- instruction as you see below. In short, everything
  8. -- following "--" is ignored.
  9.  
  10. ---------------------------------------------------------------
  11. -- At first we implement the localization library using loadfile.
  12. -- This allows us to localize strings without needing to think
  13. -- about translations.
  14. -- We can use the function loc(text) to localize a string.
  15.  
  16. HedgewarsScriptLoad("/Scripts/Locale.lua")
  17.  
  18. -- This variable will hold the number of destroyed targets.
  19. local score = 0
  20. -- This variable represents the number of targets to destroy.
  21. local score_goal = 5
  22. -- This variable controls how many milliseconds/ticks we'd
  23. -- like to wait before we end the round once all targets
  24. -- have been destroyed.
  25. local end_timer = 1000 -- 1000 ms = 1 s
  26. -- This variable is set to true if the game is lost (i.e.
  27. -- time runs out).
  28. local game_lost = false
  29. -- This variable will point to the hog's gear
  30. local player = nil
  31. -- This variable will grab the time left at the end of the round
  32. local time_goal = 0
  33.  
  34. -- This is a custom function to make it easier to
  35. -- spawn more targets with just one line of code
  36. -- You may define as many custom functions as you
  37. -- like.
  38. function spawnTarget()
  39.     -- add a new target gear
  40.     gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
  41.    
  42.     -- move it to a random position within 0 and
  43.     -- LAND_WIDTH - the width of the map
  44.     FindPlace(gear, true, 0, LAND_WIDTH)
  45.    
  46.     -- move the target to a higher vertical position
  47.     -- to ensure it's not somewhere down below
  48.     x, y = GetGearPosition(gear)
  49.     SetGearPosition(gear, x, 0)
  50. end
  51.  
  52. function onNewTurn()
  53.     ParseCommand("setweap " .. string.char(amBazooka))
  54. end
  55.  
  56. -- This function is called before the game loads its
  57. -- resources.
  58. -- It's one of the predefined function names that will
  59. -- be called by the game. They give you entry points
  60. -- where you're able to call your own code using either
  61. -- provided instructions or custom functions.
  62. function onGameInit()
  63.     -- At first we have to overwrite/set some global variables
  64.     -- that define the map, the game has to load, as well as
  65.     -- other things such as the game rules to use, etc.
  66.     -- Things we don't modify here will use their default values.
  67.  
  68.     -- The base number for the random number generator
  69.     Seed = 1
  70.     -- Game settings and rules
  71.     GameFlags = gfMultiWeapon + gfOneClanMode
  72.     -- The time the player has to move each round (in ms)
  73.     TurnTime = 30000
  74.     -- The frequency of crate drops
  75.     CaseFreq = 0
  76.     -- The number of mines being placed
  77.     MinesNum = 0
  78.     -- The number of explosives being placed
  79.     Explosives = 0
  80.     -- The delay between each round
  81.     Delay = 0
  82.     -- The map to be played
  83.     Map = "Ruler"
  84.     -- The theme to be used
  85.     Theme = "Nature"
  86.  
  87.     -- Create the player team
  88.     AddTeam(loc("Bazooka Team"), 14483456, "Simple", "Island", "Default")
  89.     -- And add a hog to it
  90.     player = AddHog(loc("Hunter"), 0, 1, "NoHat")
  91.     SetGearPosition(player, 1900, 800)
  92. end
  93.  
  94. -- This function is called when the round starts
  95. -- it spawns the first target that has to be destroyed.
  96. -- In addition it shows the scenario goal(s).
  97. function onGameStart()
  98.     -- Spawn the first target.
  99.     spawnTarget()
  100.    
  101.     -- Show some nice mission goals.
  102.     -- Parameters are: caption, sub caption, description,
  103.     -- extra text, icon and time to show.
  104.     -- A negative icon parameter (-n) represents the n-th weapon icon
  105.     -- A positive icon paramter (n) represents the (n+1)-th mission icon
  106.     -- A timeframe of 0 is replaced with the default time to show.
  107.     ShowMission(loc("Bazooka Training"), loc("Aiming Practice"), loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission."), -amBazooka, 0)
  108. end
  109.  
  110. function onGameTick()
  111.     SetGearPosition(player, 1900, 800)
  112. end
  113. -- This function is called every game tick.
  114. -- Note that there are 1000 ticks within one second.
  115. -- You shouldn't try to calculate too complicated
  116. -- code here as this might slow down your game.
  117. function onGameTick20()
  118.     -- If time's up, set the game to be lost.
  119.     -- We actually check the time to be "1 ms" as it
  120.     -- will be at "0 ms" right at the start of the game.
  121.     if TurnTimeLeft < 40 and TurnTimeLeft > 20 and score < score_goal then
  122.         game_lost = true
  123.         -- ... and show a short message.
  124.         ShowMission(loc("Bazooka Training"), loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0)
  125.         -- How about killing our poor hog due to his poor performance?
  126.         SetHealth(player, 0)
  127.         -- Just to be sure set the goal time to 1 ms
  128.         time_goal = 1
  129.     end
  130.     -- If the goal is reached or we've lost ...
  131.     if score == score_goal or game_lost then
  132.         -- ... check to see if the time we'd like to
  133.         -- wait has passed and then ...
  134.         if end_timer == 0 then
  135.             -- ... end the game ...
  136.             EndGame()
  137.         else
  138.             -- ... or just lower the timer by 1.
  139.             -- Reset the time left to stop the timer
  140.             TurnTimeLeft = time_goal
  141.         end
  142.         end_timer = end_timer - 20
  143.     end
  144. end
  145.  
  146. -- This function is called when the game is initialized
  147. -- to request the available ammo and probabilities
  148. function onAmmoStoreInit()
  149.     -- add an unlimited supply of bazooka ammo
  150.     SetAmmo(amBazooka, 9, 0, 0, 0)
  151. end
  152.  
  153. -- This function is called when a new gear is added.
  154. -- We don't need it for this training, so we can
  155. -- keep it empty.
  156. -- function onGearAdd(gear)
  157. -- end
  158.  
  159. -- This function is called before a gear is destroyed.
  160. -- We use it to count the number of targets destroyed.
  161. function onGearDelete(gear)
  162.     -- We're only interested in target gears.
  163.     if GetGearType(gear) == gtTarget then
  164.         -- Add one point to our score/counter
  165.         score = score + 1
  166.         -- If we haven't reached the goal ...
  167.         if score < score_goal then
  168.             -- ... spawn another target.
  169.             spawnTarget()
  170.         else
  171.             if not game_lost then
  172.             -- Otherwise show that the goal was accomplished
  173.             ShowMission(loc("Bazooka Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
  174.             -- Also let the hogs shout "victory!"
  175.             PlaySound(sndVictory)
  176.             -- Save the time left so we may keep it.
  177.             time_goal = TurnTimeLeft
  178.             end
  179.         end
  180.     end
  181. end
Advertisement
Add Comment
Please, Sign In to add comment