• Null entity ? :P
    3 replies, posted
so here's the error that changes the playermodel of someone to a dog (the swep code is below) [ERROR] lua/weapons/animagus swep/shared.lua:391: Tried to use a NULL entity!   1. LookupSequence - [C]:-1    2. MorphToHuman - lua/weapons/animagus swep/shared.lua:391     3. unknown - lua/weapons/animagus swep/shared.lua:153 The code for the swep ----------------------------------------------------- if( SERVER ) then     AddCSLuaFile("shared.lua") end   SWEP.Base               = "weapon_base"   SWEP.Spawnable          = true SWEP.AdminSpawnable     = true   SWEP.ViewModel      = "models/weapons/c_arms_citizen.mdl" SWEP.WorldModel     = ""    SWEP.ViewModelFlip  = false SWEP.DrawCrosshair  = false             SWEP.Primary                = {}    SWEP.Primary.Damage         = 0                               SWEP.Primary.ClipSize       = -1        SWEP.Primary.Delay          = 0.5     SWEP.Primary.DefaultClip    = 1       SWEP.Primary.Automatic      = false        SWEP.Primary.Ammo           = "none"        SWEP.Secondary              = {} SWEP.Secondary.ClipSize     = -1            SWEP.Secondary.DefaultClip  = -1 SWEP.Secondary.Delay        = 2 SWEP.Secondary.Damage       = 0       SWEP.Secondary.Automatic    = false       SWEP.Secondary.Ammo         = "none"   SWEP.ReloadDelay    = 0 SWEP.AnimDelay      = 0 SWEP.AttackAnims    = {     "fists_left",     "fists_right"}   SWEP.PlayerModel    = nil SWEP.WerewolfModel  = "models/jwk987/animal/riley.mdl" SWEP.PlayerScale    = 1.0 SWEP.WerewolfScale  = 1.15 --Change the collision type of the werewolf   SWEP.HealthBonus    = 100 SWEP.HealAmount     = 1 SWEP.HealTimer      = 1 SWEP.HealId         = ""   SWEP.RunSpeed       = 500 SWEP.WalkSpeed      = 250 SWEP.SpeedModifier  = 1.0   SWEP.InfectChance   = 0.25 SWEP.InfectDuration = 12 -- 5 x 12 = 60 seconds until infection turns to werewolfisms SWEP.ToggleVFX      = false   if ( CLIENT ) then     SWEP.PrintName  = "Animagus Kopek"          SWEP.Category   = "Kuzgun HogwartsRP"     SWEP.Author     = "Lucifer Morningstar"     SWEP.Purpose    = "Bu yetenek ile köpek şeklini alabilirsin!"     SWEP.Slot       = 0                       SWEP.SlotPos    = 1     SWEP.DrawAmmo   = false end   function SWEP:Equip(owner)     self:RegeneratingHealth(owner)     timer.Simple(0.5, function()         if !IsValid(self) then return end         owner:SetActiveWeapon(self)     end) end   function SWEP:Holster()     local owner = self.Owner     if owner != nil then         self:MorphToHuman()     end     return true end   function SWEP:OnRemove()     self:RemoveSelf()     return true end   function SWEP:OnDrop()     self:RemoveSelf()     return true end   function SWEP:RemoveSelf()     local owner = self.Owner     if owner != nil then         self:MorphToHuman()     end         if !SERVER then return end     if timer.Exists(self.HealId) then timer.Remove( self.HealId ) return end     self:Remove() end   function SWEP:Reload()     if self.ReloadDelay > CurTime() then return end     if self.PlayerModel == nil then return end     self.ReloadDelay = CurTime() + 4     self.Weapon:SetNextPrimaryFire( CurTime() + 2.5 )     self.Weapon:SetNextSecondaryFire( CurTime() + 2.5 )       if game.MaxPlayers() < 2 then self.AnimDelay = CurTime() + 4     else self.AnimDelay = SysTime() + 4 end         local owner = self.Owner     if !owner:IsValid() then return end     if !owner:Alive() then return end         if owner:GetModel() != self.WerewolfModel     then self:MorphToWerewolf()     else self:MorphToHuman()     end end   function SWEP:SecondaryAttack()     self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )         if game.MaxPlayers() < 2 then self.AnimDelay = CurTime() + 0.45     else self.AnimDelay = SysTime() + 0.4 end         local owner = self.Owner     if !owner:IsValid() then return end     if !owner:Alive() then return end     if owner:GetModel() == self.PlayerModel then         self:Reload() return  end end   function SWEP:PrimaryAttack()     self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )         if game.MaxPlayers() < 2 then self.AnimDelay = CurTime() + self.Primary.Delay     else self.AnimDelay = SysTime() + self.Primary.Delay end         local owner = self.Owner     if !owner:IsValid() then return end     if !owner:Alive() then return end     if owner:GetModel() == self.PlayerModel then return end     end   ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------   function SWEP:MorphToWerewolf()     local owner = self.Owner     if self.PlayerModel == nil then return end     if owner:GetModel() == self.WerewolfModel then return end     owner:SetModelScale( self.WerewolfScale, 3 )     owner:SetModel( self.WerewolfModel )         if self.WerewolfScale > 1 then owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )     else owner:SetCollisionGroup( COLLISION_GROUP_NONE ) end           if !owner:IsValid() then return end     if !owner:Alive() then return end     self:SetHoldType( "knife" )     self:SendWeaponAnim(ACT_HL2MP_IDLE_KNIFE)         local vm = self.Owner:GetViewModel()     vm:ResetSequence( vm:LookupSequence( "fists_draw" ) ) end   function SWEP:MorphToHuman()     local owner = self.Owner     if owner == nil or !IsValid(self) then return end     if owner:GetModel() == self.PlayerModel then return end     owner:SetModelScale( self.PlayerScale, 3 )     if self.PlayerModel != nil then owner:SetModel( self.PlayerModel ) end         if self.PlayerScale > 1 then owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )     else owner:SetCollisionGroup( COLLISION_GROUP_NONE ) end       owner:SetRunSpeed(self.WalkSpeed)     owner:SetWalkSpeed(self.RunSpeed)       if !owner:IsValid() then return end     if !owner:Alive() then return end     self:SetHoldType( "normal" )     self:SendWeaponAnim(ACT_HL2MP_IDLE_KNIFE)         local vm = self.Owner:GetViewModel()     if CLIENT then vm:ResetSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) ) end     vm:ResetSequence( vm:LookupSequence( "fists_holster" ) ) end   ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------   function SWEP:RegeneratingHealth(owner)     local hp, maxhp         self.HealId  = math.random(165, 73623)     self.HealId = "EOTI_WEREWOLF_SWEP_"..self.HealId..owner:Name()         timer.Create(self.HealId , self.HealTimer, 0, function()         if !SERVER         or !self:IsValid()         or !timer.Exists( self.HealId )         then return end                 hp = owner:Health()         maxhp = (owner:GetMaxHealth() + self.HealthBonus or 100 + self.HealthBonus)         if maxhp < hp then return end         owner:SetHealth(math.Clamp( hp + self.HealAmount, 0, maxhp ))     end) end   function SWEP:Infection(dmg)     if !(math.random(0.01,1.00) >= self.InfectChance) then return end     if !dmg:IsValid() then return end     if !dmg:IsPlayer() then return end     if !dmg:Alive() then return end     if dmg:HasWeapon(self:GetClass()) then return end       local id, step, cnt, rgb     id = "WerewolfInfectionTimer_"..dmg:Name()     step = math.floor(230/self.InfectDuration)     if timer.Exists(id) then return end         cnt = 0     dmg:SetRenderMode( RENDERMODE_TRANSALPHA )     if SERVER then dmg:ChatPrint(""..(self.InfectDuration*5).." seconds.") end     dmg:EmitSound("eoti_idlegrowlloop", 350, math.random(23,40))         timer.Create(id, 5, self.InfectDuration, function()         if !self:IsValid()         or !dmg:IsValid()         or !dmg:IsPlayer()         or !dmg:Alive()         or dmg:HasWeapon(self:GetClass())         or !timer.Exists(id)         then             dmg:SetColor( Color(255,255,255) )             dmg:SetRenderMode( RENDERMODE_NORMAL )             timer.Destroy(id)             return false         end                     rgb = 255 - (cnt * step)         cnt = cnt + 1         dmg:SetColor( Color(rgb,rgb,rgb) )                 if cnt < self.InfectDuration then return end         if not SERVER and CLIENT then return end           dmg:StopSound("eoti_idlegrowlloop")         dmg:Give(self:GetClass())         dmg:SetColor( Color(255,255,255) )         dmg:SetRenderMode( RENDERMODE_NORMAL )         timer.Destroy(id)         return true     end) end   function SWEP:Think()     local t     if game.MaxPlayers() < 2 then t = CurTime()     else t = SysTime() end     if self.AnimDelay > t then return true end         local owner, primary     owner = self.Owner     primary = (self:GetNextPrimaryFire() - CurTime())         if self.PlayerModel == nil then         self.PlayerModel = ""..self.Owner:GetModel()         self.PlayerScale = self.Owner:GetModelScale() or 1         self.WerewolfScale = self.PlayerScale * 1.0         self.WalkSpeed = owner:GetWalkSpeed()         self.RunSpeed = owner:GetRunSpeed()         return true     elseif owner:KeyDown(IN_USE) then         self.ToggleVFX = !self.ToggleVFX         if CLIENT then surface.PlaySound("UI/buttonclick.wav") end         self.AnimDelay = t + 0.5         return true     elseif owner:GetModel() == self.PlayerModel then         owner:SetRunSpeed(self.RunSpeed)         owner:SetWalkSpeed(self.WalkSpeed)         self.AnimDelay = t + 0.45         return true     elseif owner:KeyDown(IN_FORWARD) and !owner:KeyDown(IN_DUCK) then         owner:SetRunSpeed(math.Clamp(self.RunSpeed*self.SpeedModifier, 450, 1000))         owner:SetWalkSpeed(math.Clamp(self.WalkSpeed*self.SpeedModifier, 375, 1000))         owner:DoAnimationEvent(ACT_HL2MP_RUN_ZOMBIE_FAST)         self.AnimDelay = t + 0.4         return false     elseif t + primary > t then         self.AnimDelay = primary + 0.05         return true     end     self.AnimDelay = t + 0.5 end
Check if the viewmodel actually exists before trying to play animations on it. Also, what is with the spaces everywhere dude?
i have a hard time seeing bulked text so its easy for me to separate them like that with spaces :P ps : is there a gmod wiki page that i can relate to for what you said
IsValid local vm = self.Owner:GetViewModel() if IsValid(vm) then vm:ResetSequence( vm:LookupSequence( "fists_draw" ) ) end
Sorry, you need to Log In to post a reply to this thread.