Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.06 KB | None | 0 0
  1.  
  2. if SERVER then
  3.  
  4.     AddCSLuaFile("shared.lua")
  5.    
  6. end
  7.  
  8. if CLIENT then
  9.  
  10.     SWEP.PrintName          = "Mjolnir"        
  11.     SWEP.Author             = "Upset"
  12.     SWEP.Slot               = 5
  13.     SWEP.SlotPos            = 0
  14.     SWEP.WepSelectIcon      = surface.GetTextureID("weapons/mjol_icon")
  15.     SWEP.ViewModelFOV       = 90
  16.    
  17.     killicon.Add("weapon_q1_mjolnir", "weapons/mjol_icon", Color(255, 80, 0, 255))
  18.    
  19. end
  20.  
  21. function SWEP:PrimaryAttack()
  22.     if self.Owner:GetAmmoCount(self.Primary.Ammo) >= 15 then
  23.         self:SetNextPrimaryFire(CurTime() + self.Primary.ZapDelay)
  24.         self:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
  25.         self.Owner:SetAnimation(PLAYER_ATTACK1)
  26.         if SERVER then self.Owner:EmitSound(self.Primary.Sound) end
  27.         self.attackdelay = CurTime() +.5
  28.         self.cantholster = CurTime() +.6
  29.         self:SuperDamageSound()
  30.     else
  31.         self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
  32.         self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
  33.         self.Owner:SetAnimation(PLAYER_ATTACK1)
  34.         if SERVER then self.Owner:EmitSound(self.Primary.Sound) end
  35.         self.attackdelay = CurTime() +.2
  36.         self.cantholster = CurTime() +.5
  37.         self:SuperDamageSound()
  38.     end
  39. end
  40.  
  41. function SWEP:SpecialThink()
  42.     if self.attackdelay and CurTime() > self.attackdelay then
  43.         self.attackdelay = nil
  44.         if self.Owner:GetAmmoCount(self.Primary.Ammo) >= 15 then
  45.             self:Mjolnir()
  46.         else
  47.             self:Melee()
  48.         end
  49.     end
  50. end
  51.  
  52. function SWEP:Melee()
  53.     if SERVER then self.Owner:LagCompensation(true) end
  54.     local tr = util.TraceLine({
  55.     start = self.Owner:GetShootPos(),
  56.     endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.MeleeHitDist,
  57.     filter = self.Owner
  58.     })
  59.  
  60.     if !IsValid(tr.Entity) then
  61.         tr = util.TraceHull({
  62.         start = self.Owner:GetShootPos(),
  63.         endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.MeleeHitDist,
  64.         filter = self.Owner,
  65.         mins = Vector(-1, -1, -1),
  66.         maxs = Vector(1, 1, 1)
  67.         })
  68.     end
  69.    
  70.     if tr.Hit then
  71.         util.ImpactEffect(tr)
  72.         if CLIENT then return end
  73.         local dmginfo = DamageInfo()
  74.         local attacker = self.Owner
  75.         if (!IsValid(attacker)) then attacker = self end
  76.         dmginfo:SetAttacker(attacker)
  77.         dmginfo:SetInflictor(self)
  78.         dmginfo:SetDamage(self.Primary.DamageMelee)
  79.         dmginfo:SetDamageForce(self.Owner:GetUp() *4000 +self.Owner:GetForward() *15000)
  80.         tr.Entity:TakeDamageInfo(dmginfo)
  81.         self:EmitSound(self.Primary.HitFlesh)
  82.     end
  83.  
  84.     if tr.HitWorld then
  85.         if SERVER then self.Owner:EmitSound(self.Primary.HitMetal) end
  86.     end
  87.     if SERVER then self.Owner:LagCompensation(false) end
  88. end
  89.  
  90. function util.ImpactEffect(tr)
  91.     local e = EffectData()
  92.     e:SetOrigin(tr.HitPos)
  93.     e:SetStart(tr.StartPos)
  94.     e:SetSurfaceProp(tr.SurfaceProps)
  95.     e:SetDamageType(DMG_BULLET)
  96.     e:SetHitBox(tr.HitBox)
  97.     if CLIENT then
  98.         e:SetEntity(tr.Entity)
  99.     else
  100.         e:SetEntIndex(tr.Entity:EntIndex())
  101.     end
  102.     util.Effect("Impact", e)
  103. end
  104.  
  105. function SWEP:Mjolnir()
  106.  
  107.     if self.Owner:WaterLevel() > 2 then
  108.         self.Owner:Kill()
  109.     end
  110.    
  111.     self:TakeAmmo(15)
  112.     local tr = util.TraceLine({
  113.     start = self.Owner:GetShootPos(),
  114.     endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDist,
  115.     filter = self.Owner
  116.     })
  117.    
  118.     local ents = ents.FindInSphere(tr.StartPos, self.HitDist)
  119.    
  120.     for k,v in pairs(ents) do
  121.         if IsValid(v) and (v:IsPlayer() or v:IsNPC() or v:Health() > 0) and v != self:GetOwner() then
  122.             if v:IsPlayer() and !v:Alive() then return end
  123.             local dmginfo = DamageInfo()
  124.             dmginfo:SetDamage(self.Primary.Damage)
  125.             dmginfo:SetDamageType(DMG_ENERGYBEAM)
  126.             dmginfo:SetAttacker(self.Owner)
  127.             dmginfo:SetInflictor(self)
  128.             v:TakeDamageInfo(dmginfo)
  129.         end
  130.     end
  131.    
  132.     self.Owner:EmitSound(self.Primary.Zap)
  133.     self:SetNWBool("DrawBeam", true)
  134.     self:DoLightningEffect(tr)
  135.     self:DoLightningEffect(tr)
  136.     timer.Simple(.05, function()
  137.         self:DoLightningEffect(tr)
  138.     end)
  139.     timer.Simple(.1, function()
  140.         self:DoLightningEffect(tr)
  141.     end)
  142.     timer.Simple(.15, function()
  143.         self:DoLightningEffect(tr)
  144.     end)
  145.     timer.Simple(.2, function()
  146.         self:DoLightningEffect(tr)
  147.     end)
  148.     timer.Simple(.25, function()
  149.         self:DoLightningEffect(tr)
  150.     end)
  151.     timer.Simple(.3, function()
  152.         self:DoLightningEffect(tr)
  153.     end)
  154.     timer.Simple(.35, function()
  155.         self:DoLightningEffect(tr)
  156.     end)
  157.     timer.Simple(.4, function()
  158.         self:DoLightningEffect(tr)
  159.     end)
  160.     timer.Simple(.45, function()
  161.         self:DoLightningEffect(tr)
  162.     end)
  163.     timer.Simple(.5, function()
  164.         self:DoLightningEffect(tr)
  165.         self:SetNWBool("DrawBeam", false)
  166.     end)
  167. end
  168.  
  169. function SWEP:DoLightningEffect(tr)
  170.     local pos = self.Owner:GetShootPos()
  171.     local ang = self.Owner:GetAimVector():Angle()
  172.     pos = pos +ang:Up() *-20
  173.     if IsFirstTimePredicted then
  174.         local beameffect = EffectData()
  175.         beameffect:SetEntity(self)
  176.         beameffect:SetStart(pos)
  177.         beameffect:SetOrigin(tr.HitPos + ang:Right() *math.Rand(-128,128))
  178.         util.Effect("q1_mjolnir_lightning", beameffect)
  179.     end
  180. end
  181.  
  182. local lightning = Material("sprites/q1lightning")
  183.  
  184. function SWEP:ViewModelDrawn()
  185.     if !self:GetNWBool("DrawBeam") then return end
  186.     local pos = self.Owner:GetShootPos()
  187.     local ang = self.Owner:GetAimVector():Angle()
  188.     pos = pos +ang:Up() *-20
  189.  
  190.     local ents = ents.FindInSphere(pos, self.HitDist)
  191.    
  192.     for k,v in pairs(ents) do
  193.         if IsValid(v) and (v:IsPlayer() or v:IsNPC() or v:Health() > 0) and v != self:GetOwner() then
  194.             if v:IsPlayer() and !v:Alive() then return end
  195.             local endpos = v:GetPos() + ((v:OBBMins() + v:OBBMaxs()) *.5)
  196.             local rot = CurTime()
  197.             render.SetMaterial(lightning)
  198.             render.DrawBeam(pos, endpos, 10, rot, rot -1, Color(255, 255, 255, 255))
  199.             render.DrawBeam(pos, endpos, 20, rot, rot -2, Color(255, 255, 255, 255))
  200.             self:SetRenderBoundsWS(pos, endpos)
  201.         end
  202.     end
  203. end
  204.  
  205. function SWEP:DrawWorldModel()
  206.     self:DrawModel()
  207.    
  208.     if !self:GetNWBool("DrawBeam") then return end
  209.     local pos = self.Owner:GetShootPos()
  210.     local ang = self.Owner:GetAimVector():Angle()
  211.     pos = pos +ang:Up() *-20 +ang:Forward() *20
  212.  
  213.     local ents = ents.FindInSphere(pos, self.HitDist)
  214.    
  215.     for k,v in pairs(ents) do
  216.         if IsValid(v) and (v:IsPlayer() or v:IsNPC() or v:Health() > 0) and v != self:GetOwner() then
  217.             if v:IsPlayer() and !v:Alive() then return end
  218.             local endpos = v:GetPos() + ((v:OBBMins() + v:OBBMaxs()) *.5)
  219.             local rot = CurTime()
  220.             render.SetMaterial(lightning)
  221.             render.DrawBeam(pos, endpos, 10, rot, rot -1, Color(255, 255, 255, 255))
  222.             render.DrawBeam(pos, endpos, 20, rot, rot -2, Color(255, 255, 255, 255))
  223.             self:SetRenderBoundsWS(pos, endpos)
  224.         end
  225.     end
  226. end
  227.  
  228. SWEP.HoldType           = "melee"
  229. SWEP.Base               = "weapon_q1_base"
  230. SWEP.Category           = "Quake 1"
  231.  
  232. SWEP.Spawnable          = true
  233.  
  234. SWEP.ViewModel          = "models/weapons/v_q1_mjolnir.mdl"
  235. SWEP.WorldModel         = "models/weapons/w_q1_mjolnir.mdl"
  236.  
  237. SWEP.Primary.Sound          = Sound("weapons/q1/ax1.wav")
  238. SWEP.Primary.Zap            = Sound("weapons/hipweap/mjolhit.wav")
  239. SWEP.Primary.HitMetal       = Sound("weapons/hipweap/mjoltink.wav")
  240. SWEP.Primary.HitFlesh       = Sound("weapons/hipweap/mjolslap.wav")
  241. SWEP.Primary.Damage         = 30
  242. SWEP.Primary.DamageMelee    = 25
  243. SWEP.Primary.ClipSize       = -1
  244. SWEP.Primary.Delay          = 1.1
  245. SWEP.Primary.ZapDelay       = 1.5
  246. SWEP.Primary.DefaultClip    = 20
  247. SWEP.Primary.Automatic      = true
  248. SWEP.Primary.Ammo           = "Q1Cells"
  249.  
  250. SWEP.HitDist                = 256
  251. SWEP.MeleeHitDist           = 80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement