• Getting mass of object through model?
    8 replies, posted
Is there a way to get the mass of a prop through the model? For example, getting the mass of "models/props_borealis/bluebarrel001.mdl". I only ask due to wanting to make a custom spawn menu and wish to show the mass on each spawn icon, is this possible or am I getting ahead of myself... Any help is appreciated.
If you can parse the PHY file, eg "models/props_borealis/bluebarrel001.phy", you can get the mass. It's a binary file, so I'd recommend taking a look at it with a hex editor to determine the format.
Cheers for the information, how ever judging from what you've written I fear I just might be in over my head.
[QUOTE=NintendoEKS;41092262]Cheers for the information, how ever judging from what you've written I fear I just might be in over my head.[/QUOTE] If you are looking for hints for the file format, you may find some useful information in the C++ code in [url=https://facepunch.com/showthread.php?t=1242860]this project[/url].
If using Binary files and hex editors is over my head, I'm afraid scanning through C++ will merely <implode> what little knowledge remains in my head haha. Thank you though Jcw87.
I do this by, at initpostentity: 1. Create a propphysics 2. Assign model 3. Call PhysicsInit 4. Get mass 5. Repeat back to step 2. 6. Remove propphysics Then I just send the mass information to players on join. If you find out how to parse the .phy, that is probably a better idea.
Interesting concept Donkie, I'll see how I go in the morning. Eyes are sore for the night...
Bump, this should work. [code] -- Takes either the path to the model [.mdl file] or physics file [.phy] function MassFromPath( modelPath ) if not modelPath or modelPath == "" then return end modelPath = string.gsub( modelPath, "%.%w+$", ".phy" ) if not file.Exists( modelPath ) then return end local fileObj = file.Open( modelPath, "rb", "GAME" ) fileObj:Seek( fileObj:ReadLong() ) fileObj:Seek( fileObj:ReadLong() + fileObj:Tell() ) local strData = fileObj:Read( fileObj:Size() - fileObj:Tell() ) fileObj:Close() return tonumber( string.match( strData, [["mass" "(%d+%.?%d*)"]] ) ) end [/code]
The second my internet has been installed (moved houses), I am going to test the shit out of this. Your help is very much appreciated!
Sorry, you need to Log In to post a reply to this thread.