Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. class 'cMedals'
  2. function cMedals:__init()
  3.  
  4.     self.seconds = 0
  5.    
  6.     self.awayDist = 100
  7.    
  8.     self.random = math.random()
  9.    
  10.     Events:Subscribe("SecondTick", self, self.SecondTick)
  11.     Events:Subscribe("ModuleUnload", self, self.Unload)
  12.     Events:Subscribe("ShapeTriggerEnter", self, self.TriggerEnter)
  13.     Network:Subscribe("ReceiveMedal", self, self.ReceiveMedal)
  14.    
  15.    
  16. end
  17.  
  18. function cMedals:SecondTick()
  19.  
  20.     self.seconds = self.seconds + 1
  21.    
  22.     if self.seconds > 60 * 20 * self.random and IsValid(self.medalObj) then
  23.        
  24.         self.seconds = 0
  25.        
  26.         self:CreateHint()
  27.        
  28.         self.random = math.random()
  29.        
  30.     end
  31.    
  32. end
  33.  
  34. function cMedals:TriggerEnter(args)
  35.  
  36.     if not IsValid(self.medalObj) then return end
  37.    
  38.     if args.entity ~= LocalPlayer then return end
  39.    
  40.     if args.trigger:GetId() ~= self.medalTrigger:GetId() then return end
  41.    
  42.     self.medalObj:Remove()
  43.     self.medalTrigger:Remove()
  44.     self.medalTrigger = nil
  45.    
  46.     Network:Send("PlayerFoundMedal")
  47.        
  48.     CreateGongSound()
  49.        
  50. end
  51.  
  52. function cMedals:PostTick()
  53.  
  54.     if not IsValid(self.medalObj) then return end
  55.    
  56.     local dist = Vector3.Distance(self.medalObj:GetPosition() - Vector3(0,2,0), LocalPlayer:GetPosition())
  57.    
  58.     if dist < 5 then
  59.        
  60.         CreateGongSound()
  61.         CreateGongEffect(self.medalObj:GetPosition())
  62.        
  63.         self.medalObj:Remove()
  64.        
  65.         Events:Unsubscribe(self.postTickSub)
  66.         self.postTickSub = nil
  67.        
  68.         Network:Send("PlayerFoundMedal")
  69.        
  70.        
  71.     end
  72.  
  73. end
  74.  
  75. function CreateGongEffect()
  76.  
  77.     ClientParticleSystem.Play(AssetLocation.Game, {
  78.         angle = Angle(0,0,0),
  79.         position = pos,
  80.         path = "fx_vehicle_impact_snow_01.psmb"
  81.         })
  82.        
  83. end
  84.  
  85. function CreateGongSound()
  86.  
  87.     local sound = ClientSound.Create(AssetLocation.Game, {
  88.             bank_id = 24,
  89.             sound_id = 0,
  90.             position = LocalPlayer:GetPosition(),
  91.             angle = Angle()
  92.     })
  93.  
  94.     sound:SetParameter(0,0.75)
  95.  
  96. end
  97.  
  98. function CreateHintSound()
  99.  
  100.     local sound = ClientSound.Create(AssetLocation.Game, {
  101.         bank_id = 28,
  102.         sound_id = 97,
  103.         position = LocalPlayer:GetPosition(),
  104.         angle = Angle()
  105.     })
  106.     sound:SetParameter(0,0.75)
  107.  
  108.  
  109. end
  110.  
  111. function cMedals:CreateHint()
  112.  
  113.     local pos = self.medalObj:GetPosition()
  114.     Waypoint:SetPosition(pos)
  115.     local angle = self.medalObj:GetAngle()
  116.     local localPos = LocalPlayer:GetPosition()
  117.    
  118.     local dist = Vector3.Distance(pos, localPos)
  119.    
  120.     if dist > 250 then
  121.        
  122.         local rayAngle = Angle.FromVectors(Vector3.Forward, pos - localPos)
  123.        
  124.         local ray = Physics:Raycast(localPos + Vector3(0,100,0), rayAngle * Vector3.Forward, 0, self.awayDist)
  125.         local rayDown = Physics:Raycast(ray.position + Vector3(0,300,0), Vector3.Down, 1, 1000)
  126.        
  127.         if rayDown.position.y < 200 then rayDown.position.y = 200 end
  128.  
  129.         local hintDist = Vector3.Distance(rayDown.position, localPos)
  130.        
  131.         if hintDist < self.awayDist * 2 and hintDist > 10 then
  132.            
  133.             CreateHintSound()
  134.            
  135.             CreateHintEffect(rayDown.position)
  136.  
  137.         end
  138.        
  139.     end
  140.  
  141. end
  142.  
  143. function CreateHintEffect(pos)
  144.  
  145.     ClientParticleSystem.Play(AssetLocation.Game, {
  146.         angle = Angle(0,0,0),
  147.         position = pos,
  148.         path = "fx_km07_cylinder_l2_fire_09.psmb",
  149.         timeout = 14
  150.         })
  151.        
  152.     ClientLight.Play({
  153.         position = pos + Vector3(0,2.5,0),
  154.         color = Color(255,199,43),
  155.         multiplier = 7,
  156.         radius = 7,
  157.         constant_attenuation = 0,
  158.         linear_attenuation = 0,
  159.         quadratic_attenuation = 1,
  160.         timeout = 14
  161.         })
  162.  
  163. end
  164.  
  165. function cMedals:ReceiveMedal(args)
  166.  
  167.     self.medalObj = ClientStaticObject.Create({
  168.         position = args.position,
  169.         angle = args.angle,
  170.         model = "km06.base.flz/key015_01-z1_01.lod"
  171.     })
  172.    
  173.     if self.medalTrigger then self.medalTrigger:Remove() end
  174.     self.medalTrigger = ShapeTrigger.Create({
  175.         position = args.position - Vector3(0,2,0),
  176.         angle = Angle(0, 0, 0),
  177.         components = {
  178.             {
  179.                 type = TriggerType.Sphere,
  180.                 size = Vector3(3.5, 3.5, 3.5),
  181.                 position = Vector3(),
  182.             }
  183.         },
  184.         trigger_player = true,
  185.         trigger_player_in_vehicle = false,
  186.         trigger_vehicle = false,
  187.         trigger_npc = false,
  188.     })
  189.  
  190. end
  191.  
  192. function cMedals:Unload()
  193.  
  194.     if IsValid(self.medalObj) then
  195.    
  196.         self.medalObj:Remove()
  197.        
  198.     end
  199.    
  200.     if self.wing1 then self.wing1:Remove() end
  201.     if self.wing2 then self.wing2:Remove() end
  202.    
  203. end
  204.  
  205. cMedals = cMedals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement