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.
[lua]
function GM:OnEntityCreated( prop )
if ( prop:GetClass() == "prop_physics" ) && prop:GetPhysicsObject():IsValid() then
prop:SetNWFloat("PropHealth",5+prop:GetPhysicsObject():GetMass()) end end
[/lua]
The health of the prop is 0. because the mass is invalid.
Without checking if it's valid,
I get this lua error.
[lua]
[@gamemodes\####\gamemode\shared.lua:40] Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)(Hook: OnEntityCreated)
[/lua]
But yet, this works:
[lua]
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())
end
concommand.Add("get_mass",GetMass)
[/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.
Sorry, you need to Log In to post a reply to this thread.