Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class 'FireArmsManager'
- function FireArmsManager:__init()
- GlobalCooldownTimer = Timer()
- DotColor = Color(255, 0, 0, 150)
- DotRadius = Render.Size.x / 500
- self.Firing = false
- Events:Subscribe("LocalPlayerBulletHit", self, self.HandleDamage)
- Events:Subscribe("LocalPlayerInput", self, self.LocalPlayerInput)
- Events:Subscribe("Render", self, self.Render)
- Events:Subscribe("InputPoll", self, self.InputPoll)
- positionTable = {}
- end
- function FireArmsManager:RenderTest()
- if CameraPos and CameraAngle then
- local CalcAngle = Copy(CameraAngle)
- for i = 1, 200 do
- local integer = (5*i) + 5
- CalcAngle.pitch = CalcAngle.pitch + -0.00436332313--0.00872664626
- local FireRay = Physics:Raycast(CameraPos, CalcAngle * Vector3.Forward, 0, integer)
- local RenderColor = Color.Red
- local valid = IsValid(FireRay.entity)
- if valid then
- RenderColor = Color.Lime
- end
- Render:DrawLine(CameraPos, FireRay.position, RenderColor)
- end
- end
- end
- end
- function FireArmsManager:Render()
- if Game:GetState() ~= GUIState.Game then return end
- self:RenderAimDot(LocalPlayer)
- for players in Client:GetStreamedPlayers() do
- self:RenderAimDot(players)
- end
- for i, v in pairs(positionTable) do
- Render:DrawLine(lastPosition, v, Color.Red)
- end
- end
- function FireArmsManager:RenderAimDot(player)
- local PlayerWeapon = player:GetEquippedWeapon()
- if PlayerWeapon then
- if StadardArmsStatsTable[PlayerWeapon.id] then
- if StadardArmsStatsTable[PlayerWeapon.id].RedDot then
- if player:GetState() == 4 or player:GetState() == 5 then
- local AimDot = player:GetAimTarget()
- if AimDot then
- local DotPos = AimDot.position
- if DotPos then
- local ScreenDotPos = Render:WorldToScreen(DotPos)
- Render:FillCircle(ScreenDotPos, DotRadius, DotColor)
- end
- end
- end
- end
- end
- end
- end
- function FireArmsManager:RenderTest()
- local CameraPos=Camera:GetPosition()
- local CalcAngle=Copy(Camera:GetAngle())
- for i = 50, 20 do
- local CalcAngle.pitch = CalcAngle.pitch + -0.00872664626
- local FireRay = Physics:Raycast(CameraPos, CalcAngle * Vector3.Forward, 0, i)
- local RenderColor=Color.Red
- if IsValid(FireRay.entity) then
- end
- Render:DrawLine(CameraPos, FireRay.position, RenderColor)
- end
- end
- function FireArmsManager:HandleDamage(args)
- if IsValid(args.attacker) then
- local AttackerWeapon = args.attacker:GetEquippedWeapon()
- if AttackerWeapon then
- if StadardArmsStatsTable[AttackerWeapon.id] then
- return false
- end
- end
- end
- end
- function FireArmsManager:InputPoll()
- if Game:GetState() == GUIState.Game then
- if self.Firing then
- -- Input:SetValue(Action.FireRight, 0, false)
- self.Firing = false
- end
- end
- end
- function FireArmsManager:FireAtTarget(target, attacker, statsTable, aimTable, rayTable)
- if IsValid(target) and IsValid(attacker) then
- -- print("Firing...")
- local FireTable = {}
- FireTable.Target = target
- FireTable.Attacker = attacker
- FireTable.Stats = statsTable
- FireTable.Aim = aimTable
- FireTable.Ray = rayTable
- FireTable.NearestBone = nil
- if target.__type == "Player" then
- local NearestBone = nil
- local NearestBonePosition = target:GetPosition()
- for boneName, bone in pairs(target:GetBones()) do
- local NearestBoneDistance = Vector3.Distance(NearestBonePosition, rayTable.position)
- local ThisBoneDistance = Vector3.Distance(bone.position, rayTable.position)
- if ThisBoneDistance < NearestBoneDistance then
- NearestBone = boneName
- NearestBonePosition = bone.position
- end
- end
- FireTable.NearestBone = NearestBone
- end
- Network:Send("FireArmDamagePlayer", FireTable)
- end
- end
- function FireArmsManager:LocalPlayerInput(inputType)
- local PlayerWeapon = LocalPlayer:GetEquippedWeapon()
- local PlayerSlot = LocalPlayer:GetEquippedSlot()
- local PlayerWeaponID = PlayerWeapon.id
- local PlayerWeaponClip = PlayerWeapon.ammo_clip
- local PlayerWeaponReserve = PlayerWeapon.ammo_reserve
- local PlayerVehicle = LocalPlayer:GetVehicle()
- local PlayerState = LocalPlayer:GetState()
- local PlayerBaseState = LocalPlayer:GetBaseState()
- local PlayerUpperState = LocalPlayer:GetUpperBodyState()
- local EffectiveStatsTable = StadardArmsStatsTable[PlayerWeaponID]
- if self.Firing then return false end
- if not EffectiveStatsTable then return end
- if LocalPlayer:InVehicle() then return end
- local EffectiveCooldown = EffectiveStatsTable.Cooldown
- if inputType.input == Action.FireRight then
- if PlayerWeaponClip > 0 then
- if GlobalCooldownTimer:GetSeconds() >= EffectiveCooldown then
- GlobalCooldownTimer:Restart()
- if PlayerUpperState == 347 or PlayerUpperState == 348 then
- self.Firing = true
- local FireAim = LocalPlayer:GetAimTarget()
- -- print("AimTable:",FireAim, FireAim.entity, FireAim.position)
- -- print("RayTable:",FireRay, FireRay.distance, FireRay.position, FireRay.normal, FireRay.entity)
- local FireRay = Physics:Raycast(Camera:GetPosition(), (Camera:GetAngle() * Vector3(0, 0, -1)), 0, EffectiveStatsTable.MaxRange)
- if PlayerWeapon.id == 14 then -- sniper rifle
- -- bullet drop stuff
- totalRange = 0
- positionTable = {}
- local originalVector = Camera:GetAngle() * Vector3.Forward
- FireRay = Physics:Raycast(Camera:GetPosition(), originalVector , 0, 5)
- pitchAngle = Angle(0, -0.00872664626, 0)
- oldAngle = Camera:GetAngle()
- totalRange = FireRay.distance
- CameraPos = Camera:GetPosition()
- CameraAngle = Camera:GetAngle()
- Events:Subscribe("Render", self, self.RenderTest)
- while totalRange < 1000 and totalRange % 5 == 0 do
- directionVector = oldAngle*Vector3.Forward
- FireRay = Physics:Raycast(FireRay.position, directionVector, 0, 5)
- totalRange = totalRange + FireRay.distance
- originalVector = directionVector
- lastPosition = Camera:GetPosition()
- table.insert(positionTable, FireRay.position)
- oldAngle = oldAngle
- oldAngle.pitch = oldAngle.pitch + pitchAngle.y
- if IsValid(FireRay.entity) then -- in the very rare case that it hits s something on exactly 5 meters or something
- break
- end
- end
- if not IsValid(FireRay.entity) then return end
- print("Drop target was valid")
- if FireRay.entity == nil then return end
- print("Drop target wasn't nil")
- if FireRay.entity.__type == "StaticObject" or FireRay.entity.__type == "ClientStaticObject" then return end
- print("Drop target was of correct type")
- if Vector3.Distance(LocalPlayer:GetPosition(), FireRay.entity:GetPosition()) < EffectiveStatsTable.MaxRange then
- self:FireAtTarget(FireAim.entity, LocalPlayer, EffectiveStatsTable, FireAim, FireRay)
- print("Firing at drop target")
- end
- else
- if not IsValid(FireAim.entity) and not IsValid(FireRay.entity) then return end
- if FireAim.entity == nil or FireRay.entity == nil then return end
- if FireAim.entity.__type == "StaticObject" or FireAim.entity.__type == "ClientStaticObject" then return end
- if FireAim.entity:GetPosition() == FireRay.entity:GetPosition() then
- if Vector3.Distance(LocalPlayer:GetPosition(), FireRay.entity:GetPosition()) < EffectiveStatsTable.MaxRange then
- self:FireAtTarget(FireAim.entity, LocalPlayer, EffectiveStatsTable, FireAim, FireRay)
- end
- end
- end
- end
- else
- return false
- end
- end
- end
- end
- FireArmsManager = FireArmsManager()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement