Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Conditional Hooks
- $Application: FS2_Open
- $On Game Init:
- [
- MAlert = {}
- function MAlert:Init()
- self.Enabled = true
- --The different proximity levels, from farthest to closest
- --Sound is either the index from sounds.tbl or the sound name in the tbm, distance is distance from the player
- --Period is how long there is between beeps
- --self.Level[x] = {s(ound) = 00, d(istance) = 00, p(eriod) = 00}
- self.ProxL = {}
- self.ProxL[1] = {s = 164, d = 2001, p = 10}
- self.ProxL[2] = {s = 1001, d = 2000, p = 1}
- self.ProxL[3] = {s = 1002, d = 1250, p = 0.75}
- self.ProxL[4] = {s = 1003, d = 750, p = 0.5}
- self.ProxL[8] = {s = 1004, d = 400, p = 0.2}
- --Teams to notify you about
- self.Teams = {"Hostile"}
- --Put the $Name of weapon classes you want to be notified about here
- self.WeaponClass = {"Aratrum PD", "Howell PD"}
- --Extra fun targetting brackets too?
- self.Brackets = true
- --When to play a sound next
- self.NextNotify = -1
- end
- function MAlert:Exit()
- self.Enabled = nil
- self.NextNotify = nil
- self.ProxL = nil
- self.Teams = nil
- self.WeaponClass = nil
- self.Brackets = nil
- end
- function MAlert:GetLevel()
- local result
- local player = hv.Player
- local distance
- local r,g,b
- --gr.setColor(255,255,255)
- --gr.drawString("Distances ", 100, 100)
- for i = 1, #mn.Weapons do --for each weapon...
- local weapon = mn.Weapons[i]
- for _,v in pairs(self.WeaponClass) do --and each weapon class we defined...
- for _,team in pairs(self.Teams) do --and each team we defined...
- if (weapon.Class == tb.WeaponClasses[v]) and (weapon.Team.Name == team) then --if one matches...
- distance = player.Position:getDistance(weapon.Position) --get our distance to it
- if self.Brackets and (distance < self.ProxL[1].d) then --maybe add some brackets...
- r,g,b = weapon.Team:getColor()
- gr.setColor(r,g,b,192)
- gr.drawTargetingBrackets(weapon)
- end
- for i,p in ipairs(self.ProxL) do --go through the distances we had defined....
- if (p.d > distance) and ((not result) or (i > result)) then --if the distances are right and its more important than the last one...
- --gr.drawString(p.d)
- result = i -- ...that's our warning level!
- end
- end
- end
- end
- end
- end
- return result
- end
- function MAlert:Notify(level)
- if level then
- local mtime = mn.getMissionTime()
- if (level > 0) and (self.NextNotify < mtime) then
- local l = self.ProxL[level]
- ad.playGameSound(l.s)
- self.NextNotify = mtime + l.p
- end
- end
- end
- ]
- $State: GS_STATE_GAME_PLAY
- $On Gameplay Start:
- [
- if MAlert.Enabled then
- MAlert:Exit()
- end
- ]
- $On Frame:
- [
- if MAlert.Enabled then
- MAlert:Notify(MAlert:GetLevel())
- end
- ]
- $On Mission End:
- [
- if MAlert.Enabled then
- MAlert:Exit()
- end
- ]
- #End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement