How would I make a gun not fire any bullets, as In, just melee someone with the gun.
I want to edit the current gun's code.
Thanks :)
Remove the bit that says self.Owner:FireBullets(bullet) and put in your code for hitting people.
Hmm there isn't one.
Maybe you can just tell me how to make this
Into something that melees people instead of firing at them.
Thanks :)
(I'm not asking you to make me a swep, just make it melee people)
Any help will be greatly appreciated.
[lua]
--------------------------------------------------------------------------------------------------------
-- 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 --
-- I did not create the models but do not know who did --
--------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------- ADMINS, MODIFY VARIABLES HERE -----------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.RateOfFire = .7 -- pause between shots
SWEP.ModeRate = 1 -- pause between switching modes
SWEP.NPC = true -- works on NPC's
SWEP.PLY = true -- works on players
SWEP.Timed = true -- default mode, if false then sleep is permanent
if CLIENT then CreateClientConVar("tranq_settime", "10", false, true) end
//SWEP.ViewModel = "models/weapons/v_pistol.mdl"
//SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.HoldType = "pistol"
if CLIENT then CreateClientConVar("tranq_settime", "10", false, true) end
-- Basic SWEP Settings
SWEP.Author = "Elwaywitvac"
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 = -1
SWEP.Primary.DefaultClip = -1
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:SecondaryAttack( )
-- Fire the weapon
self.Weapon:EmitSound(ShootSound)
self.Weapon:SetNextPrimaryFire( CurTime() + self.RateOfFire )
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
-- tranq NPC/Player
if tr.Entity:IsPlayer() and self.PLY then
if self.Timed then
tranqPlayer(tr.Entity, self.Owner:GetInfo("tranq_settime"))
else
tranqPlayer(tr.Entity, nil)
end
elseif tr.Entity:IsNPC() and self.NPC then
if self.Timed then
tranqNPC(tr.Entity, self.Owner:GetInfo("tranq_settime"))
else
tranqNPC(tr.Entity, nil)
end
end
end
function SWEP:PrimaryAttack()
-- 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
-- reload timer
local canReload=0
--- Change Modes
function SWEP:Reload()
if CurTime()<canReload then
return
end
-- toggle timed/permanent
if self.Timed then
self.Timed = false
self.Owner:PrintMessage(HUD_PRINTCENTER, "Permanent Sleep Mode")
else
self.Timed = true
self.Owner:PrintMessage(HUD_PRINTCENTER, "Temporary Sleep Mode: " .. self.Owner:GetInfo("tranq_settime") .. "s")
end
-- wait for switch
canReload = CurTime()+self.ModeRate
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())
-- revive npc
elseif ent.wasNPC then
local npc = ents.Create(ent.npcType) -- create the entity
util.PrecacheModel(ent:GetModel()) -- precache the model
npc:SetModel(ent:GetModel()) -- and set it
local spawnPos = ent:GetPos()+Vector(0,0,0) -- position to spawn it
npc:SetPos(spawnPos) -- position
npc:SetSkin(ent.npcSkin)
npc:SetAngles(Angle(0,ent:GetAngles().y,0))
if ent.npcWep != "" then -- if it's an NPC and we found a weapon for it when it was spawned, then
npc:SetKeyValue("additionalequipment",ent.npcWep) -- give it the weapon
end
if ent.entType == "npc_citizen" then
npc:SetKeyValue("citizentype",ent.npcCitType) -- set the citizen type - rebel, refugee, etc.
if ent.npcCitType == "3" && ent.npcCitMed==1 then -- if it's a rebel, then it might be a medic, so check that
npc:SetKeyValue("spawnflags","131072") -- set medic spawn flag
end
end
npc:Spawn()
npc:Activate()
-- don't deal with other ents
else
return
end
-- remove ragdoll
ent:Remove()
end
-- Tranq NPC, mostly taken from crate maker
function tranqNPC(npc, t)
-- get info about npc
local skin = npc:GetSkin()
local wep = ""
local possibleWep = ents.FindInSphere(npc:GetPos(),0.01) -- find anything in the center basically
for k, v in pairs(possibleWep) do
if string.find(v:GetClass(),"weapon_") == 1 then
wep = v:GetClass()
end
end
local citType = "" -- citizen type
local citMed = 0 -- is it a medic? assume no
if npc:GetClass() == "npc_citizen" then
citType = string.sub(npc:GetModel(),21,21) -- get group number (e.g. models/humans/group0#/whatever)
if string.sub(npc:GetModel(),22,22) == "m" then citMed = 1 end -- medic skins have an "m" after the number
end
-- make ragdoll now that all info is gathered
local rag = ents.Create( "prop_ragdoll" )
if not rag:IsValid() then return end
-- build rag
rag:SetModel( npc:GetModel() )
rag:SetKeyValue( "origin", npc:GetPos().x .. " " .. npc:GetPos().y .. " " .. npc:GetPos().z )
rag:SetAngles(npc:GetAngles())
-- npc vars
rag.wasNPC = true
rag.npcType = npc:GetClass()
rag.npcWep = wep
rag.npcCitType = citType
rag.npcCitMed = citMed
rag.npcSkin = skin
--finalize
rag:Spawn()
rag:Activate()
-- make ragdoll fall
//rag:GetPhysicsObject():SetVelocity(8*npc:GetVelocity())
--remove npc
npc:Remove()
-- sleep
if t the
Replace anywhere you see
[lua]
self.Owner:GetEyeTrace()
[/lua]
with a declaration of another trace. GetEyeTrace goes for an extreme distance, so you cannot tell it to go a short distance (melee).
A tracehull would most likely be the best option.
Sorry, you need to Log In to post a reply to this thread.