[B] --SCROLL TO THE BOTTOM OF THE POST TO READ WHAT I NEED HELP WITH--[/B]
I'm attempting to combine a mad cow weapon (The revolver, 357) with the taser gun. Here's the coding: [CODE]// Variables that are used on both client and server
SWEP.HoldType = "pistol"
SWEP.Base = "weapon_mad_base"
SWEP.ViewModel = "models/weapons/v_357.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Spawnable = true
SWEP.AdminSpawnable = false
SWEP.Primary.Sound = Sound("Weapon_357.Single")
SWEP.Primary.Recoil = 6
SWEP.Primary.Damage = 8
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0.1
SWEP.Primary.Delay = 0.7
SWEP.Primary.ClipSize = 1 // Size of a clip
SWEP.Primary.DefaultClip = 10 // Default number of bullets in a clip
SWEP.Primary.Automatic = false // Automatic/Semi Auto
SWEP.Primary.Ammo = "357"
SWEP.Secondary.ClipSize = -1 // Size of a clip
SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip
SWEP.Secondary.Automatic = true // Automatic/Semi Auto
SWEP.Secondary.Ammo = ""
SWEP.ShellEffect = "none" // "effect_mad_shell_pistol" or "effect_mad_shell_rifle" or "effect_mad_shell_shotgun"
SWEP.ShellDelay = 0
SWEP.Pistol = true
SWEP.Rifle = false
SWEP.Shotgun = false
SWEP.Sniper = false
SWEP.IronSightsPos = Vector (-5.6891, -3.925, 2.5776)
SWEP.IronSightsAng = Vector (0.214, -0.1767, 0)
SWEP.RunArmOffset = Vector (0.0961, 0, 5.9811)
SWEP.RunArmAngle = Vector (-25.4014, 2.0332, 0)
local taseredrags = {}
local taseruniquetimer1 = 0
local taseruniquetimer2 = 0
function SWEP:Reload()
self.Weapon:DefaultReload( ACT_VM_RELOAD ) //animation for reloading
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 // Check to see if what the player is aiming at is an NPC or Player
end
self.Weapon:EmitSound( "Weapon_StunStick.Activate")
self.BaseClass.ShootEffects( self )
self:TakePrimaryAmmo(1)
if (!SERVER) then return end
if eyetrace.Entity:IsPlayer() then
self.Owner:PrintMessage( HUD_PRINTCENTER, "Now right click to shock!"..eyetrace.Entity:GetName( ) )
self:tasePlayer(eyetrace.Entity) // If the it is a player then bring them down tranqPlayer()
end
if eyetrace.Entity:IsNPC() then
self.Owner:PrintMessage( HUD_PRINTCENTER, "Now right click to electrocute the NPC" )
self:taseNPC(eyetrace.Entity, self.Owner) // If the it is a NPC then bring them down with tranqNPC()
end
end
function SWEP:tasePlayer(ply)
-- 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.taseredply = ply
table.insert(taseredrags, rag)
-- "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())
-- bring the motherfucker back
self:setrevivedelay(rag)
end
function SWEP:taseNPC(npc, npcShooter)
-- 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.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)
--finalize
rag:Spawn()
rag:Activate()
-- make ragdoll fall
rag:GetPhysicsObject():SetVelocity(8*npc:GetVelocity())
--remove npc
npc:Remove()
self:setrevivedelay(rag)
end
function SWEP:setrevivedelay(rag)
if taseruniquetimer1 > 30 then
taseruniquetimer1 = 0
end
taseruniquetimer1 = taseruniquetimer1 + 1
timer.Create("revivedelay"..taseruniquetimer1, 10, 1, self.taserevive, self, rag )
end
function SWEP:taserevive(ent)
-- revive player
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())
ent.taseredply:SetMoveType(MOVETYPE_NONE)
ent.taseredply:ConCommand("pp_motionblur 1")
ent.taseredply:ConCommand("pp_motionblur_addalpha 0.06 ")
ent.taseredply:ConCommand("pp_motionblur_delay 0")
ent.taseredply:ConCommand("pp_motionblur_drawalpha 0.99 ")
if taseruniquetimer2 > 30 then
taseruniquetimer2 = 0
end
taseruniquetimer2 = taseruniquetimer2 + 1
timer.Create("pauseplayer"..taseruniquetimer2, 3, 1, self.pauseplayer, self, ent.taseredply)
-- revive npc
elseif ent.tasewasNPC then
local npc = ents.Create(ent.tasenpcType) -- 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.tasenpcSkin)
npc:SetAngles(Angle(0,ent:GetAngles().y,0))
if ent.tasenpcWep != "" then -- if it's an NPC and we found a weapon for it when it was spawned, then
npc:SetKeyValue("additionalequipment",ent.tasenpcWep) -- give it the weapon
end
if ent.taseentType == "npc_citizen" then
npc:SetKeyValue("citizentype",ent.tasenpcCitType) -- set the citizen type - rebel, refugee, etc.
if ent.tasenpcCitType == "3" && ent.tasenpcCitMed==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()
cleanup.Add (uplayer, "NPC", npc);
undo.Create ("Tasered NPC");
undo.AddEntity (npc);
undo.SetPlayer (ent.tasenpcShooter);
undo.Finish();
-- don't deal with other ents
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:pauseplayer(ply)
ply:SetMoveType(MOVETYPE_WALK )
ply:ConCommand("pp_motionblur 0")
end
function SWEP:SecondaryAttack()
if table.Count( taseredrags ) == 0 then return end
self.Owner:EmitSound( "Weapon_Pistol.Empty")
self.Owner:EmitSound( "Weapon_SMG1.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
--Debug Stuff
if !SERVER then return end
local printdebug
local d_Fired = false
local d_Spread = 100
local d_Firerate = 40
local d_Recharge = 116
local d_Iters = 2
--Combines the debug data ready for printing
hook.Add("Think", "debug_combine", function()
if d_Fired == false then
local SpreadAmount = 0
local TotalSpread = 0
local FiredBullets = 0
local TimeSpentRecharge = 0
local debugVer
SpreadAmount
Let me look for the max range code here, I have it somewhere in my LUA folder >.>
Alright, thank you. I see how cops are unable to catch up to people that are wanted and it ends up with the guy turning around and blasting you to bits. All I really care about is the max range of the shot, and the tasing actually being a projectile that hits them and tases, Not just an instant point, click.
Hey, While i'm at it, Does anyone know how to show if a player has a gun license? It will help Gun Dealers know if the person who wants a weapon actually has a license.
[QUOTE=serfma;31698054]Alright, thank you. I see how cops are unable to catch up to people that are wanted and it ends up with the guy turning around and blasting you to bits. All I really care about is the max range of the shot, and the tasing actually being a projectile that hits them and tases, Not just an instant point, click.
Hey, While i'm at it, Does anyone know how to show if a player has a gun license? It will help Gun Dealers know if the person who wants a weapon actually has a license.[/QUOTE]Should be a DarkRP Function, I can search for that too.. I can't find max range :(
[QUOTE=mikeym;31698092]Should be a DarkRP Function, I can search for that too.. I can't find max range :([/QUOTE]
Indeed, it is. But i've heard that it doesn't work anymore. Don't know why. Someone said they had to fix a lua file and it worked for them.
[QUOTE=serfma;31698152]Indeed, it is. But i've heard that it doesn't work anymore. Don't know why. Someone said they had to fix a lua file and it worked for them.[/QUOTE]Update DarkRP, then see... Last I know, it works on the latest version
[QUOTE=mikeym;31698170]Update DarkRP, then see... Last I know, it works on the latest version[/QUOTE]
No no, They said the latest version of DarkRP (SVN) Doesn't work with it. I'm using the latest SVN version too. The piece of paper doesn't show above a persons head.
[QUOTE=serfma;31698221]No no, They said the latest version of DarkRP (SVN) Doesn't work with it. I'm using the latest SVN version too. The piece of paper doesn't show above a persons head.[/QUOTE]It can't be hard to update, read around, find the error, fix it...
[QUOTE=mikeym;31698247]It can't be hard to update, read around, find the error, fix it...[/QUOTE]
Oh trust me, i've google'd everywhere, searched everywhere, etc. Found NOTHING. :S
Anyone have any ideas? Would be greately appreciated if you could help me out with this one. D:
I just fixed [url=http://code.google.com/p/darkrp/source/detail?r=886]the gun license thing for you.[/url]
(Yeah I got access to the DarkRP SVN today :dance:)
[QUOTE=Drakehawke;31699112]I just fixed [url=http://code.google.com/p/darkrp/source/detail?r=886]the gun license thing for you.[/url]
(Yeah I got access to the DarkRP SVN today :dance:)[/QUOTE]2 and a half years, no bans or thread closes... :D
Nice fix though >:D
[QUOTE=Drakehawke;31699112]I just fixed [url=http://code.google.com/p/darkrp/source/detail?r=886]the gun license thing for you.[/url]
(Yeah I got access to the DarkRP SVN today :dance:)[/QUOTE]
Awesome! Thanks a load.
I'm still needing to fix the Taser, I would do it my self but i'm not fluent in Lua. xD
[editline]13th August 2011[/editline]
Bump, Is it possible to re-code it to do the same thing but whenever a bullet hits a player? Such as tasing them when you damage a person
[B]Hello good sir,[/B]
We have a questions sub-forum located at: [url]http://www.facepunch.com/forums/337[/url]
Please post any Garrysmod Lua related questions in that subforum.
We also have a similar forum for any Requests.
Thank you.
For distance, simply add in something like:
[lua]
if self:GetPos():Distance( eyetrace.Entity:GetPos() ) > 200 then return end
[/lua]
Not sure about making it less accurate.
[QUOTE=Drakehawke;31707403]For distance, simply add in something like:
[lua]
if self:GetPos():Distance( eyetrace.Entity:GetPos() ) > 200 then return end
[/lua]
Not sure about making it less accurate.[/QUOTE]
Adding that in anywhere in the code 'destroys' the taser, completely dissapears until I remove it. o.O
Even in SWEP:PrimaryAttack?
[QUOTE=Drakehawke;31709531]Even in SWEP:PrimaryAttack?[/QUOTE]
When you add that code under 'local = eyetrace' right under the primary attack function, the weapon doesn't work at all.
[QUOTE=serfma;31709613]When you add that code under 'local = eyetrace' right under the primary attack function, the weapon doesn't work at all.[/QUOTE]
You need to add it after you've checked that eyetrace.Entity is a valid entity.
Sorry, you need to Log In to post a reply to this thread.