• Going insane with this script.
    1 replies, posted
[lua]UseSimpleSpace = true local planets = {} local ignoreents = { "point_brush", "logic_case", "func_door", "func_door_rotating", "prop_door_rotating" } local function IsSpaceMap() local mapname = string.lower( game.GetMap() ) local spacemaps = { "sb_", "sb3_", "galactic", "new_worlds", "solarsystem", "twinsuns", "spacefun", "spacebuild" } for k, v in pairs( spacemaps ) do if string.find( mapname, v ) then UseSimpleSpace = true break --This is a statement you don't see much. Basically I'm stopping the for loop right here. No point in going on. end end end hook.Add( "Initialize", "CheckSpaceMap", IsSpaceMap ); local function ToggleSpace( ply, args, cmd ) UseSimpleSpace = util.tobool( args[1] ) end concommand.Add( "togglesimplespace", ToggleSpace ) local function GravityToggle( ent, bool, exp ) --Just a little alias for readibility sake. local physobj = ent:GetPhysicsObject() if( bool == true ) then physobj:EnableGravity( true ) physobj:EnableDrag( true ) else if exp == 0 then physobj:EnableGravity( false ) physobj:EnableDrag( false ) else ent:SetGravity( exp ) physobj:EnableDrag( true ) end end end local function PlayerTest( ply, args, cmd ) GravityToggle( ply, util.tobool( args[1] ), tonumber( args[2] )) end concommand.Add( "testplayergravity", PlayerTest ) if UseSimpleSpace then local function AddAllPlanets() local planet = {} local allplanets = ents.FindByClass( "logic_case" ) local isplanet = false local radius = 0 local gravity = 0 for _, p in pairs ( allplanets ) do for k, v in pairs ( p:GetKeyValues() ) do if ( k == "Case01" and v == "planet" ) then isplanet = true end if (k == "Case02") then planet.radius = tonumber( v ) end if (k == "Case03") then planet.gravity = tonumber( v ) end end if isplanet then planet.position = p:GetPos() table.insert( planets, planet ) end end print( "Hey hey hey! SimpleSpace is initializing!" ) print( util.TableToKeyValues( planets ) ) end hook.Add( "InitPostEntity", "AddAllPlanets", AddAllPlanets ) local function GravityCheck() --I think there's a song or a band or something that goes by that name. local allents = ents.GetAll() for _,e in pairs ( allents ) do if( e:IsValid() and e:GetPhysicsObject():IsValid() and !e:IsWorld() and !table.HasValue( ignoreents, e ) and !e:IsPlayer() ) then for k, v in pairs ( planets ) do if e:GetPos():Distance( v.position ) > v.radius then GravityToggle( e, false, 0 ) else GravityToggle( e, true, 1 ) break end end end end end --hook.Add( "Think", "SimpleSpaceStuff", GravityCheck ) timer.Create("GravityCheck", 0.1, 0, GravityCheck ) end [/lua] So this little sonuva has kept me busy for this whole day. It's a "simple" spacebuild implementation I made because I hate LS and RD and all that crap. And so far, it works pretty well, except for one single fact. There's no gravity in planets, everything is flying. I've been looking into it for the past hour and I just can't figure why. I've even made stupid tests and stuff ( You can see on the script ), but nada. Help will be much appreciated.
PhysObj.EnableGravity does not seem to work for players (I would use it for entities though). I had a very similar problem just yesterday. Instead, use [b][url=wiki.garrysmod.com/?title=Entity.SetGravity]Entity.SetGravity [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and set the player's gravity to something like 0.0001 (setting it to zero is like setting it to 1). If you set the gravity that low, drag won't be a factor either. [editline]05:32PM[/editline] Also, with your testplayergravity, the order of the arguments to a concommand is ply,cmd,args, not ply,args,cmd.
Sorry, you need to Log In to post a reply to this thread.