G'day, I started a thread with a few questions a day or two ago. All problems solved except an issue I had with a Taser SWEP. If the player that has fired a taser dies or DC's, the tasered player is never revived. Any suggestions are always appreciated! Here is the code (it's quite long):
[CODE]if ( SERVER ) then
AddCSLuaFile( "shared.lua" )
SWEP.Weight = 2
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true
SWEP.HoldType = "pistol"
SWEP.Category = "Taser"
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
end
if ( CLIENT ) then
SWEP.PrintName = "Taser";
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
SWEP.Category = "Taser"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
end
SWEP.Author = "Emmemad";
SWEP.Contact = "";
SWEP.Purpose = "Tasering";
SWEP.Instructions = "Left click to bring down.";
//SWEP.Spawnable = true
//SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "357"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""
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:tasePlayer(eyetrace.Entity) // If the it is a player then bring them down tranqPlayer()
end
if eyetrace.Entity:IsNPC() then
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, function() self:taserevive(rag) end) ---------------------------------------------
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())
-- 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
[/CODE]
Dumb? How did was the post dumb? I was asking the community if they could help me fix a serious bug with an SWEP.
[QUOTE=Aura1;41192965]Dumb? How did was the post dumb? I was asking the community if they could help me fix a serious bug with an SWEP.[/QUOTE]
For 2 reasons really.
First of all, [URL="http://facepunch.com/showthread.php?t=1254727"]this[/URL] thread exists for the sole purpose of converting/fixing addons. Or even more appropriately, you could go to the [URL="http://facepunch.com/showthread.php?t=1269027"]LUA Scripter Hire Thread[/URL] or even the newly revived [URL="http://coderhire.com/"]CoderHire[/URL] website.
Last but certainly not least, if you actually read the sticky you would see this..
[QUOTE=garry;39737459]Do not post huge scripts and expect people to fix them. If you wrote the script then you should know why it doesn't work. If you're editing someone's script and can't get it to work then don't! Learn how to code![/QUOTE]
In short, literally any option would have been better than pasting the whole code here asking for someone to fix it for you.
Hey, this looks familiar.
[url]http://facepunch.com/showthread.php?t=1276691[/url]
Yep. If you would look, someone posted the same thread with the same issue. And I even provided a fix.
[url]http://facepunch.com/showthread.php?t=1276691&p=41131970&viewfull=1#post41131970[/url]
Don't expect anyone to do it for you.
Sorry, you need to Log In to post a reply to this thread.