Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local FailDist = 300 //How far can the Tazer "Bullets" go? The more, the further it will go.
- if ( SERVER ) then
- AddCSLuaFile( "shared.lua" )
- SWEP.Weight = 2
- SWEP.AutoSwitchTo = true
- SWEP.AutoSwitchFrom = true
- SWEP.HoldType = "pistol"
- SWEP.Category = "X-Ray Gaming"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.AdminOnly = false //Is the Weapon for Admins only? false = All People can use it ; true = Only Admins can use it.
- end
- if ( CLIENT ) then
- SWEP.PrintName = "Taser";
- SWEP.Slot = 2;
- SWEP.SlotPos = 1;
- SWEP.DrawAmmo = false;
- SWEP.DrawCrosshair = true;
- SWEP.Category = "X-Ray Gaming"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.AdminOnly = false //Is the Weapon for Admins only? false = All People can use it ; true = Only Admins can use it.
- end
- SWEP.Contact = "";
- SWEP.Purpose = "Tasing people who is a treat";
- SWEP.Instructions = "Left Click = Taser someone ; Right Click = Tazer them once on the ground.";
- SWEP.ViewModel = "models/weapons/cg_ocrp2/v_taser.mdl"
- SWEP.WorldModel = "models/weapons/cg_ocrp2/w_taser.mdl"
- SWEP.UseHands = false
- SWEP.ViewModelFOV = 70
- SWEP.HoldType = "pistol"
- SWEP.SwayScale = .25
- SWEP.Primary.ClipSize = 1
- SWEP.Primary.DefaultClip = 20
- SWEP.Primary.Automatic = false
- SWEP.Primary.Ammo = "Pistol"
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = true
- SWEP.Secondary.Ammo = ""
- local taseredrags = {}
- local taseruniquetimer1 = 0
- function SWEP:Reload()
- self.Weapon:DefaultReload( ACT_VM_RELOAD )
- end
- function SWEP:PrimaryAttack()
- if ( !self:CanPrimaryAttack() ) then return end
- local eyetrace = self.Owner:GetEyeTrace();
- if !eyetrace.Entity:IsPlayer() then
- if !eyetrace.Entity:IsNPC() then return end
- end
- self.Weapon:EmitSound( "weapons/crossbow/bolt_fly4.wav")
- self.BaseClass.ShootEffects( self )
- self:TakePrimaryAmmo(1)
- self:SetNextPrimaryFire(5)
- if (!SERVER) then return end
- if eyetrace.Entity:IsPlayer() then
- if self.Owner:GetPos():Distance(eyetrace.Entity:GetPos()) < FailDist then
- self.Owner:ChatPrint("The player has been tased")
- self:tasePlayer(eyetrace.Entity)
- self.Owner:ConCommand( "say /me slots a new battery into his stun gun. It takes 3 seconds to charge.")
- else
- self.Owner:ConCommand( "say /me slots a new battery into his stun gun. It takes 3 seconds to charge.")
- timer.Simple( 3, function()
- self.Owner:RemoveAmmo( 100, "GaussEnergy" )
- self:SetClip1( 100, "GaussEnergy" )
- self.Weapon:EmitSound( "items/battery_pickup.wav" )
- self._ReloadBugFix = 0
- end);
- return
- end
- end
- if eyetrace.Entity:IsNPC() then
- if self.Owner:GetPos():Distance(eyetrace.Entity:GetPos()) < FailDist then
- self.Owner:ConCommand( "say /me slots a new battery into his stun gun. It takes 3 seconds to charge.")
- timer.Simple( 3, function()
- self.Owner:RemoveAmmo( 100, "GaussEnergy" )
- self:SetClip1( 100, "GaussEnergy" )
- self.Weapon:EmitSound( "items/battery_pickup.wav" )
- self._ReloadBugFix = 0
- end);
- self:taseNPC(eyetrace.Entity, self.Owner)
- else
- self.Owner:ChatPrint("The player is too far away!" )
- return
- end
- end
- end
- function SWEP:tasePlayer(ply)
- local rag = ents.Create( "prop_ragdoll" )
- if not rag:IsValid() then return end
- rag:SetModel( ply:GetModel() )
- rag:SetKeyValue( "origin", ply:GetPos().x .. " " .. ply:GetPos().y .. " " .. ply:GetPos().z )
- rag:SetAngles(ply:GetAngles())
- rag.taseredply = ply
- table.insert(taseredrags, rag)
- ply:StripWeapons()
- ply:DrawViewModel(false)
- ply:DrawWorldModel(false)
- ply:Spectate(OBS_MODE_CHASE)
- ply:SpectateEntity(rag)
- rag:Spawn()
- rag:Activate()
- rag:GetPhysicsObject():SetVelocity(4*ply:GetVelocity())
- self:setrevivedelay(rag)
- end
- function SWEP:taseNPC(npc, npcShooter)
- local skin = npc:GetSkin()
- local wep = ""
- local possibleWep = ents.FindInSphere(npc:GetPos(),0.01)
- for k, v in pairs(possibleWep) do
- if string.find(v:GetClass(),"weapon_") == 1 then
- wep = v:GetClass()
- end
- end
- local citType = ""
- local citMed = 0
- if npc:GetClass() == "npc_citizen" then
- citType = string.sub(npc:GetModel(),21,21)
- if string.sub(npc:GetModel(),22,22) == "m" then citMed = 1 end
- end
- local rag = ents.Create( "prop_ragdoll" )
- if not rag:IsValid() then return end
- rag:SetModel( npc:GetModel() )
- rag:SetKeyValue( "origin", npc:GetPos().x .. " " .. npc:GetPos().y .. " " .. npc:GetPos().z )
- rag:SetAngles(npc:GetAngles())
- rag.tasewasNPC = true
- rag.tasenpcType = npc:GetClass()
- rag.tasenpcWep = wep
- rag.tasenpcCitType = citType
- rag.tasenpcCitMed = citMed
- rag.tasenpcSkin = skin
- rag.tasenpcShooter = npcShooter
- table.insert(taseredrags, rag)
- rag:Spawn()
- rag:Activate()
- rag:GetPhysicsObject():SetVelocity(8*npc:GetVelocity())
- npc:Remove()
- self:setrevivedelay(rag)
- end
- function SWEP:setrevivedelay(rag)
- if taseruniquetimer1 > 30 then
- taseruniquetimer1 = 0
- end
- taseruniquetimer1 = taseruniquetimer1 + 1
- // Wanna set the Taser Time? Change the "7" below this line to any number you want. 7 = 7 Seconds.
- timer.Create("revivedelay"..taseruniquetimer1, 15, 1, function() self:taserevive(rag) end)
- end
- function SWEP:taserevive(ent)
- if !ent then return end
- if ent.taseredply then
- if ( !ent.taseredply:IsValid() ) then return end
- local phy = ent:GetPhysicsObject()
- phy:EnableMotion(false)
- ent:SetSolid(SOLID_NONE)
- ent.taseredply:DrawViewModel(true)
- ent.taseredply:DrawWorldModel(true)
- ent.taseredply:Spawn()
- ent.taseredply:SetPos(ent:GetPos())
- ent.taseredply:SetVelocity(ent:GetPhysicsObject():GetVelocity())
- elseif ent.tasewasNPC then
- local npc = ents.Create(ent.tasenpcType)
- util.PrecacheModel(ent:GetModel())
- npc:SetModel(ent:GetModel())
- local spawnPos = ent:GetPos()+Vector(0,0,0)
- npc:SetPos(spawnPos)
- npc:SetSkin(ent.tasenpcSkin)
- npc:SetAngles(Angle(0,ent:GetAngles().y,0))
- //if ent.tasenpcWep != "" then
- //npc:SetKeyValue("additionalequipment",ent.tasenpcWep)
- //end
- if ent.taseentType == "npc_citizen" then
- npc:SetKeyValue("citizentype",ent.tasenpcCitType)
- if ent.tasenpcCitType == "3" && ent.tasenpcCitMed==1 then
- npc:SetKeyValue("spawnflags","131072")
- end
- end
- npc:Spawn()
- npc:Activate()
- cleanup.Add (uplayer, "NPC", npc);
- undo.Create ("Tasered NPC");
- undo.AddEntity (npc);
- undo.SetPlayer (ent.tasenpcShooter);
- undo.Finish();
- else
- return
- end
- for k, v in pairs(taseredrags) do
- if v == ent then
- table.remove( taseredrags, k )
- end
- end
- ent:Remove()
- end
- function SWEP:SecondaryAttack()
- if table.Count( taseredrags ) == 0 then return end
- self.Owner:EmitSound( "Weapon_Pistol.Empty")
- self.Owner:EmitSound( "Weapon_Shotgun.Empty")
- if (!SERVER) then return end
- for k, v in pairs(taseredrags) do
- local shock1 = math.random(-1200, 1200 )
- local shock2 = math.random(-1200, 1200 )
- local shock3 = math.random(-1200, 1200 )
- v:GetPhysicsObject():ApplyForceCenter( Vector( shock1, shock2, shock3 ) )
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement