• Print

Author Topic: SuperPowers - Set run speed and jump power of players. Update! (v1.1, SVN only)  (Read 37215 times)

0 Members and 1 Guest are viewing this topic.

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
SuperPowers is an addon for ULX that adds two commands, 'ulx runspeed', and 'ulx jumppower'.
'ulx runspeed' sets the run speed of the specified players to the specified number.

Usage:
ulx runspeed <player(s)> <run speed>
('ulx runspeed ^ 2000' would make you run extremely fast.)


'ulx jumppower' sets the jump power of the specified players to the specified number.

Usage:
ulx jumppower <player(s)> <jump power>
('ulx jumppower ^ 2000' would make you jump like The Incredible Hulk.)


I've attached versions for both non-SVN and SVN versions of ULX/ULib.

Installation:
Extract to addons.


Thanks to JamminR for the name.

EDIT:
Update! Version 1.1, added ability to set runspeed/jumppower based on usergroup of players.
This version is for ULX SVN only, because the old 'release' version of ULib is missing a function I need. (This is still being looked into)
I attached the new one and kept the old one incase you don't need this.

To set the runspeed for a certain group, put ulx_runspeed_<groupname> <speed> in your server.cfg file. (Works for custom groups too.  ;))
Do the same for jumppower, only put jumppower instead of runspeed.
Here are examples of how this is done, including all default groups (Zero or less disables auto-set):

ulx_runspeed_superadmin "1000"
ulx_runspeed_admin "1000"
ulx_runspeed_user "0"
ulx_runspeed_operator "0"

ulx_jumppower_superadmin "500"
ulx_jumppower_admin "500"
ulx_jumppower_user "0"
ulx_jumppower_operator "0"

« Last Edit: February 23, 2010, 04:43:27 pm by RynO-SauruS »


YouTube music player by RynO-SauruS

Offline Gmods

  • Newbie
  • *
  • Posts: 43
  • Karma: 2
Re: SuperPowers - Set run speed and jump power of players.
« Reply #1 on: February 02, 2010, 12:46:55 pm »
I really like your releases RynO. Simple ideas but very handy. I'll be adding this to both my servers, thanks!

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
Re: SuperPowers - Set run speed and jump power of players.
« Reply #2 on: February 02, 2010, 02:24:10 pm »
Thank you!


YouTube music player by RynO-SauruS

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: SuperPowers - Set run speed and jump power of players.
« Reply #3 on: February 02, 2010, 03:26:28 pm »
Ha! I only gave some suggestions as to the name. No credit necessary. ;P
Ryno-Saurus's releases have been T-rex-iffic
(Sorry, couldn't resist)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
Re: SuperPowers - Set run speed and jump power of players.
« Reply #4 on: February 02, 2010, 03:56:00 pm »
Thanks!  ;D


YouTube music player by RynO-SauruS

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: SuperPowers - Set run speed and jump power of players.
« Reply #5 on: February 15, 2010, 07:46:52 pm »
Just looked over the SVN version code and have a programmer's tip.
Returning true, or actually using return at all for these specific functions, isn't necessary.
:)

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

Offline stanlee

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • XtremeServerGaming
Re: SuperPowers - Set run speed and jump power of players.
« Reply #6 on: February 20, 2010, 05:32:28 pm »
RynO, could you make this set the values of jump/speed for certain usergroups?
This would really be useful for the premium members of my roleplay server.
I could just set the group "Premium" to a higher jump/speed.
You get what I mean  8)

Anyways, this is a great addon!
ADD ME ON STEAM:   sirusmaximu
I'm always in the need of good lua coders!

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
Re: SuperPowers - Set run speed and jump power of players.
« Reply #7 on: February 20, 2010, 07:12:10 pm »
Thanks for the compliment. I think UTeam has the ability to set the run speed based on usergroup, but I don't know if it can set the jump power..
Changing SuperPowers to set them based on usergroups might require code for reading settings from a text table like UTeam does with UTeam.txt, which I've never done before.
I might look into it.


YouTube music player by RynO-SauruS

Offline stanlee

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • XtremeServerGaming
Re: SuperPowers - Set run speed and jump power of players.
« Reply #8 on: February 21, 2010, 06:56:28 am »
Thanks for the compliment. I think UTeam has the ability to set the run speed based on usergroup, but I don't know if it can set the jump power..
Changing SuperPowers to set them based on usergroups might require code for reading settings from a text table like UTeam does with UTeam.txt, which I've never done before.
I might look into it.

Do it do it!!
:D
ADD ME ON STEAM:   sirusmaximu
I'm always in the need of good lua coders!

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
Re: SuperPowers - Set run speed and jump power of players.
« Reply #9 on: February 23, 2010, 04:26:46 pm »
Ok, about the 'auto-set runspeed/jumppower by usergroup' thing. I've actually written a working one of the SVN version, it creates CVARs for every group like this (it will create them for custom groups, too.  ;)):

ulx_runspeed_superadmin
ulx_runspeed_admin
ulx_runspeed_user
ulx_runspeed_operator

ulx_jumppower_superadmin
ulx_jumppower_admin
ulx_jumppower_user
ulx_jumppower_operator

And if you set these greater than zero, and a player belongs to the right usergroup, it will set their runspeed or jumppower accordingly, on their FIRST spawn.
If you change these during gameplay, the player will have to reconnect or change it manually via !runspeed or !jumppower.
I made it like this so if a person wants to have a different runspeed or jumppower than the default for their group, they can use the regular command to
change it manually, and it won't reset when they die. The problem is, I need the function Player:GetUserGroup() for this to work,
and only the SVN version has this function! (it doesn't come with gmod either)
The way this works is, I hook into PlayerInitialSpawn and retrieve what's stored in the CVAR for whatever usergroup they're in.
To make a version of this for non-SVN, I need some other method of doing this without Player:GetUserGroup().. *looks at JamminR and Megiddo*
I guess I'll go ahead and upload the one I made for SVN ULX/ULib..

Oh, by the way JamminR, thanks for the developers tip, I removed 'return true'.  ;)
« Last Edit: February 23, 2010, 04:46:12 pm by RynO-SauruS »


YouTube music player by RynO-SauruS

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
I'd suggest just ripping the function out and implementing it yourself, it's only one line of code:

Code: Lua
  1. local meta = FindMetaTable( "Player" )
  2. --[[
  3.         Function: Player:GetUserGroup
  4.        
  5.         This should have been included with garrysmod by default, so ULib is creating it for us.
  6.        
  7.         Returns:
  8.        
  9.                 The group the player belongs to.
  10.                
  11.         Revisions:
  12.        
  13.                 v2.40 - Initial.
  14. ]]
  15. function meta:GetUserGroup()
  16.         return self:GetNetworkedString( "UserGroup" )
  17. end

It's hackish code, I admit, but that's the advantage of hiding it behind a function: Next time garry breaks it, we can change it easily.
Experiencing God's grace one day at a time.

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
I guess I should have mentioned I tried that, it seems to just return blank. I'll try it again with lua_run.

Edit:
Tried it again, returns blank. The code I used:
Code: Lua
  1. lua_run for _,v in pairs(player.GetAll()) do if string.find(string.lower(v:Nick()), 'ryn') != nil then print("\""..v:GetNetworkedString("UserGroup").."\"") end end
It printed this:
""

(Blank)  :(
« Last Edit: February 23, 2010, 05:47:17 pm by RynO-SauruS »


YouTube music player by RynO-SauruS

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Did you run that from your server console?
Worked for me in both single player and my dev ded server.
Returned "superadmin"

Another programmers tip - ipairs is more efficient (when it can be used, I forget exactly when.)
It works in this instance.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
I did it in a listen server, with the release ULib and ULX installed. You probably did it with SVN ULX/ULib. I'll try that. From the looks of it, it works when used
with the SVN version installed, but not the release version. Is there maybe some change that was made to make this work?


YouTube music player by RynO-SauruS

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Can't see anything that would make it not work without ULX/ULib (release or SVN).
Experiencing God's grace one day at a time.

  • Print