I searched, found no answers.
I fiddled around with other addons, trying my own stuff
for about an hour, and I can't figure it out.
When someone spawns a prop, I want to get the mass of that prop.
But nothing works.
[lua]
function GM:OnEntityCreated( prop )
if prop:GetClass() == "prop_physics" then
mass = prop:GetPhysicsObject():GetMass()
Msg(mass)
end end
[/lua]
I get this error:
[lua] [@gamemodes\ \gamemode\init.lua:???] Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)(Hook: OnEntityCreated) [/lua]
You forgot an end and you are not doing anything with the mass variable.
I erased some of my unneeded code to post here (I also tested removing it in game, and I still get the error) Oh, and I know I forgot an end.
Untested:
[lua]
function GM:OnEntityCreated( prop )
if prop:GetClass() == "prop_physics" then
if prop:GetPhysicsObject():IsValid() then --check if the physics object is valid
phys = prop:GetPhysicsObject()
Msg(phys:GetMass() .. "\n")
end
end
end
[/lua]
-snip-
That worked, thunder. Except all props have the same mass. D:
[lua] function GM:OnEntityCreated( prop )
if prop:GetClass() == "prop_physics" then
if prop:GetPhysicsObject():IsValid() then
phys = prop:GetPhysicsObject()
Mass=phys:GetMass()
Msg(Mass)
end
prop:SetNWFloat("PropHealth",50+Mass )
end end
[/lua]
I have no idea what cold cause props having all the same mass try to do
prop:SetNWFloat("PropHealth", 50+phys:GetMass())
Sorry, you need to Log In to post a reply to this thread.