(Again) Strange GetMass Error

Ok, I’ve asked a bunch of people, looked at other peoples code,
and they all do, and say the samething.

Yet, I’m getting errors when I do it.


function GM:OnEntityCreated( prop )

if ( prop:GetClass() == “prop_physics” ) && prop:GetPhysicsObject():IsValid() then
prop:SetNWFloat(“PropHealth”,5+prop:GetPhysicsObject():GetMass()) end end


The health of the prop is 0. because the mass is invalid.
Without checking if it’s valid,
I get this lua error.
[@gamemodes####\gamemode\shared.lua:40] Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)(Hook: OnEntityCreated)

But yet, this works:
function GetMass(ply)
local tr = ply:GetEyeTrace()
if not tr.Entity then return end
ply:PrintMessage(HUD_PRINTTALK, tr.Entity:GetPhysicsObject():GetMass())
–ply:PrintMessage(HUD_PRINTTALK, tr.Entity:GetPhysicsObject():GetVolume())

[/lua] (from the wiki)

So yeah. I’ve asked a bunch of people, examined others’ coding, I just don’t get it.

I don’t know if I should have made a new thread or not, if so, sorry.

If I understood correctly, you should add a small timer in the OnEntityCreated hook, since it seems something’s fucked up with the prop on the moment of creation.

Freggin’ wow, I figured it would be something stupid simple,
Ima test that later when I have a chance. Thanks a lot, duud.