Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SWEP:PrimaryAttack()
- if self.Weapon:Clip1() <= 0 then self:EmitSound("common/wpn_denyselect.wav") return end
- local tr = self.Owner:GetEyeTrace()
- local target = tr.Entity
- if (tr.HitPos - self.Owner:GetShootPos()):Length() < 100 then
- local chancestun = math.random(1,20)
- if (string.find(tr.Entity:GetClass(), "npc_strider")
- -- There are all classes,who cant stun.
- or string.find(tr.Entity:GetClass(), "npc_helicopter")
- or string.find(tr.Entity:GetClass(), "npc_combinegunship")
- or string.find(tr.Entity:GetClass(), "npc_combinedropship")
- or string.find(tr.Entity:GetClass(), "npc_turret_floor")
- or string.find(tr.Entity:GetClass(), "npc_turret_ceiling")
- or string.find(tr.Entity:GetClass(), "npc_turret_ground")
- or string.find(tr.Entity:GetClass(), "npc_clawscanner")
- or string.find(tr.Entity:GetClass(), "npc_cscanner")
- or string.find(tr.Entity:GetClass(), "npc_manhack")
- or string.find(tr.Entity:GetClass(), "npc_barnacle")) then
- self:EmitSound(Sound(self.Primary.Sound))
- else
- if SERVER and tr.Entity:IsNPC() and IsValid(tr.Entity) and
- MyChanceStun(chancestun) then
- self:EmitSound("weapons/stunstick/stunstick_fleshhit" .. math.random(1,2) .. ".wav")
- -- This is all vars,what we need.
- if target:GetActiveWeapon():IsValid() and IsValid(target:GetActiveWeapon()) then
- weaponnpc = target:GetActiveWeapon():GetClass()
- weaponmodel = target:GetActiveWeapon():GetModel()
- else
- weaponnpc = nil
- weaponmodel = nil
- end
- npcskin = target:GetSkin()
- npcclass = target:GetClass()
- npchealth = target:Health()
- npcangle = target:GetAngles()
- npcmodel = target:GetModel()
- npcmaterial = target:GetMaterial()
- npcname = target:GetName()
- npccolor = target:GetColor()
- -- Spawning stunning ragdoll.Lol :D
- local rag = ents.Create("prop_ragdoll")
- rag:SetModel(npcmodel)
- rag:SetSkin(npcskin)
- rag:SetMaterial(npcmaterial)
- rag:SetPos(target:GetPos())
- rag:Spawn()
- rag:GetTable().ang = npcangle
- rag:SetNWString("NpcClass",npcclass)
- rag:SetColor(Color(npccolor.r,npccolor.g,npccolor.b,npccolor.a))
- rag:SetNWString("NpcName",npcname)
- rag:SetName(rag:GetNWString("NpcName"))
- rag:SetNWInt("Health",npchealth)
- rag:SetNWInt("Takedamages",0)
- rag:SetNWBool("IsStunedNPC",true)
- if !(weaponnpc == nil) then
- rag:SetNWString("WeaponNpc",weaponnpc)
- end
- for i = 0,32 do
- rag:SetBodygroup(i,target:GetBodygroup(i))
- end
- for i = 0, rag:GetPhysicsObjectCount( ) do
- local physobj = rag:GetPhysicsObjectNum( i )
- if (physobj) and IsValid(physobj)then
- local pos, ang = target:GetBonePosition( target:TranslatePhysBoneToBone( i ) )
- physobj:SetPos(pos)
- physobj:SetAngles(ang)
- physobj:EnableMotion(false)
- end
- end
- if weaponmodel != nil then
- local wep = ents.Create("cycler")
- wep:SetModel( weaponmodel )
- wep:SetParent(rag)
- wep:AddEffects( EF_BONEMERGE )
- wep:Spawn()
- end
- target:Remove()
- timer.Simple(ststuntimecvar:GetFloat(),function() if IsValid(rag) then
- -- Spawning our npc.
- local npc = ents.Create(rag:GetNWString("NpcClass"))
- if !(rag:GetTable().ang == nil) then
- npc:SetAngles(rag:GetTable().ang)
- else
- npc:SetAngles(Angle(0,0,0))
- end
- npc:SetPos(rag:GetPos())
- -- So,npc cant use player weapons.
- if !(rag:GetNWString("WeaponNpc") == nil) then
- if rag:GetNWString("WeaponNpc") == "weapon_smg1" then
- npc:SetKeyValue("additionalequipment","ai_weapon_smg1")
- elseif rag:GetNWString("WeaponNpc") == "weapon_357" then
- npc:SetKeyValue("additionalequipment","ai_weapon_357")
- elseif rag:GetNWString("WeaponNpc") == "weapon_crossbow" then
- npc:SetKeyValue("additionalequipment","ai_weapon_crossbow")
- elseif rag:GetNWString("WeaponNpc") == "weapon_crowbar" then
- npc:SetKeyValue("additionalequipment","ai_weapon_crowbar")
- elseif rag:GetNWString("WeaponNpc") == "weapon_rpg" then
- npc:SetKeyValue("additionalequipment","ai_weapon_rpg")
- elseif rag:GetNWString("WeaponNpc") == "weapon_stunstick" then
- npc:SetKeyValue("additionalequipment","ai_weapon_stunstick")
- elseif rag:GetNWString("WeaponNpc") == "weapon_pistol" then
- npc:SetKeyValue("additionalequipment","ai_weapon_pistol")
- elseif rag:GetNWString("WeaponNpc") == "ai_weapon_shotgun" then
- npc:SetKeyValue("additionalequipment","ai_weapon_shotgun")
- elseif rag:GetNWString("WeaponNpc") == "weapon_ar2" then
- npc:SetKeyValue("additionalequipment","ai_weapon_ar2")
- else
- npc:SetKeyValue("additionalequipment",rag:GetNWString("WeaponNpc"))
- end
- end
- npc:SetSkin(rag:GetSkin())
- npc:Activate()
- npc:Spawn()
- npc:SetModel(rag:GetModel())
- npc:SetMaterial(rag:GetMaterial())
- npc:SetColor(Color(rag:GetColor().r,rag:GetColor().g,rag:GetColor().b,rag:GetColor().a))
- npc:SetName(rag:GetNWString("NpcName"))
- npc:SetHealth(rag:GetNWInt("Health"))
- for i = 0,32 do
- npc:SetBodygroup(i,rag:GetBodygroup(i))
- end
- rag:Remove()
- end
- end)
- elseif SERVER and tr.Entity:IsNPC() and IsValid(tr.Entity) and
- MyChanceShock(chancestun) then
- self:EmitSound("weapons/stunstick/stunstick_fleshhit" .. math.random(1,2) .. ".wav")
- -- This is all vars,what we need.
- if target:GetActiveWeapon():IsValid() and IsValid(target:GetActiveWeapon()) then
- weaponnpc2 = target:GetActiveWeapon():GetClass()
- weaponmodel2 = target:GetActiveWeapon():GetModel()
- else
- weaponnpc2 = nil
- weaponmodel2 = nil
- end
- npcskin2 = target:GetSkin()
- npcclass2 = target:GetClass()
- npchealth2 = target:Health()
- npcangle2 = target:GetAngles()
- npcmodel2 = target:GetModel()
- npcmaterial2 = target:GetMaterial()
- npcname2 = target:GetName()
- npccolor2 = target:GetColor()
- local rag2 = ents.Create("prop_ragdoll")
- rag2:SetModel(npcmodel2)
- rag2:SetSkin(npcskin2)
- rag2:SetMaterial(npcmaterial2)
- rag2:SetPos(target:GetPos())
- rag2:SetColor(Color(npccolor2.r,npccolor2.g,npccolor2.b,npccolor2.a))
- rag2:Spawn()
- rag2:SetNWString("NpcClass2",npcclass2)
- rag2:SetNWString("NpcName2",npcname2)
- rag2:SetName(rag2:GetNWString("NpcName2"))
- rag2:GetTable().ang2 = npcangle
- rag2:SetNWBool("IsStunedNPC2",true)
- rag2:SetNWBool("NotAlivenpc",false)
- rag2:SetNWInt("Takedamages2",0)
- rag2:SetNWInt("Health2",npchealth2)
- if !(weaponnpc2 == nil) then
- rag2:SetNWString("WeaponNpc2",weaponnpc2)
- end
- for i = 0,32 do
- rag2:SetBodygroup(i,target:GetBodygroup(i))
- end
- for i = 0, rag2:GetPhysicsObjectCount( ) do
- local physobj = rag2:GetPhysicsObjectNum( i )
- if (physobj) and IsValid(physobj)then
- local pos, ang = target:GetBonePosition( target:TranslatePhysBoneToBone( i ) )
- physobj:SetPos(pos)
- physobj:SetAngles(ang)
- physobj:EnableMotion(true)
- physobj:ApplyForceCenter((target:GetPos() - self.Owner:GetPos())*20)
- end
- end
- if weaponmodel2 != nil then
- local wep2 = ents.Create("cycler")
- wep2:SetModel( weaponmodel2 )
- wep2:SetParent(rag2)
- wep2:AddEffects( EF_BONEMERGE )
- wep2:Spawn()
- end
- target:Remove()
- timer.Create( "shockstunrag" .. rag2:EntIndex(),0.2,(stshocktimecvar:GetFloat()*10)/2,function()
- if IsValid(rag2) then
- local PhysObj = rag2:GetPhysicsObject()
- local mass = PhysObj:GetMass()
- PhysObj:ApplyForceOffset((mass * 4 * Vector(math.Rand(-13.5, 15.2), math.Rand(-13.5, 15.2), math.Rand(13.5, 20.2))), (PhysObj:GetPos() + Vector(math.Rand(-82, 82), math.Rand(-82, 82), math.Rand(-82, 82))))
- if stshockeffectencvar:GetBool() then
- local effectdata = EffectData()
- effectdata:SetOrigin( rag2:GetPos() )
- effectdata:SetStart( rag2:GetPos() )
- effectdata:SetMagnitude(15)
- effectdata:SetEntity( rag2 )
- util.Effect( "TeslaHitBoxes", effectdata)
- local light = ents.Create("light_dynamic")
- light:SetPos( rag2:GetPos() )
- light:Spawn()
- light:SetKeyValue("_light","235 235 255")
- light:SetKeyValue("distance",120)
- light:SetParent( rag2 )
- light:Fire("kill","",0.1)
- end
- rag2:EmitSound("Town.d1_town_01_LoudSpark")
- end
- end)
- timer.Simple(stshocktimecvar:GetFloat() + stragdolltimecvar:GetFloat(),function()
- if SERVER and IsValid(rag2) and rag2:GetNWBool("NotAlivenpc") == true then
- rag2:Fire( "FadeAndRemove", "", 0.4)
- end
- end)
- timer.Simple(stshocktimecvar:GetFloat(),function() if IsValid(rag2) and !(rag2:GetNWBool("NotAlivenpc") == true) then
- -- Spawning our npc.
- local npc = ents.Create(rag2:GetNWString("NpcClass2"))
- if !(rag2:GetTable().ang2 == nil) then
- npc:SetAngles(rag2:GetTable().ang2)
- else
- npc:SetAngles(Angle(0,0,0))
- end
- npc:SetPos(rag2:GetPos())
- -- So,npc cant use player weapons.
- if !(rag2:GetNWString("WeaponNpc2") == nil) then
- if rag2:GetNWString("WeaponNpc2") == "weapon_smg1" then
- npc:SetKeyValue("additionalequipment","ai_weapon_smg1")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_357" then
- npc:SetKeyValue("additionalequipment","ai_weapon_357")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_crossbow" then
- npc:SetKeyValue("additionalequipment","ai_weapon_crossbow")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_crowbar" then
- npc:SetKeyValue("additionalequipment","ai_weapon_crowbar")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_rpg" then
- npc:SetKeyValue("additionalequipment","ai_weapon_rpg")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_stunstick" then
- npc:SetKeyValue("additionalequipment","ai_weapon_stunstick")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_pistol" then
- npc:SetKeyValue("additionalequipment","ai_weapon_pistol")
- elseif rag2:GetNWString("WeaponNpc2") == "ai_weapon_shotgun" then
- npc:SetKeyValue("additionalequipment","ai_weapon_shotgun")
- elseif rag2:GetNWString("WeaponNpc2") == "weapon_ar2" then
- npc:SetKeyValue("additionalequipment","ai_weapon_ar2")
- else
- npc:SetKeyValue("additionalequipment",rag2:GetNWString("WeaponNpc2"))
- end
- end
- npc:SetSkin(rag2:GetSkin())
- npc:Activate()
- npc:Spawn()
- npc:SetModel(rag2:GetModel())
- npc:SetMaterial(rag2:GetMaterial())
- npc:SetColor(Color(rag2:GetColor().r,rag2:GetColor().g,rag2:GetColor().b,rag2:GetColor().a))
- npc:SetName(rag2:GetNWString("NpcName2"))
- npc:SetHealth(rag2:GetNWInt("Health2"))
- for i = 0,32 do
- npc:SetBodygroup(i,rag2:GetBodygroup(i))
- end
- rag2:Remove()
- end
- end)
- elseif SERVER and tr.Entity:IsPlayer() and tr.Entity:Alive() and IsValid(tr.Entity) and target:GetNWBool("StunnedPlayer")==false and
- MyChanceStun(chancestun) then
- self:EmitSound("weapons/stunstick/stunstick_fleshhit" .. math.random(1,2) .. ".wav")
- target:Freeze(true)
- target:ViewPunch( Angle( -16,math.Rand(-48, -24),2 ) )
- target:ScreenFade(bit.bor(SCREENFADE.OUT,SCREENFADE.PURGE),color_white,0.3,0)
- target:SetNWBool("StunnedPlayer",true)
- timer.Simple(ststuntimecvar:GetFloat(),function() if IsValid(target) then
- target:Freeze(false)
- target:SetNWBool("StunnedPlayer",false)
- end
- end)
- elseif SERVER and tr.Entity:IsPlayer() and tr.Entity:Alive() and IsValid(tr.Entity) and
- MyChanceShock(chancestun) then
- -- This is all vars,what we need.
- local myweps={}
- for k, v in pairs(target:GetWeapons()) do
- table.insert(myweps,v:GetClass())
- end
- local myammo={}
- for k, v in pairs(target:GetWeapons()) do
- table.insert(myammo,v:Clip1())
- end
- local myammoin={}
- local myammointype={}
- for k, v in pairs(target:GetWeapons()) do
- table.insert(myammoin,target:GetAmmoCount(v:GetPrimaryAmmoType()))
- table.insert(myammointype,v:GetPrimaryAmmoType())
- end
- local myammoin2={}
- local myammointype2={}
- for k, v in pairs(target:GetWeapons()) do
- table.insert(myammoin2,target:GetAmmoCount(v:GetSecondaryAmmoType()))
- table.insert(myammointype2,v:GetSecondaryAmmoType())
- end
- if target:GetActiveWeapon():IsValid() and IsValid(target:GetActiveWeapon()) then
- weaponply = target:GetActiveWeapon():GetClass()
- weaponplymodel = target:GetActiveWeapon():GetModel()
- else
- weaponply = nil
- weaponplymodel = nil
- end
- plyskin = target:GetSkin()
- plyhealth = target:Health()
- plyangle = target:GetAngles()
- plymodel = target:GetModel()
- plycolor = target:GetColor()
- plyarmor = target:Armor()
- plymaterial = target:GetMaterial()
- local rag3 = ents.Create("prop_ragdoll")
- rag3:SetModel(plymodel)
- rag3:SetSkin(plyskin)
- rag3:SetPos(target:GetPos())
- rag3:SetColor(Color(plycolor.r,plycolor.g,plycolor.b,plycolor.a))
- rag3:SetMaterial(plymaterial)
- rag3:Spawn()
- rag3:GetTable().ang3 = plyangle
- rag3:SetNWBool("IsStunedNPC2",true)
- rag3:SetNWBool("IsStunedPlayer",true)
- rag3:SetNWBool("NotAlivenpc",false)
- rag3:SetNWInt("Takedamages2",0)
- rag3:SetNWInt("Health2",plyhealth)
- rag3:SetNWInt("Armor",plyarmor)
- rag3:SetNWEntity("Playerent",target)
- rag3.mywepsgive = myweps
- rag3.myammogive = myammo
- rag3.myammoingive = myammoin
- rag3.myammointypegive = myammointype
- rag3.myammoingive2 = myammoin2
- rag3.myammointypegive2 = myammointype2
- target:Spectate( OBS_MODE_CHASE )
- target:SpectateEntity( rag3 )
- target:StripWeapons()
- for i = 0,32 do
- rag3:SetBodygroup(i,target:GetBodygroup(i))
- end
- for i = 0, rag3:GetPhysicsObjectCount( ) do
- local physobj = rag3:GetPhysicsObjectNum( i )
- if (physobj) and IsValid(physobj)then
- local pos, ang = target:GetBonePosition( target:TranslatePhysBoneToBone( i ) )
- physobj:SetPos(pos)
- physobj:SetAngles(ang)
- physobj:EnableMotion(true)
- physobj:ApplyForceCenter((target:GetPos() - self.Owner:GetPos())*20)
- end
- end
- if weaponply!= nil then
- local wep2 = ents.Create("cycler")
- wep2:SetModel( weaponplymodel )
- wep2:SetParent(rag3)
- wep2:AddEffects( EF_BONEMERGE )
- wep2:Spawn()
- end
- target:Spectate( OBS_MODE_CHASE )
- target:SpectateEntity( rag3 )
- timer.Create( "shockstunragply" .. rag3:EntIndex(),0.2,(stshocktimecvar:GetFloat()*10)/2,function()
- if IsValid(rag3) then
- local PhysObj = rag3:GetPhysicsObject()
- local mass = PhysObj:GetMass()
- PhysObj:ApplyForceOffset((mass * 4 * Vector(math.Rand(-13.5, 15.2), math.Rand(-13.5, 15.2), math.Rand(13.5, 20.2))), (PhysObj:GetPos() + Vector(math.Rand(-82, 82), math.Rand(-82, 82), math.Rand(-82, 82))))
- if stshockeffectencvar:GetBool() then
- local effectdata = EffectData()
- effectdata:SetOrigin( rag3:GetPos() )
- effectdata:SetStart( rag3:GetPos() )
- effectdata:SetMagnitude(15)
- effectdata:SetEntity( rag3 )
- util.Effect( "TeslaHitBoxes", effectdata)
- local light = ents.Create("light_dynamic")
- light:SetPos( rag3:GetPos() )
- light:Spawn()
- light:SetKeyValue("_light","235 235 255")
- light:SetKeyValue("distance",120)
- light:SetParent( rag3 )
- light:Fire("kill","",0.1)
- end
- rag3:EmitSound("Town.d1_town_01_LoudSpark")
- end
- end)
- timer.Simple(stshocktimecvar:GetFloat() + stragdolltimecvar:GetFloat(),function()
- if SERVER and IsValid(rag3) and rag3:GetNWBool("NotAlivenpc") == true then
- rag3:Fire( "FadeAndRemove", "", 0.4)
- end
- end)
- timer.Simple(stshocktimecvar:GetFloat(),function() if IsValid(rag3) and !(rag3:GetNWBool("NotAlivenpc") == true) then
- -- Spawning our player.
- rag3:GetNWEntity("Playerent"):UnSpectate()
- local ply = rag3:GetNWEntity("Playerent")
- ply:Activate()
- ply:Spawn()
- ply:StripWeapons()
- local weps = rag3.mywepsgive
- local ammos = rag3.myammogive
- for i=1, #weps, 1 do
- ply:Give(weps[i])
- end
- local plywp = ply:GetWeapons()
- local plyams = ammos
- for i=1, #plywp, 1 do
- for k=1, #plyams, 1 do
- plywp[i]:SetClip1(plyams[i])
- end
- end
- local plammoin = rag3.myammoingive
- local plammointype = rag3.myammointypegive
- for i=1, #plammoin, 1 do
- for b=1, #plammointype, 1 do
- ply:SetAmmo(plammoin[i], plammointype[i])
- end
- end
- local plammoin2 = rag3.myammoingive2
- local plammointype2 = rag3.myammointypegive2
- for i=1, #plammoin2, 1 do
- for b=1, #plammointype2, 1 do
- ply:SetAmmo(plammoin2[i], plammointype2[i])
- end
- end
- ply:GetWeapon("weapon_stunner")
- ply:SetAngles(rag3:GetTable().ang3 )
- ply:SetPos(rag3:GetPos())
- ply:SetModel(rag3:GetModel())
- ply:SetMaterial(rag3:GetMaterial())
- ply:SetSkin(rag3:GetSkin())
- ply:SetHealth(rag3:GetNWInt("Health2"))
- ply:SetArmor(rag3:GetNWInt("Armor"))
- if ply:Armor() <= 0 then
- ply:SetArmor(0)
- end
- for i = 0,32 do
- ply:SetBodygroup(i,rag3:GetBodygroup(i))
- end
- rag3:SetNWBool("notrespawnneed",true)
- rag3:Remove()
- end
- end)
- elseif SERVER and tr.Entity:IsNPC() and IsValid(tr.Entity) and MyChanceNormal(chancestun) then
- self:EmitSound("weapons/stunstick/stunstick_fleshhit" .. math.random(1,2) .. ".wav")
- else
- self:EmitSound(Sound(self.Primary.Sound))
- end
- end
- local bullet = {}
- bullet.Num = 1
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector( 0.1 * 0.1 , 0.1 * 0.1, 0)
- bullet.Tracer = 0
- bullet.Force = 20
- bullet.Damage = math.random(stdmgcvarmin:GetInt(),stdmgcvarmax:GetInt())
- bullet.Callback = function(attacker, trace, dmginfo)
- dmginfo:SetDamageType(DMG_GENERIC)
- end
- bullet.AmmoType = self.Primary.Ammo
- local rnda = 2 * -1
- local rndb = 2 * math.random(-1, 1)
- self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- self.Owner:FireBullets( bullet )
- self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
- if !(stunlimitedpowercvar:GetBool()) then
- self:TakePrimaryAmmo(self.Primary.TakeAmmo)
- end
- self:SetNextPrimaryFire( CurTime() + stfireratecvar:GetFloat() )
- self:SetNextSecondaryFire( CurTime() + stfireratecvar:GetFloat() )
- timer.Create( "stunner_idle" .. self:EntIndex(), 0.6, 1, function() if IsValid(self.Weapon) and self.Weapon:GetOwner():GetActiveWeapon():GetClass() == "weapon_stunner" then self.Weapon:SendWeaponAnim(ACT_VM_IDLE) end end)
- else
- self:EmitSound("weapons/stunstick/stunstick_swing" .. math.random(1,2) .. ".wav" )
- self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- self:SetNextPrimaryFire( CurTime() + stfireratecvar:GetFloat() )
- self:SetNextSecondaryFire( CurTime() + stfireratecvar:GetFloat() )
- timer.Create( "stunner_idle" .. self:EntIndex(), 0.6, 1, function() if IsValid(self.Weapon) and self.Weapon:GetOwner():GetActiveWeapon():GetClass() == "weapon_stunner" then self.Weapon:SendWeaponAnim(ACT_VM_IDLE) end end)
- end
- end
- hook.Add( "EntityRemoved", "PlayerRemoved", function( ent )
- if SERVER and ent:GetClass()=="prop_ragdoll" and ent:GetNWBool("IsStunedNPC2") == true and !(ent:GetNWBool("NotAlivenpc") == true) and !(ent:GetNWBool("notrespawnneed")==true) and ent:GetNWInt("Health2")>0 and IsValid(ent:GetNWEntity("Playerent")) then
- local rply = ent:GetNWEntity("Playerent")
- timer.Simple(2,function() if IsValid(rply) then
- local ply = rply
- ply:Activate()
- ply:Spawn()
- end
- end)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement