Author Topic: Gravity  (Read 5119 times)

0 Members and 1 Guest are viewing this topic.

Offline Donkie

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Gravity
« on: August 22, 2009, 07:51:26 AM »
Hello folks! I have made a !gravity command :D
Its very simple, i took the code from !hp and changed it abit.
Syntax is: !gravity <user> <gravity amount>
Note that i have multiplyed the gravity amount by 600 so 600 is default.

Just copy/paste this code snippet to the end of your ulx/lua/ulx/modules/fun.lua and you are good to go :D
Code: [Select]
function ulx.cc_gravity( ply, command, argv, args )
if #argv < 1 then
ULib.tsay( ply, ulx.LOW_ARGS, true )
return
end

local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords
if not targets then
ULib.tsay( ply, err, true )
return
end

local gravity = tonumber( argv[ 2 ] )
if not gravity then
ULib.tsay( ply, "\"" .. argv[ 2 ] .. "\" is an invalid amount!", true )
return
end

if gravity >= 2000 then
ULib.tsay( ply, "Sorry, you cannot set players' gravity to 2,000 or more.", true )
return
end

if gravity < 0.001 then
ULib.tsay( ply, "Sorry, you cannot set players' gravity to less than 0.001.", true )
return
end

for _, v in ipairs( targets ) do
ulx.logUserAct( ply, v, "#A set #T's gravity to " .. gravity )
v:SetGravity( gravity/600 )
end
end
ulx.concommand( "gravity", ulx.cc_gravity, "<user(s)> - sets the gravity for the specified users. 600 is default", ULib.ACCESS_ADMIN, "!gravity", _, ulx.ID_PLAYER_HELP )
« Last Edit: December 06, 2009, 02:34:29 AM by Donkie »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Gravity
« Reply #1 on: August 22, 2009, 10:56:31 AM »
Interesting idea. I thought server liimit for gravity couldn't be overwritten. Guess this may have changed due to gamemode ideas for players.
Why do you multiply the number input by 600?
If server/player default is 600, and I want to raise it to 800, how would taking 600*800 make it 800?

Also, your code chat command makes someone have to type !gravityqqq in the chat box.
Was that intended?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Donkie

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Gravity
« Reply #2 on: August 22, 2009, 12:55:02 PM »
<censor>, i had garrysmod running and i need to hold Q to tab out, made it fail obviously. Also, the SetGravity command has a 1 to normal gravity and 0 to zero gravity, therefor i multiplyed it by 600 to make it like real garrysmod gravity.

http://wiki.garrysmod.com/?title=Entity.SetGravity
Taken from the link:
0 is no gravity, 1 is full gravity.
« Last Edit: August 22, 2009, 01:36:29 PM by JamminR »

Offline Donkie

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Gravity
« Reply #3 on: August 22, 2009, 01:44:22 PM »
Tbh, the *600 made it fail and you cant reset to your old gravity, let it just be at 1 :3

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Gravity
« Reply #4 on: August 22, 2009, 01:54:04 PM »
Ok.. might want to tweak the math a bit more then?
According the the setgravity page, "is a fraction of the server-wide gravity"
If I enter a gravity number 1 to 2000, and you multiply it by 600, won't that number always be more than 1?

Find a way to use between 1 and 100, make the user type it in understanding that, for example, ulx gravity <player> 50 is 50% of the server gravity. Use math to change the actual number from a real to percentage... have that decimal percentage applied to set gravity.
According to the setgravity command, you shouldn't have to multiply anything.
Make it a decimal 0 to 1, and you've got it set.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Donkie

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Gravity
« Reply #5 on: September 05, 2009, 07:14:55 AM »
Updated main post, added /600 after the setGravity, you now write a value between 0.001 and 1200.
600 is default.