Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------------------------------
- -- Tranq Gun v1.5 --
- -- Special thanks to Mahalis for his crate maker --
- -- and Adrian Leuzzi for his ragdoll gun --
- -- as well as everyone who helped to document the GMod wiki -- --
- --------------------------------------------------------------------------------------------------------
- --Ported by Charles445
- if SERVER then
- AddCSLuaFile( "shared.lua" )
- end
- SWEP.HoldType = "ar2"
- if CLIENT then
- SWEP.PrintName = "Tranquilizer"
- SWEP.Slot = 7
- SWEP.ViewModelFlip = false
- SWEP.ViewModelFOV = 54
- SWEP.EquipMenuData = {
- type = "item_weapon",
- desc = "Used on suspects that won't comply."
- };
- SWEP.Icon = "VGUI/ttt/icon_polter"
- end
- SWEP.Base = "weapon_tttbase"
- SWEP.Kind = WEAPON_EQUIP2
- SWEP.CanBuy = {ROLE_DETECTIVE}
- SWEP.WeaponID = AMMO_TRANQ -- What does this do?
- SWEP.ViewModel = "models/weapons/v_IRifle.mdl"
- SWEP.WorldModel = "models/weapons/w_IRifle.mdl"
- -- THESE VARIABLES CAN BE CHANGED
- SWEP.RateOfFire = 5 -- pause between shots
- SWEP.SetTime = 10 -- YOU CAN CHANGE THIS TO SET THE DURATION OF THE SLEEP
- -- That's it for variables you should change
- -- Basic SWEP Settings
- SWEP.Author = "Elwaywitvac"
- SWEP.PrintName = "Tranquilizer Gun"
- SWEP.Contact = "Elwaywitvac@gmail.com"
- SWEP.Purpose = "Knocks Players/NPCs unconcious"
- SWEP.Instructions = "Rate of Fire: " .. SWEP.RateOfFire .. " secs \nPrimary: Sleep\nSecondary: Revive\nReload: Change Mode(permanent/temporary)"
- SWEP.Primary.ClipSize = 3
- SWEP.Primary.DefaultClip = 3
- SWEP.Primary.ClipMax = 3
- SWEP.Primary.Automatic = false
- SWEP.Primary.Ammo = "none"
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = "none"
- local ShootSound = Sound( "Weapon_crossbow.Single" )
- if SERVER then sleeping = {} end
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- ----------- SWEP FUNCTIONS -----------
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- Make ply/npc sleep
- function SWEP:PrimaryAttack()
- -- Fire the weapon
- self.Weapon:SetNextPrimaryFire( CurTime() + self.RateOfFire )
- if not self:CanPrimaryAttack() then return end
- self.Weapon:EmitSound(ShootSound)
- self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- self:TakePrimaryAmmo(1)
- -- Only server handles ragdolls
- if(!SERVER) then return end
- local tr = self.Owner:GetEyeTrace()
- if ( (SinglePlayer() && SERVER) || CLIENT ) then
- self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
- end
- -- if there isn't anything there quit
- if ( tr.HitWorld ) then return end
- -- tranq Player
- if tr.Entity:IsPlayer() then
- tranqPlayer(tr.Entity, self.SetTime)
- end
- end
- -- Revive
- function SWEP:SecondaryAttack( )
- -- Fire the weapon
- self.Weapon:EmitSound(ShootSound)
- self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- -- Only server handles ragdolls
- if(!SERVER) then return end
- local tr = self.Owner:GetEyeTrace()
- -- if there isn't anything there quit
- if ( tr.HitWorld ) then return end
- -- revive what you hit
- revive(tr.Entity)
- end
- function SWEP:Reload()
- --Reload does absolutely nothing! Hooray!
- end
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- ----------- TRANQ FUNCTIONS ---------
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -------------- Revive
- function revive(ent)
- -- revive player
- if !ent then return end
- if ent.ply then
- local phy = ent:GetPhysicsObject()
- phy:EnableMotion(false)
- ent:SetSolid(SOLID_NONE)
- ent.ply:DrawViewModel(true)
- ent.ply:DrawWorldModel(true)
- ent.ply:Spawn()
- ent.ply:SetPos(ent:GetPos())
- ent.ply:SetVelocity(ent:GetPhysicsObject():GetVelocity())
- end
- -- remove ragdoll
- ent:Remove()
- end
- function tranqPlayer(ply, t)
- -- create ragdoll
- local rag = ents.Create( "prop_ragdoll" )
- if not rag:IsValid() then return end
- -- build rag
- rag:SetModel( ply:GetModel() )
- rag:SetKeyValue( "origin", ply:GetPos().x .. " " .. ply:GetPos().y .. " " .. ply:GetPos().z )
- rag:SetAngles(ply:GetAngles())
- -- player vars
- rag.ply = ply
- -- "remove" player
- ply:StripWeapons()
- ply:DrawViewModel(false)
- ply:DrawWorldModel(false)
- ply:Spectate(OBS_MODE_CHASE)
- ply:SpectateEntity(rag)
- -- finalize ragdoll
- rag:Spawn()
- rag:Activate()
- -- make ragdoll fall
- rag:GetPhysicsObject():SetVelocity(4*ply:GetVelocity())
- --Timed sleep
- local key = (t + CurTime())
- sleeping[key] = rag
- return rag
- end
- -- Watch for temporary revives (hook on think)
- function checkSleeping()
- for t, ent in pairs(sleeping) do
- if CurTime() > t then
- revive(ent)
- sleeping[t] = nil
- end
- end
- end
- hook.Add("Think", "checksleeping", checkSleeping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement