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

0 Members and 1 Guest are viewing this topic.

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 10
    • View Profile
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 »

Offline Gmods

  • Newbie
  • *
  • Posts: 43
  • Karma: 2
    • View Profile
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: 51
  • Karma: 10
    • View Profile
Re: SuperPowers - Set run speed and jump power of players.
« Reply #2 on: February 02, 2010, 02:24:10 PM »
Thank you!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • ****
  • Posts: 3262
  • Karma: 106
  • Project Specialist
    • View Profile
    • 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)
Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it - David Pogue

Offline RynO-SauruS

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

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • ****
  • Posts: 3262
  • Karma: 106
  • Project Specialist
    • View Profile
    • 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.
:)

Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it - David Pogue

Offline stanlee

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
    • 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: 51
  • Karma: 10
    • View Profile
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.

Offline stanlee

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
    • 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: 51
  • Karma: 10
    • View Profile
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 »

Offline Megiddo

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

Code: (lua) [Select]
local meta = FindMetaTable( "Player" )
--[[
Function: Player:GetUserGroup

This should have been included with garrysmod by default, so ULib is creating it for us.

Returns:

The group the player belongs to.

Revisions:

v2.40 - Initial.
]]
function meta:GetUserGroup()
return self:GetNetworkedString( "UserGroup" )
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.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” -Brian W. Kernighan
"I love working on my crappy code. it is crappy, but it is mine. I guess I could love other people's code, but it's like loving other people's children -- not quite the same as your own" -- Jeff Atwood
"Their tree came and found my tree!" -- Stickly Man!

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 10
    • View Profile
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) [Select]
lua_run for _,v in pairs(player.GetAll()) do if string.find(string.lower(v:Nick()), 'ryn') != nil then print("\""..v:GetNetworkedString("UserGroup").."\"") end endIt printed this:
""

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

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • ****
  • Posts: 3262
  • Karma: 106
  • Project Specialist
    • View Profile
    • 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.
Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it - David Pogue

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 10
    • View Profile
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?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • ****
  • Posts: 3488
  • Karma: 188
  • Project Lead
    • View Profile
Can't see anything that would make it not work without ULX/ULib (release or SVN).
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” -Brian W. Kernighan
"I love working on my crappy code. it is crappy, but it is mine. I guess I could love other people's code, but it's like loving other people's children -- not quite the same as your own" -- Jeff Atwood
"Their tree came and found my tree!" -- Stickly Man!