Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[-------------------------------------------------------------------------
- Energy Rifle by Demonkush
- ---------------------------------------------------------------------------]]
- AddCSLuaFile()
- SWEP.PrintName = "Лазер пушечка"
- SWEP.HoldType = "ar2"
- SWEP.ViewModel = "models/weapons/c_irifle.mdl"
- SWEP.WorldModel = "models/weapons/w_irifle.mdl"
- SWEP.ShowWorldModel = true
- SWEP.ShowViewModel = true
- SWEP.UseHands = true
- SWEP.ViewModelFlip = false
- SWEP.Icon = "vgui/ttt/icon_polter"
- SWEP.ViewModelFOV = 70
- SWEP.Kind = WEAPON_HEAVY
- SWEP.Base = "weapon_tttbase"
- SWEP.Slot = 2
- function SWEP:OnDrop()
- self:Remove()
- end
- SWEP.Primary.ClipSize = -1
- SWEP.Primary.DefaultClip = -1
- SWEP.Primary.Automatic = true
- SWEP.Primary.Ammo = "none"
- SWEP.Primary.Sound = "demon_laserrifle.shoot"
- SWEP.Primary.Damage = 0
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = "none"
- SWEP.SoundDelay = 0
- SWEP.PunchDelay = 0
- SWEP.NextAttack = 0.5
- SWEP.Energy = 100
- SWEP.MaxEnergy = 100
- SWEP.RechargeDelay = 1
- SWEP.WeaponMode = "powershot"
- local weaponmodes = {}
- weaponmodes["powershot"] = "Power Shot" -- Super Beam
- weaponmodes["pulsebomb"] = "Pulse Bomb" -- Bomb
- weaponmodes["shockblast"] = "Shock Blast" -- Shotgun
- if SERVER then
- util.AddNetworkString("demon_laserrifle_sendmode")
- util.AddNetworkString("demon_laserrifle_delay")
- end
- function SWEP:SendMode(mode)
- if CLIENT then return end
- net.Start("demon_laserrifle_sendmode")
- net.WriteString(mode)
- net.WriteEntity(self)
- net.Send(self:GetOwner())
- end
- function SWEP:SendDelay(delay)
- if CLIENT then return end
- net.Start("demon_laserrifle_delay")
- net.WriteInt(delay,8)
- net.WriteEntity(self)
- net.Send(self:GetOwner())
- end
- function SWEP:Reload()
- self:CycleWeapon()
- end
- function SWEP:CycleWeapon()
- if CLIENT then return end
- if self.NextAttack > CurTime() then return end
- self.NextAttack = CurTime()+0.5
- self:SendDelay(0.5)
- local mode = self.WeaponMode
- if mode == "powershot" then
- self.WeaponMode = "pulsebomb"
- elseif mode == "pulsebomb" then
- self.WeaponMode = "shockblast"
- elseif mode == "shockblast" then
- self.WeaponMode = "powershot"
- end
- self:SendMode(self.WeaponMode)
- end
- if CLIENT then
- net.Receive("demon_laserrifle_sendmode",function(len,pl)
- local mode = net.ReadString()
- local wep = net.ReadEntity()
- if !IsValid(wep) then return end
- wep.WeaponMode = mode
- wep:EmitSound("npc/roller/mine/rmine_chirp_quest1.wav",45,90,0.5)
- end)
- net.Receive("demon_laserrifle_delay",function(len,pl)
- local delay = net.ReadInt(8)
- local wep = net.ReadEntity()
- if !IsValid(wep) then return end
- wep.NextAttack = CurTime() + delay
- end)
- end
- --[[-------------------------------------------------------------------------
- Functions
- ---------------------------------------------------------------------------]]
- function SWEP:Initialize()
- self.NextAttack = 0
- self.Energy = 100
- self.MaxEnergy = 100
- self.RechargeDelay = 0
- self:SetHoldType(self.HoldType)
- self:SetNWInt("Energy",self.MaxEnergy)
- end
- function SWEP:Think()
- if CLIENT then
- LocalPlayer():GetViewModel():SetMaterial("")
- end
- if self.RechargeDelay < CurTime() then
- if self.Energy < self.MaxEnergy then
- self.Energy = math.Clamp(self.Energy+1,0,self.MaxEnergy)
- self:SetNWInt("Energy",self.Energy)
- end
- self.RechargeDelay = CurTime() + 0.1
- end
- end
- function SWEP:CanAttack(energy)
- if self.NextAttack < CurTime() then
- if self.Energy >= energy then
- return true
- else return false end
- else return false end
- end
- function SWEP:PrimaryAttack()
- if !self:CanAttack(3) then return end
- self:EmitSound("demon_laserrifle.shoot")
- self:GetOwner():SetAnimation(PLAYER_ATTACK1)
- self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
- local bullet = {}
- bullet.Num = 1
- bullet.Src = self:GetOwner():GetShootPos()
- bullet.Dir = self:GetOwner():GetAimVector()
- bullet.Spread = Vector(0.01, 0.01, 0)
- bullet.Tracer = 1
- bullet.TracerName = "demon_tracer_laser"
- bullet.Force = 3
- bullet.Damage = 15
- bullet.Callback = function(att,tr,dmg)
- if tr.Hit then
- sound.Play("ambient/levels/labs/electric_explosion5.wav",tr.HitPos,75,100,0.5)
- local blast = EffectData()
- blast:SetOrigin(tr.HitPos)
- blast:SetScale(0.5)
- util.Effect("demon_blast_small",blast)
- local col = HSVToColor(RealTime() * 64 % 360, 0.65, 1)
- local impact = EffectData()
- impact:SetOrigin(tr.HitPos)
- impact:SetNormal(tr.HitNormal)
- impact:SetScale(1)
- impact:SetAngles(Angle(col.r,col.g,col.b))
- util.Effect("demon_decal_pulse",impact)
- local blast = EffectData()
- blast:SetOrigin(tr.HitPos)
- blast:SetScale(0.125)
- blast:SetAngles(Angle(col.r,col.g,col.b))
- util.Effect("fx_model_blast",blast)
- end
- end
- local r = math.random(1,2)
- if r == 1 then
- self.Energy = self.Energy - 3
- self:SetNWInt("Energy",self.Energy)
- end
- self:GetOwner():ViewPunch(Angle(math.Rand(-1,1),math.Rand(-0.5,0.5),0))
- self:GetOwner():FireBullets(bullet)
- self.NextAttack = CurTime()+0.1
- self:SendDelay(0.1)
- end
- local explodedmgents = {
- "npc_strider",
- "npc_combinegunship",
- "npc_combinedropship",
- "npc_rollermine",
- "npc_helicopter",
- "combine_mine",
- "func_tank"
- }
- function SWEP:PowerShot()
- self:EmitSound("demon_laserrifle.shootbig")
- self:GetOwner():SetAnimation(PLAYER_ATTACK1)
- self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
- local bullet = {}
- bullet.Num = 1
- bullet.Src = self:GetOwner():GetShootPos()
- bullet.Dir = self:GetOwner():GetAimVector()
- bullet.Spread = Vector(0.01, 0.01, 0)
- bullet.Tracer = 1
- bullet.TracerName = "demon_tracer_laser"
- bullet.Force = 10
- bullet.Damage = 0
- bullet.Callback = function(att,tr,dmginfo)
- if tr.Hit then
- if self.Energy >= 75 then
- sound.Play("ambient/levels/labs/electric_explosion2.wav",tr.HitPos,85,125,0.8)
- else
- sound.Play("ambient/levels/labs/electric_explosion2.wav",tr.HitPos,75,155,0.7)
- end
- if SERVER then
- for _, ent in ipairs(ents.FindInSphere(tr.HitPos,145)) do
- if IsValid(ent) then
- if ent != self:GetOwner() then
- local dmg = DamageInfo()
- dmg:SetDamage(dmginfo:GetDamage())
- dmg:SetAttacker(self:GetOwner())
- dmg:SetInflictor(self)
- ent:TakeDamageInfo(dmg)
- if ent:GetClass() == "combine_mine" then
- ent:Fire("Disarm","",0)
- end
- if ent:GetClass() == "func_tank" or ent:GetClass() == "func_tankmortar" then
- ent:Remove()
- end
- else
- local diff = tr.HitPos:Distance(self:GetOwner():GetPos())
- local ang = (tr.HitPos - self:GetOwner():GetPos()):Angle():Forward()
- if diff < 100 then
- self:GetOwner():SetVelocity(-ang*512)
- end
- end
- end
- end
- end
- local blast = EffectData()
- blast:SetOrigin(tr.HitPos)
- blast:SetScale(5)
- util.Effect("demon_blast_small",blast)
- local col = HSVToColor(RealTime() * 64 % 360, 0.65, 1)
- local impact = EffectData()
- impact:SetOrigin(tr.HitPos)
- impact:SetNormal(tr.HitNormal)
- impact:SetScale(2)
- impact:SetAngles(Angle(col.r,col.g,col.b))
- util.Effect("demon_decal_pulse",impact)
- local blast = EffectData()
- blast:SetOrigin(tr.HitPos)
- blast:SetScale(0.25)
- blast:SetAngles(Angle(col.r,col.g,col.b))
- util.Effect("fx_model_blast",blast)
- end
- end
- self:GetOwner():ViewPunch(Angle(math.Rand(-1,1),math.Rand(-0.5,0.5),0))
- self:GetOwner():FireBullets(bullet)
- end
- function SWEP:PulseBomb()
- self:EmitSound("demon_laserrifle.shootbig")
- self:GetOwner():SetAnimation(PLAYER_ATTACK1)
- self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
- if SERVER then
- local bomb = ents.Create("demon_laserrifle_pulsebomb")
- bomb:SetPos(self:GetOwner():GetShootPos())
- bomb:SetOwner(self:GetOwner())
- bomb:Spawn()
- bomb.Energy = self.Energy
- local phys = bomb:GetPhysicsObject()
- if IsValid(phys) then
- phys:SetVelocity(self:GetOwner():GetAimVector()*2048)
- end
- end
- self:GetOwner():ViewPunch(Angle(math.Rand(-1,1),math.Rand(-0.5,0.5),0))
- end
- function SWEP:ShockBlast()
- self:EmitSound("demon_laserrifle.shootbig")
- self:GetOwner():SetAnimation(PLAYER_ATTACK1)
- self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
- local bullet = {}
- bullet.Num = 5
- bullet.Src = self:GetOwner():GetShootPos()
- bullet.Dir = self:GetOwner():GetAimVector()
- bullet.Spread = Vector(0.1, 0.1, 0)
- bullet.Tracer = 1
- bullet.TracerName = "demon_tracer_laser"
- bullet.Force = 25
- bullet.Damage = 5
- bullet.Callback = function(att,tr,dmginfo)
- if tr.Hit then
- if SERVER then
- for _, ent in ipairs(ents.FindInSphere(tr.HitPos,55)) do
- if IsValid(ent) then
- if ent != self:GetOwner() then
- local dmg = DamageInfo()
- dmg:SetDamage(dmginfo:GetDamage())
- dmg:SetAttacker(self:GetOwner())
- dmg:SetInflictor(self)
- ent:TakeDamageInfo(dmg)
- end
- if self.Energy >= 75 then
- if ent != self:GetOwner() then
- if ent:GetClass() == "combine_mine" then
- ent:Fire("Disarm","",0)
- end
- if ent:GetClass() == "func_tank" then
- ent:Remove()
- end
- else
- local diff = tr.HitPos:Distance(self:GetOwner():GetPos())
- local ang = (tr.HitPos - self:GetOwner():GetPos()):Angle():Forward()
- if diff < 100 then
- self:GetOwner():SetVelocity(-ang*512)
- end
- end
- end
- end
- end
- end
- local scale = 1
- if self.Energy >= 75 then
- scale = 2.5
- if self.SoundDelay < CurTime() then
- sound.Play("ambient/levels/labs/electric_explosion2.wav",tr.HitPos,85,75,0.8)
- self.SoundDelay = CurTime() + 0.1
- end
- else
- if self.SoundDelay < CurTime() then
- sound.Play("ambient/levels/labs/electric_explosion2.wav",tr.HitPos,75,100,0.7)
- self.SoundDelay = CurTime() + 0.1
- end
- end
- local blast = EffectData()
- blast:SetOrigin(tr.HitPos)
- blast:SetScale(scale/2)
- util.Effect("demon_blast_small",blast)
- local col = HSVToColor(RealTime() * 64 % 360, 0.65, 1)
- local impact = EffectData()
- impact:SetOrigin(tr.HitPos)
- impact:SetNormal(tr.HitNormal)
- impact:SetScale(scale/5)
- impact:SetAngles(Angle(col.r,col.g,col.b))
- util.Effect("demon_decal_pulse",impact)
- local blast = EffectData()
- blast:SetOrigin(tr.HitPos)
- blast:SetScale(scale/10)
- blast:SetAngles(Angle(col.r,col.g,col.b))
- util.Effect("fx_model_blast",blast)
- end
- end
- if self.PunchDelay < CurTime() then
- self:GetOwner():ViewPunch(Angle(math.Rand(-1,1),math.Rand(-0.5,0.5),0))
- self.PunchDelay = CurTime() + 0.1
- end
- self:GetOwner():FireBullets(bullet)
- end
- function SWEP:SecondaryAttack()
- if !self:CanAttack(40) then return end
- if self.WeaponMode == "powershot" then
- self:PowerShot()
- end
- if self.WeaponMode == "pulsebomb" then
- self:PulseBomb()
- end
- if self.WeaponMode == "shockblast" then
- self:ShockBlast()
- end
- self.Energy = self.Energy - 40
- self:SetNWInt("Energy",self.Energy)
- self.NextAttack = CurTime()+1
- self:SendDelay(1)
- end
- function SWEP:DoImpactEffect() return true end
- function SWEP:Deploy()
- return true
- end
- function SWEP:Holster()
- return true
- end
- function SWEP:OnRemove()
- end
- --[[-------------------------------------------------------------------------
- Client
- ---------------------------------------------------------------------------]]
- if CLIENT then
- local sights_opacity = CreateConVar("ttt_ironsights_crosshair_opacity", "0.8", FCVAR_ARCHIVE)
- local crosshair_brightness = CreateConVar("ttt_crosshair_brightness", "1.0", FCVAR_ARCHIVE)
- local crosshair_size = CreateConVar("ttt_crosshair_size", "1.0", FCVAR_ARCHIVE)
- local disable_crosshair = CreateConVar("ttt_disable_crosshair", "0", FCVAR_ARCHIVE)
- local enable_color_crosshair = CreateConVar("ttt_crosshair_color_enable", "0", FCVAR_ARCHIVE)
- local crosshair_color_r = CreateConVar("ttt_crosshair_color_r", "30", FCVAR_ARCHIVE)
- local crosshair_color_g = CreateConVar("ttt_crosshair_color_g", "160", FCVAR_ARCHIVE)
- local crosshair_color_b = CreateConVar("ttt_crosshair_color_b", "160", FCVAR_ARCHIVE)
- local enable_gap_crosshair = CreateConVar("ttt_crosshair_gap_enable", "0", FCVAR_ARCHIVE)
- local crosshair_gap = CreateConVar("ttt_crosshair_gap", "0", FCVAR_ARCHIVE)
- local crosshair_opacity = CreateConVar("ttt_crosshair_opacity", "1", FCVAR_ARCHIVE)
- local crosshair_static = CreateConVar("ttt_crosshair_static", "0", FCVAR_ARCHIVE)
- local crosshair_weaponscale = CreateConVar("ttt_crosshair_weaponscale", "1", FCVAR_ARCHIVE)
- local crosshair_thickness = CreateConVar("ttt_crosshair_thickness", "1", FCVAR_ARCHIVE)
- local crosshair_outlinethickness = CreateConVar("ttt_crosshair_outlinethickness", "0", FCVAR_ARCHIVE)
- local enable_dot_crosshair = CreateConVar("ttt_crosshair_dot", "0", FCVAR_ARCHIVE)
- function SWEP:DrawHUD()
- if self.HUDHelp then
- self:DrawHelp()
- end
- local client = LocalPlayer()
- if disable_crosshair:GetBool() or not IsValid(client) then return end
- local sights = not self.NoSights and self:GetIronsights()
- local x = math.floor(ScrW() * 0.5)
- local y = math.floor(ScrH() * 0.5)
- local scale = crosshair_weaponscale:GetBool() and math.max(0.2, 1.5 * self:GetPrimaryCone()) or 1
- local timescale = 1
- if not crosshair_static:GetBool() then
- timescale = (2 - math.Clamp((CurTime() - self:LastShootTime()) * 5, 0.0, 1.0))
- end
- local alpha = sights and sights_opacity:GetFloat() or crosshair_opacity:GetFloat()
- local bright = crosshair_brightness:GetFloat() or 1
- local gap = enable_gap_crosshair:GetBool() and math.floor(timescale * crosshair_gap:GetFloat()) or math.floor(20 * scale * timescale * (sights and 0.8 or 1))
- local thickness = crosshair_thickness:GetFloat()
- local outline = math.floor(crosshair_outlinethickness:GetFloat())
- local length = math.floor(gap + 25 * crosshair_size:GetFloat() * scale * timescale)
- local offset = thickness * 0.5
- if outline > 0 then
- surface.SetDrawColor(0, 0, 0, 255 * alpha)
- surface.DrawRect(x - length - outline, y - offset - outline, length - gap + outline * 2, thickness + outline * 2)
- surface.DrawRect(x + gap - outline, y - offset - outline, length - gap + outline * 2, thickness + outline * 2)
- surface.DrawRect(x - offset - outline, y - length - outline, thickness + outline * 2, length - gap + outline * 2)
- surface.DrawRect(x - offset - outline, y + gap - outline, thickness + outline * 2, length - gap + outline * 2)
- end
- if enable_color_crosshair:GetBool() then
- surface.SetDrawColor(crosshair_color_r:GetInt() * bright, crosshair_color_g:GetInt() * bright, crosshair_color_b:GetInt() * bright, 255 * alpha)
- else
- -- somehow it seems this can be called before my player metatable
- -- additions have loaded
- if client.GetSubRoleData then
- local col = client:GetRoleColor()
- surface.SetDrawColor(col.r * bright, col.g * bright, col.b * bright, 255 * alpha)
- else
- surface.SetDrawColor(0, 255 * bright, 0, 255 * alpha)
- end
- end
- -- draw crosshair dot
- if enable_dot_crosshair:GetBool() then
- surface.DrawRect(x - thickness * 0.5, y - thickness * 0.5, thickness, thickness)
- end
- surface.DrawRect(x - length, y - offset, length - gap, thickness)
- surface.DrawRect(x + gap, y - offset, length - gap, thickness)
- surface.DrawRect(x - offset, y - length, thickness, length - gap)
- surface.DrawRect(x - offset, y + gap, thickness, length - gap)
- local energy = self:GetNWInt("Energy")
- local energytext = ""
- if energy > 0 then
- if energy < 10 then
- energytext = "Мало энергии"
- end
- energytext = "Энергия: "..energy
- else
- energytext = "Нет энергии"
- end
- local x,y = ScrW()-12,ScrH()-64
- local energyval = math.Clamp((energy*2),16,200)
- surface.SetDrawColor(Color(155,155,255,215))
- surface.DrawRect(x-energyval,y,energyval-16,34)
- surface.SetDrawColor(Color(0,0,0,215))
- surface.DrawOutlinedRect(x-energyval,y,energyval-16,34)
- draw.SimpleTextOutlined(
- energytext,
- "DermaLarge",
- ScrW()-32,
- ScrH()-32,
- Color(215,235,255,225),
- TEXT_ALIGN_RIGHT,
- TEXT_ALIGN_BOTTOM,
- 2,
- Color(0,0,0,215)
- )
- local col = Color(255,255,255,255)
- local powershot = weaponmodes[self.WeaponMode]
- if energy >= 15 then
- if energy >= 75 then
- col = HSVToColor(RealTime() * 32 % 360, 0.8, 1)
- powershot = "Super "..powershot
- end
- else
- col = Color(255,255,255,55)
- end
- draw.SimpleTextOutlined(
- "Пкм: "..powershot,
- "Trebuchet18",
- ScrW()-32,
- ScrH()-68,
- col,
- TEXT_ALIGN_RIGHT,
- TEXT_ALIGN_BOTTOM,
- 2,
- Color(0,0,0,215)
- )
- local col = Color(255,255,255,255)
- if energy <= 0 then
- col = Color(255,255,255,55)
- end
- draw.SimpleTextOutlined(
- "ЛКМ: стреляй",
- "Trebuchet18",
- ScrW()-32,
- ScrH()-84,
- col,
- TEXT_ALIGN_RIGHT,
- TEXT_ALIGN_BOTTOM,
- 2,
- Color(0,0,0,215)
- )
- if self.NextAttack > CurTime() then
- local amt = CurTime()-self.NextAttack
- end
- draw.SimpleTextOutlined(
- "R: режим меняй",
- "Trebuchet18",
- ScrW()-32,
- ScrH()-100,
- Color(255,255,255,115),
- TEXT_ALIGN_RIGHT,
- TEXT_ALIGN_BOTTOM,
- 2,
- Color(0,0,0,115)
- )
- end
- local GetPTranslation = LANG.GetParamTranslation
- -- Many non-gun weapons benefit from some help
- local help_spec = {text = "", font = "TabLarge", xalign = TEXT_ALIGN_CENTER}
- function SWEP:DrawHelp()
- local data = self.HUDHelp
- local translate = data.translatable
- local primary = data.primary
- local secondary = data.secondary
- if translate then
- primary = primary and GetPTranslation(primary, data.translate_params)
- secondary = secondary and GetPTranslation(secondary, data.translate_params)
- end
- help_spec.pos = {ScrW() * 0.5, ScrH() - 40}
- help_spec.text = secondary or primary
- draw.TextShadow(help_spec, 2)
- -- if no secondary exists, primary is drawn at the bottom and no top line
- -- is drawn
- if secondary then
- help_spec.pos[2] = ScrH() - 60
- help_spec.text = primary
- draw.TextShadow(help_spec, 2)
- end
- end
- -- mousebuttons are enough for most weapons
- local default_key_params = {
- primaryfire = Key("+attack", "LEFT MOUSE"),
- secondaryfire = Key("+attack2", "RIGHT MOUSE"),
- usekey = Key("+use", "USE")
- }
- function SWEP:AddHUDHelp(primary_text, secondary_text, translate, extra_params)
- extra_params = extra_params or {}
- self.HUDHelp = {
- primary = primary_text,
- secondary = secondary_text,
- translatable = translate,
- translate_params = table.Merge(extra_params, default_key_params)
- }
- end
- end
- --[[-------------------------------------------------------------------------
- Sounds
- ---------------------------------------------------------------------------]]
- sound.Add({
- name = "demon_laserrifle.shoot",
- channel = CHAN_STATIC,
- volume = 0.3,
- level = 55,
- pitch = {125,135},
- sound = "weapons/airboat/airboat_gun_energy1.wav"
- })
- sound.Add({
- name = "demon_laserrifle.shootbig",
- channel = CHAN_STATIC,
- volume = 0.4,
- level = 65,
- pitch = {110,120},
- sound = "weapons/physcannon/energy_disintegrate4.wav"
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement