Guest User

Taser

a guest
Apr 13th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.25 KB | None | 0 0
  1.  
  2.  
  3. if ( SERVER ) then
  4.  
  5.     AddCSLuaFile( "shared.lua" )
  6.    
  7.     SWEP.Weight             = 2
  8. SWEP.AutoSwitchTo       = true
  9. SWEP.AutoSwitchFrom     = true
  10.     SWEP.HoldType           = "pistol"
  11.    
  12. end
  13.  
  14. if ( CLIENT ) then
  15.  
  16. SWEP.PrintName = "Taser";
  17. SWEP.Slot = 3;
  18. SWEP.SlotPos = 1;
  19. SWEP.DrawAmmo = false;
  20. SWEP.DrawCrosshair = true;
  21.  
  22.  
  23. end
  24.  
  25. SWEP.Author = "Fub4r";
  26. SWEP.Contact = "fub4r2006@hotmail.co.uk";
  27. SWEP.Purpose = "Tasering";
  28. SWEP.Instructions = "Left click to bring down, then right click to electrocute!";
  29.  
  30. SWEP.Spawnable          = false
  31. SWEP.AdminSpawnable     = true
  32.  
  33. SWEP.ViewModel          = "models/weapons/v_pistol.mdl"
  34. SWEP.WorldModel         = "models/weapons/w_pistol.mdl"
  35.  
  36. SWEP.Primary.ClipSize       = 1
  37. SWEP.Primary.DefaultClip    = 40
  38. SWEP.Primary.Automatic      = false
  39. SWEP.Primary.Ammo           = "357"
  40.  
  41. SWEP.Secondary.ClipSize     = -1
  42. SWEP.Secondary.DefaultClip  = -1
  43. SWEP.Secondary.Automatic    = true
  44. SWEP.Secondary.Ammo         = ""
  45.  
  46. local taseredrags = {}
  47. local taseruniquetimer1 = 0
  48. local taseruniquetimer2 = 0
  49.  
  50.  function SWEP:Reload()
  51. self.Weapon:DefaultReload( ACT_VM_RELOAD ) //animation for reloading
  52. end
  53.  
  54.  function SWEP:PrimaryAttack()
  55.  if ( !self:CanPrimaryAttack() ) then return end
  56.  local eyetrace = self.Owner:GetEyeTrace();
  57.  if !eyetrace.Entity:IsPlayer() then
  58.   if !eyetrace.Entity:IsNPC() then return end       // Check to see if what the player is aiming at is an NPC or Player
  59.   end
  60.  
  61. self.Weapon:EmitSound( "Weapon_StunStick.Activate")  
  62. self.BaseClass.ShootEffects( self )
  63. self:TakePrimaryAmmo(1)
  64.  
  65.  
  66.  if (!SERVER) then return end
  67.  
  68.  if eyetrace.Entity:IsPlayer() then
  69.  self.Owner:PrintMessage( HUD_PRINTCENTER, "Now right click to electrocute "..eyetrace.Entity:GetName( ) )  
  70.  self:tasePlayer(eyetrace.Entity)    // If the it is a player then bring them down tranqPlayer()
  71.  end
  72.  if eyetrace.Entity:IsNPC() then
  73.  self.Owner:PrintMessage( HUD_PRINTCENTER, "Now right click to electrocute the NPC" )
  74.  self:taseNPC(eyetrace.Entity, self.Owner)    // If the it is a NPC then bring them down with tranqNPC()
  75.  end
  76.   end
  77.  
  78.  
  79. function SWEP:tasePlayer(ply)
  80.     -- create ragdoll
  81.     local rag = ents.Create( "prop_ragdoll" )
  82.     if not rag:IsValid() then return end
  83.  
  84.     -- build rag
  85.     rag:SetModel( ply:GetModel() )
  86.     rag:SetKeyValue( "origin", ply:GetPos().x .. " " .. ply:GetPos().y .. " " .. ply:GetPos().z )
  87.     rag:SetAngles(ply:GetAngles())
  88.            
  89.     -- player vars
  90.     rag.taseredply = ply
  91.     table.insert(taseredrags, rag)
  92.        
  93.     -- "remove" player
  94.     ply:StripWeapons()
  95.     ply:DrawViewModel(false)
  96.     ply:DrawWorldModel(false)
  97.     ply:Spectate(OBS_MODE_CHASE)
  98.     ply:SpectateEntity(rag)
  99.    
  100.     -- finalize ragdoll
  101.     rag:Spawn()
  102.     rag:Activate()
  103.    
  104.     -- make ragdoll fall
  105.     rag:GetPhysicsObject():SetVelocity(4*ply:GetVelocity())
  106.    
  107.     -- bring the motherfucker back
  108.  
  109.      self:setrevivedelay(rag)
  110.    
  111. end
  112.  
  113. function SWEP:taseNPC(npc, npcShooter)
  114.     -- get info about npc
  115.     local skin = npc:GetSkin()
  116.     local wep = ""
  117.     local possibleWep = ents.FindInSphere(npc:GetPos(),0.01) -- find anything in the center basically
  118.     for k, v in pairs(possibleWep) do
  119.         if string.find(v:GetClass(),"weapon_") == 1 then
  120.             wep = v:GetClass()
  121.         end
  122.     end
  123.  
  124.     local citType = "" -- citizen type
  125.     local citMed = 0 -- is it a medic? assume no
  126.     if npc:GetClass() == "npc_citizen" then
  127.         citType = string.sub(npc:GetModel(),21,21) -- get group number (e.g. models/humans/group0#/whatever)
  128.         if string.sub(npc:GetModel(),22,22) == "m" then citMed = 1 end -- medic skins have an "m" after the number
  129.     end
  130.  
  131.     -- make ragdoll now that all info is gathered  
  132.     local rag = ents.Create( "prop_ragdoll" )
  133.     if not rag:IsValid() then return end
  134.    
  135.     -- build rag
  136.     rag:SetModel( npc:GetModel() )
  137.     rag:SetKeyValue( "origin", npc:GetPos().x .. " " .. npc:GetPos().y .. " " .. npc:GetPos().z )
  138.     rag:SetAngles(npc:GetAngles())
  139.    
  140.     -- npc vars
  141.     rag.tasewasNPC = true
  142.     rag.tasenpcType = npc:GetClass()
  143.     rag.tasenpcWep = wep
  144.     rag.tasenpcCitType = citType
  145.     rag.tasenpcCitMed = citMed
  146.     rag.tasenpcSkin = skin
  147.     rag.tasenpcShooter = npcShooter
  148.     table.insert(taseredrags, rag)
  149.    
  150.     --finalize
  151.     rag:Spawn()
  152.     rag:Activate()
  153.    
  154.     -- make ragdoll fall
  155.   rag:GetPhysicsObject():SetVelocity(8*npc:GetVelocity())
  156.        
  157.     --remove npc
  158.     npc:Remove()
  159.  
  160.  self:setrevivedelay(rag)
  161.  
  162.    
  163.     end
  164.  
  165. function SWEP:setrevivedelay(rag)
  166. if taseruniquetimer1 > 30 then
  167. taseruniquetimer1 = 0
  168. end
  169. taseruniquetimer1 = taseruniquetimer1 + 1
  170.  
  171. timer.Create("revivedelay"..taseruniquetimer1, 10, 1, self.taserevive, self, rag )
  172. end
  173.  
  174. function SWEP:taserevive(ent)
  175.     -- revive player
  176.     if !ent then return end
  177.    
  178.     if ent.taseredply then
  179.    if ( !ent.taseredply:IsValid() ) then return end
  180.    local phy = ent:GetPhysicsObject()
  181.         phy:EnableMotion(false)
  182.         ent:SetSolid(SOLID_NONE)
  183.     ent.taseredply:DrawViewModel(true)
  184.     ent.taseredply:DrawWorldModel(true)
  185.     ent.taseredply:Spawn()
  186.     ent.taseredply:SetPos(ent:GetPos())
  187.     ent.taseredply:SetVelocity(ent:GetPhysicsObject():GetVelocity())
  188. ent.taseredply:SetMoveType(MOVETYPE_NONE)
  189. ent.taseredply:ConCommand("pp_motionblur 1")
  190. ent.taseredply:ConCommand("pp_motionblur_addalpha 0.06 ")
  191. ent.taseredply:ConCommand("pp_motionblur_delay 0")
  192. ent.taseredply:ConCommand("pp_motionblur_drawalpha 0.99 ")
  193. if taseruniquetimer2 > 30 then
  194. taseruniquetimer2 = 0
  195. end
  196. taseruniquetimer2 = taseruniquetimer2 + 1
  197. timer.Create("pauseplayer"..taseruniquetimer2, 3, 1, self.pauseplayer, self, ent.taseredply)
  198.  
  199.     -- revive npc
  200.     elseif ent.tasewasNPC then
  201.         local npc = ents.Create(ent.tasenpcType) -- create the entity
  202.        
  203.         util.PrecacheModel(ent:GetModel()) -- precache the model
  204.         npc:SetModel(ent:GetModel()) -- and set it
  205.         local spawnPos = ent:GetPos()+Vector(0,0,0) -- position to spawn it
  206.        
  207.         npc:SetPos(spawnPos) -- position
  208.         npc:SetSkin(ent.tasenpcSkin)
  209.         npc:SetAngles(Angle(0,ent:GetAngles().y,0))
  210.        
  211.         if ent.tasenpcWep != "" then -- if it's an NPC and we found a weapon for it when it was spawned, then
  212.             npc:SetKeyValue("additionalequipment",ent.tasenpcWep) -- give it the weapon
  213.         end
  214.        
  215.         if ent.taseentType == "npc_citizen" then
  216.             npc:SetKeyValue("citizentype",ent.tasenpcCitType) -- set the citizen type - rebel, refugee, etc.
  217.             if ent.tasenpcCitType == "3" && ent.tasenpcCitMed==1 then -- if it's a rebel, then it might be a medic, so check that
  218.                 npc:SetKeyValue("spawnflags","131072") -- set medic spawn flag
  219.             end
  220.         end
  221.                
  222.         npc:Spawn()
  223.         npc:Activate()
  224.        
  225. cleanup.Add (uplayer, "NPC", npc);
  226.  
  227. undo.Create ("Tasered NPC");
  228. undo.AddEntity (npc);
  229. undo.SetPlayer (ent.tasenpcShooter);
  230.  
  231. undo.Finish();
  232.  
  233.        
  234.     -- don't deal with other ents
  235.     else
  236.         return
  237.     end
  238.    
  239.         for k, v in pairs(taseredrags) do
  240.         if v == ent then
  241.              table.remove( taseredrags, k )
  242.         end
  243.     end
  244.     ent:Remove()
  245.  
  246. end
  247.  
  248.  
  249. function SWEP:pauseplayer(ply)
  250.  
  251. ply:SetMoveType(MOVETYPE_WALK )
  252. ply:ConCommand("pp_motionblur 0")
  253.  
  254. end
  255.  
  256.  
  257.  
  258.  
  259.  function SWEP:SecondaryAttack()
  260.  if table.Count( taseredrags ) == 0 then return end
  261.  
  262.  self.Owner:EmitSound( "Weapon_Pistol.Empty")
  263.   self.Owner:EmitSound( "Weapon_SMG1.Empty")
  264.   if (!SERVER) then return end
  265.    
  266.     for k, v in pairs(taseredrags) do
  267.      local shock1 = math.random(-1200, 1200 )
  268.    local shock2 = math.random(-1200, 1200 )
  269.     local shock3 = math.random(-1200, 1200 )
  270.     v:GetPhysicsObject():ApplyForceCenter( Vector( shock1, shock2, shock3 ) )
  271.         end
  272.    
  273.     end
Add Comment
Please, Sign In to add comment