One of my sweps keeps showing a lua error about once a hour, randomly.
Here is the error:
[code][ERROR] addons/spas/lua/effects/rg_muzzle_grenade/init.lua:11: Tried to use a NULL entity!
1. GetOwner - [C]:-1
2. unknown - addons/spas/lua/effects/rg_muzzle_grenade/init.lua:11
[/code]
What dose 1. GetOwner - [C]:-1 mean? How can I fix this?? Here is line 11 in that file:
[code]local AddVel = self.WeaponEnt:GetOwner():GetVelocity()[/code]
right before that line, add:
[lua]
if ( !IsValid( self ) || !IsValid( self.WeaponEnt ) || !self.WeaponEnt.GetOwner || !IsValid( self.WeaponEnt:GetOwner( ) ) || !self.WeaponEnt:GetOwner( ).GetVelocity ) then return; end
[/lua]
Edit: actually, you said it was GetOwner which returned the nil, ok so the above line is overkill. It will work but technically all you need is:
[lua]// Checks to see if the SWEP is valid, then the weapon ent, makes sure the function exists to for GetOwner, then makes sure the Entity is Valid for the return of GetOwner - the GetVelocity above isn't needed. This can be shortened even more
if ( !IsValid( self ) || !IsValid( self.WeaponEnt ) || !self.WeaponEnt.GetOwner || !IsValid( self.WeaponEnt:GetOwner( ) ) then return; end
[/lua]
[lua]// UltraShort
if ( !IsValid( self.WeaponEnt ) || !self.WeaponEnt.GetOwner || !IsValid( self.WeaponEnt:GetOwner( ) ) then return; end
[/lua]
I thought it worked at first but now this keeps popping up.
[code]Lua Error: [ERROR] addons/spas/lua/weapons/weapon_real_spas/shared.lua:417: Tried to use a NULL entity! 1. MuzzleFlash - [C]:-1 2. CSShootBullet - addons/spas/lua/weapons/weapon_real_spas/shared.lua:417 3. RecoilPower - addons/spas/lua/weapons/weapon_real_spas/shared.lua:387 4. unknown - addons/spas/lua/weapons/weapon_real_spas/shared.lua:180
16:08:10 Lua Error: [ERROR] addons/spas/lua/weapons/weapon_real_spas/shared.lua:468: Tried to use a NULL entity! 1. SetNotSolid - [C]:-1 2. ResetDoor - addons/spas/lua/weapons/weapon_real_spas/shared.lua:468 3. unknown - addons/spas/lua/weapons/weapon_real_spas/shared.lua:490[/code]
Post the full code; I have to run out for a bit but I'll check it when I'm back. Something else must be going on....
Maybe someone else will be able to look at it before I'm back, if not I'll do it :-)
[QUOTE=Acecool;44374364]Post the full code; I have to run out for a bit but I'll check it when I'm back. Something else must be going on....
Maybe someone else will be able to look at it before I'm back, if not I'll do it :-)[/QUOTE]
Thanks for helping me man, here's the full code:
[code]
local h3 = {}
h3["channel"] = CHAN_WEAPON
h3["level"] = SNDLVL_GUNFIRE
h3["sound"] = "weapons/spas/spas12-1.wav"
h3["name"] = "Weapon_H3.Single"
h3["script"] = "scripts/sounds/hl2_game_sounds_weapons.txt"
local h31 = {}
h31["channel"] = CHAN_ITEM
h31["level"] = SNDLVL_NORM
h31["sound"] = "weapons/spas/m3_insertshell.wav"
h31["name"] = "Spas12.Insert"
h31["script"] = "scripts/sounds/hl2_game_sounds_weapons.txt"
h31["pitch"] = "95,105"
sound.Add(h31)
local h36 = {}
h36["channel"] = CHAN_ITEM
h36["level"] = SNDLVL_NORM
h36["sound"] = "weapons/spas/m3_pump.wav"
h36["name"] = "Spas12.Pump"
h36["script"] = "scripts/sounds/hl2_game_sounds_weapons.txt"
h36["pitch"] = "95,105"
sound.Add(h36)
sound.Add(h3)
-- CAN THE SHOTGUN DESTROY DOORS WITH THE BUCKSHOT ROUNDS? 1 = YES, 0 = NO
SWEP.DestroyDoor = 1
--------------------------------------------------------------------------
-- Read the weapon_real_base if you really want to know what each action does
/*---------------------------------------------------------*/
local HitImpact = function(attacker, tr, dmginfo)
local hit = EffectData()
hit:SetOrigin(tr.HitPos)
hit:SetNormal(tr.HitNormal)
hit:SetScale(20)
util.Effect("effect_hit", hit)
return true
end
/*---------------------------------------------------------*/
if (SERVER) then
AddCSLuaFile("shared.lua")
end
if (CLIENT) then
SWEP.PrintName = "SPAS-12"
SWEP.Author = "Buu342"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.IconLetter = "k"
SWEP.Purpose = "shooting things"
killicon.AddFont("weapon_spas_12", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ))
end
/*---------------------------------------------------------
Muzzle Effect + Shell Effect
---------------------------------------------------------*/
SWEP.MuzzleEffect = "rg_muzzle_grenade" -- This is an extra muzzleflash effect
-- Available muzzle effects: rg_muzzle_grenade, rg_muzzle_highcal, rg_muzzle_hmg, rg_muzzle_pistol, rg_muzzle_rifle, rg_muzzle_silenced, none
SWEP.ShellEffect = "rg_shelleject_shotgun" -- This is a shell ejection effect
-- Available shell eject effects: rg_shelleject, rg_shelleject_rifle, rg_shelleject_shotgun, none
SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
SWEP.ShellEjectAttachment = "2" -- Should be "2" for CSS models or "1" for hl2 models
SWEP.EjectDelay = 0.53
/*-------------------------------------------------------*/
local DoorSound = Sound("physics/wood/wood_box_impact_hard3.wav")
local ShotgunReloading
ShotgunReloading = false
SWEP.Instructions = "Buckshot Damage (Per buckshot lead): 9% \nSlug Damage (Per slug): 88% \nRecoil: 50% \nBuckshot Precision: 55% \nSlug Precision: 85% \nType: Pump-Action \n\nChange Mode: E + Right Click"
SWEP.Category = "SPAS12" -- For HAXORS: feel free to change this if you want this swep in a different category
SWEP.Base = "weapon_real_base_pistol"
SWEP.HoldType = "shotgun"
SWEP.Spawnable = true
SWEP.AdminSpawnable = false
SWEP.ViewModel = "models/weapons/v_spas12_shotgun.mdl"
SWEP.WorldModel = "models/weapons/w_spas12_shotgun.mdl"
SWEP.Primary.Sound = Sound("Weapon_H3.Single")
SWEP.Primary.Recoil = 5
SWEP.Primary.Damage = 20
SWEP.Primary.NumShots = 15
SWEP.Primary.Cone = 0.045
SWEP.Primary.ClipSize = 8
SWEP.Primary.Delay = 0.95
SWEP.Primary.DefaultClip = 40
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "buckshot"
SWEP.Primary.Force = 2000
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.IronSightsPos = Vector (2.8603, -1.2217, 0.8227)
SWEP.IronSightsAng = Vector (1.3197, 0.0305, -0.0001)
SWEP.RunArmOffset = Vector (3.8652, -2.8154, -0.3196)
SWEP.RunArmAngle = Vector (-13.4962, 29.1912, -4.9571)
SWEP.data = {}
SWEP.mode = "burst" -- Start with the buckshot rounds
SWEP.data.burst = {} -- Buckshot Rounds
SWEP.data.burst.Cone = 0.045 -- Cone of the buckshot rounds
SWEP.data.burst.NumShots = 12 -- 12 little leads
SWEP.data.burst.Damage = 9 -- Damage of a lead
SWEP.data.semi = {} -- Slug Rounds
SWEP.data.semi.Cone = 0.015 -- Cone of the slug rounds
SWEP.data.semi.NumShots = 1 -- 1 big lead
SWEP.data.semi.Damage = 88 -- Damage of the big lead
function SWEP:Initialize()
automode = false
end
/*---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
if self.Owner:KeyDown(IN_USE) then
if automode == false then
automode = true
self.Owner:PrintMessage( HUD_PRINTCENTER, "Automatic Mode" )
self.Weapon:SetNextSecondaryFire(CurTime() + 1)
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
timer.Simple(0.3, function() self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) end)
self.Primary.Delay = 0.4
self.Primary.Cone = 1
else
automode = false
self.Owner:PrintMessage( HUD_PRINTCENTER, "Pump Mode" )
self.Weapon:SetNextSecondaryFire(CurTime() + 1)
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
timer.Simple(0.3, function() self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) end)
self.Primary.Delay = 0.95
self.Primary.Cone = 0.045
end
elseif SERVER then
end
if !self.Owner:KeyDown(IN_USE) then
if not self:CanPrimaryAttack() or self.Owner:WaterLevel() > 2 then return end
-- If your gun have a problem or if you are under water, you'll not be able to fire
self.Reloadaftershoot = CurTime() + self.Primary.Delay
-- Set the reload after shoot to be not able to reload when firering
self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
-- Set next secondary fire after your fire delay
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
-- Set next primary fire after your fire delay
self.Weapon:EmitSound(self.Primary.Sound)
-- Emit the gun sound when you fire
self:RecoilPower()
self:TakePrimaryAmmo(1)
-- Take 1 ammo in you clip
if ((game.SinglePlayer() and SERVER) or CLIENT) then
self.Weapon:SetNetworkedFloat("LastShootTime", CurTime())
end
end
end
/*---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
if self.Owner:KeyDown(IN_USE) then
if self.mode == "semi" then
self.mode = "burst"
self.Owner:PrintMessage( HUD_PRINTCENTER, "Buckshot Rounds" )
self.Weapon:SetNextSecondaryFire(CurTime() + 1)
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
timer.Simple(0.3, function() self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) end)
else
self.mode = "semi"
self.Owner:PrintMessage( HUD_PRINTCENTER, "Slug Rounds" )
self.Weapon:SetNextSecondaryFire(CurTime() + 1)
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
timer.Simple(0.3, function() self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) end)
end
self.data[self.mode].Init(self)
elseif SERVER then
end
end
/*---------------------------------------------------------
Deploy
---------------------------------------------------------*/
function SWEP:Deploy()
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
-- Set the deploy animation when deploying
self:SetIronsights( false )
-- Set the ironsight mod to false
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
-- Set the next primary fire to 1 second after deploying
ShotgunReloadin
Following the stack all the way back to this:
timer.Simple(25, function() ResetDoor( trace.Entity, ent, 10) end )
And the other error is: self.Owner:MuzzleFlash() ? - it is more likely than not saying there's an error with self.Owner, but why that would error out, I'm not sure without running it. Where did you download it?
For the MuzzleFlash make sure that function exists before calling it. But, I'm not sure what's going on without running the code. A base is required for it it seems; where did you get it?
[QUOTE=Acecool;44409716]Following the stack all the way back to this:
timer.Simple(25, function() ResetDoor( trace.Entity, ent, 10) end )
And the other error is: self.Owner:MuzzleFlash() ? - it is more likely than not saying there's an error with self.Owner, but why that would error out, I'm not sure without running it. Where did you download it?
For the MuzzleFlash make sure that function exists before calling it. But, I'm not sure what's going on without running the code. A base is required for it it seems; where did you get it?[/QUOTE]
I got it from the steam workshop.
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=105979143[/url]
Sorry, you need to Log In to post a reply to this thread.