so I have this script which is suppose to freeze the grenades on the map so they do not fall this is what I have.
The error
[code]
[ERROR] lua/autorun/fixphys.lua:1: attempt to index global 'GM' (a nil value)
1. unknown - lua/autorun/fixphys.lua:1
[/code]
The Code I use in lua/autorun
[code]
function GM:OnEntityCreated( ent )
if prop:IsWeapon() then
phys = prop:GetPhysicsObject()
if phys:IsValid() then
phys:Sleep()
else
print("phys is false!")
end
end
end
[/code]
Can't find the error.
I am pretty sure auto-run files are added before the gamemode state is created, or after it is passed. Don't override core functions in addons, you also have an error in it ( Your arg is ent, but you use prop instead ); use
[lua]hook.Add( "OnEntityCreated", function( _ent )
if ( IsValid( _ent ) && _ent:IsWeapon( ) ) then
local _phys = _ent:GetPhysicsObject( );
if ( IsValid( _phys ) ) then
phys:Sleep( );
// Consider adding constraints
else
print( "phys is false!" );
end
end
end );[/lua]
Make it into a [URL="http://wiki.garrysmod.com/page/hook/Add"]hook[/URL]. Don't use GM functions for what you're trying to do.
Thanks!
Sorry, you need to Log In to post a reply to this thread.