Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class 'cMedals'
- function cMedals:__init()
- self.seconds = 0
- self.awayDist = 100
- self.random = math.random()
- Events:Subscribe("SecondTick", self, self.SecondTick)
- Events:Subscribe("ModuleUnload", self, self.Unload)
- Events:Subscribe("ShapeTriggerEnter", self, self.TriggerEnter)
- Network:Subscribe("ReceiveMedal", self, self.ReceiveMedal)
- end
- function cMedals:SecondTick()
- self.seconds = self.seconds + 1
- if self.seconds > 60 * 20 * self.random and IsValid(self.medalObj) then
- self.seconds = 0
- self:CreateHint()
- self.random = math.random()
- end
- end
- function cMedals:TriggerEnter(args)
- if not IsValid(self.medalObj) then return end
- if args.entity ~= LocalPlayer then return end
- if args.trigger:GetId() ~= self.medalTrigger:GetId() then return end
- self.medalObj:Remove()
- self.medalTrigger:Remove()
- self.medalTrigger = nil
- Network:Send("PlayerFoundMedal")
- CreateGongSound()
- end
- function cMedals:PostTick()
- if not IsValid(self.medalObj) then return end
- local dist = Vector3.Distance(self.medalObj:GetPosition() - Vector3(0,2,0), LocalPlayer:GetPosition())
- if dist < 5 then
- CreateGongSound()
- CreateGongEffect(self.medalObj:GetPosition())
- self.medalObj:Remove()
- Events:Unsubscribe(self.postTickSub)
- self.postTickSub = nil
- Network:Send("PlayerFoundMedal")
- end
- end
- function CreateGongEffect()
- ClientParticleSystem.Play(AssetLocation.Game, {
- angle = Angle(0,0,0),
- position = pos,
- path = "fx_vehicle_impact_snow_01.psmb"
- })
- end
- function CreateGongSound()
- local sound = ClientSound.Create(AssetLocation.Game, {
- bank_id = 24,
- sound_id = 0,
- position = LocalPlayer:GetPosition(),
- angle = Angle()
- })
- sound:SetParameter(0,0.75)
- end
- function CreateHintSound()
- local sound = ClientSound.Create(AssetLocation.Game, {
- bank_id = 28,
- sound_id = 97,
- position = LocalPlayer:GetPosition(),
- angle = Angle()
- })
- sound:SetParameter(0,0.75)
- end
- function cMedals:CreateHint()
- local pos = self.medalObj:GetPosition()
- Waypoint:SetPosition(pos)
- local angle = self.medalObj:GetAngle()
- local localPos = LocalPlayer:GetPosition()
- local dist = Vector3.Distance(pos, localPos)
- if dist > 250 then
- local rayAngle = Angle.FromVectors(Vector3.Forward, pos - localPos)
- local ray = Physics:Raycast(localPos + Vector3(0,100,0), rayAngle * Vector3.Forward, 0, self.awayDist)
- local rayDown = Physics:Raycast(ray.position + Vector3(0,300,0), Vector3.Down, 1, 1000)
- if rayDown.position.y < 200 then rayDown.position.y = 200 end
- local hintDist = Vector3.Distance(rayDown.position, localPos)
- if hintDist < self.awayDist * 2 and hintDist > 10 then
- CreateHintSound()
- CreateHintEffect(rayDown.position)
- end
- end
- end
- function CreateHintEffect(pos)
- ClientParticleSystem.Play(AssetLocation.Game, {
- angle = Angle(0,0,0),
- position = pos,
- path = "fx_km07_cylinder_l2_fire_09.psmb",
- timeout = 14
- })
- ClientLight.Play({
- position = pos + Vector3(0,2.5,0),
- color = Color(255,199,43),
- multiplier = 7,
- radius = 7,
- constant_attenuation = 0,
- linear_attenuation = 0,
- quadratic_attenuation = 1,
- timeout = 14
- })
- end
- function cMedals:ReceiveMedal(args)
- self.medalObj = ClientStaticObject.Create({
- position = args.position,
- angle = args.angle,
- model = "km06.base.flz/key015_01-z1_01.lod"
- })
- if self.medalTrigger then self.medalTrigger:Remove() end
- self.medalTrigger = ShapeTrigger.Create({
- position = args.position - Vector3(0,2,0),
- angle = Angle(0, 0, 0),
- components = {
- {
- type = TriggerType.Sphere,
- size = Vector3(3.5, 3.5, 3.5),
- position = Vector3(),
- }
- },
- trigger_player = true,
- trigger_player_in_vehicle = false,
- trigger_vehicle = false,
- trigger_npc = false,
- })
- end
- function cMedals:Unload()
- if IsValid(self.medalObj) then
- self.medalObj:Remove()
- end
- if self.wing1 then self.wing1:Remove() end
- if self.wing2 then self.wing2:Remove() end
- end
- cMedals = cMedals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement