Advertisement
MjnMixael

Untitled

Aug 13th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. #Conditional Hooks
  2. $Application: FS2_Open
  3.  
  4. $On Game Init:
  5. [
  6.  
  7. MAlert = {}
  8.  
  9. function MAlert:Init()
  10.  
  11. self.Enabled = true
  12.  
  13. --The different proximity levels, from farthest to closest
  14. --Sound is either the index from sounds.tbl or the sound name in the tbm, distance is distance from the player
  15. --Period is how long there is between beeps
  16. --self.Level[x] = {s(ound) = 00, d(istance) = 00, p(eriod) = 00}
  17. self.ProxL = {}
  18. self.ProxL[1] = {s = 164, d = 2001, p = 10}
  19. self.ProxL[2] = {s = 1001, d = 2000, p = 1}
  20. self.ProxL[3] = {s = 1002, d = 1250, p = 0.75}
  21. self.ProxL[4] = {s = 1003, d = 750, p = 0.5}
  22. self.ProxL[8] = {s = 1004, d = 400, p = 0.2}
  23.  
  24. --Teams to notify you about
  25. self.Teams = {"Hostile"}
  26.  
  27. --Put the $Name of weapon classes you want to be notified about here
  28. self.WeaponClass = {"Aratrum PD", "Howell PD"}
  29.  
  30. --Extra fun targetting brackets too?
  31. self.Brackets = true
  32.  
  33. --When to play a sound next
  34. self.NextNotify = -1
  35.  
  36. end
  37.  
  38. function MAlert:Exit()
  39.  
  40. self.Enabled = nil
  41. self.NextNotify = nil
  42. self.ProxL = nil
  43. self.Teams = nil
  44. self.WeaponClass = nil
  45. self.Brackets = nil
  46.  
  47. end
  48.  
  49. function MAlert:GetLevel()
  50.  
  51. local result
  52. local player = hv.Player
  53. local distance
  54. local r,g,b
  55.  
  56. --gr.setColor(255,255,255)
  57. --gr.drawString("Distances ", 100, 100)
  58.  
  59. for i = 1, #mn.Weapons do --for each weapon...
  60. local weapon = mn.Weapons[i]
  61. for _,v in pairs(self.WeaponClass) do --and each weapon class we defined...
  62. for _,team in pairs(self.Teams) do --and each team we defined...
  63. if (weapon.Class == tb.WeaponClasses[v]) and (weapon.Team.Name == team) then --if one matches...
  64. distance = player.Position:getDistance(weapon.Position) --get our distance to it
  65.  
  66. if self.Brackets and (distance < self.ProxL[1].d) then --maybe add some brackets...
  67. r,g,b = weapon.Team:getColor()
  68. gr.setColor(r,g,b,192)
  69. gr.drawTargetingBrackets(weapon)
  70. end
  71.  
  72. for i,p in ipairs(self.ProxL) do --go through the distances we had defined....
  73. if (p.d > distance) and ((not result) or (i > result)) then --if the distances are right and its more important than the last one...
  74. --gr.drawString(p.d)
  75. result = i -- ...that's our warning level!
  76. end
  77. end
  78. end
  79. end
  80. end
  81. end
  82.  
  83. return result
  84.  
  85. end
  86.  
  87. function MAlert:Notify(level)
  88.  
  89. if level then
  90. local mtime = mn.getMissionTime()
  91.  
  92. if (level > 0) and (self.NextNotify < mtime) then
  93. local l = self.ProxL[level]
  94. ad.playGameSound(l.s)
  95. self.NextNotify = mtime + l.p
  96. end
  97. end
  98.  
  99. end
  100.  
  101. ]
  102.  
  103. $State: GS_STATE_GAME_PLAY
  104. $On Gameplay Start:
  105. [
  106. if MAlert.Enabled then
  107. MAlert:Exit()
  108. end
  109.  
  110. ]
  111.  
  112. $On Frame:
  113. [
  114. if MAlert.Enabled then
  115. MAlert:Notify(MAlert:GetLevel())
  116. end
  117. ]
  118.  
  119. $On Mission End:
  120. [
  121. if MAlert.Enabled then
  122. MAlert:Exit()
  123. end
  124. ]
  125.  
  126. #End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement