• Print

Author Topic: Not sure what's wrong  (Read 4348 times)

0 Members and 1 Guest are viewing this topic.

Offline wayzata20

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Not sure what's wrong
« on: May 16, 2015, 09:35:46 am »
So, I have the following code for double jumping. I want only the Owner and eventually a few other ranks to be able to double jump, but it is not working and I have no idea what is wrong. Can someone tell me what needs to be fixed?

Code: Lua
  1. local special = {"Owner"}
  2. local steamid = data.networkid
  3. local userid = data.userid
  4. local group = ULib.ucl.getUserInfoFromID(steamid)
  5. if table.HasValue(special, group.group) then
  6.     hook.Add("KeyPress", "DoubleJump", function(pl, k)
  7. if not pl or not pl:IsValid() or k~=2 then
  8.         return
  9. end
  10.                
  11. if not pl.Jumps or pl:IsOnGround() then
  12.         pl.Jumps=0
  13. end
  14.        
  15. if pl.Jumps==2 then return end
  16.        
  17. pl.Jumps = pl.Jumps + 1
  18. if pl.Jumps==2 then
  19.         local ang = pl:GetAngles()
  20.         local forward, right = ang:Forward(), ang:Right()
  21.                
  22.         local vel = -1 * pl:GetVelocity()
  23.         vel = vel + Vector(0, 0, 300)
  24.                
  25.         local spd = pl:GetMaxSpeed()
  26.                
  27.         if pl:KeyDown(IN_FORWARD) then
  28.                 vel = vel + forward * spd
  29.         elseif pl:KeyDown(IN_BACK) then
  30.                 vel = vel - forward * spd
  31.         end
  32.                
  33.         if pl:KeyDown(IN_MOVERIGHT) then
  34.                 vel = vel + right * spd
  35.         elseif pl:KeyDown(IN_MOVELEFT) then
  36.                 vel = vel - right * spd
  37.         end
  38.                
  39.         pl:SetVelocity(vel)
  40.     end
  41. end)
  42. if not table.HasValue(special, group.group) then      
  43.         end
  44. end

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Not sure what's wrong
« Reply #1 on: May 16, 2015, 04:10:30 pm »
Is this all the code?
You would need to have some kind of movement hook to process this.

Also, why are you choosing to use ULib.ucl.getUserInfoFromID for this? That is really only useful for getting information for offline players.

You should be using http://wiki.garrysmod.com/page/Player/GetUserGroup

Offline wayzata20

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Not sure what's wrong
« Reply #2 on: May 16, 2015, 06:48:53 pm »
That was all the code, but I changed the group code to the Player:GetUserGroup(), but it still doesn't work. I am new to Lua, so it it something simple that I am missing?
Code: Lua
  1. hook.Add("KeyPress", "DoubleJump", function(pl, k)
  2. if Player:GetUserGroup() == "Owner" then
  3.     if not pl or not pl:IsValid() or k~=2 then
  4.         return
  5.     end
  6.                
  7.     if not pl.Jumps or pl:IsOnGround() then
  8.         pl.Jumps=0
  9.     end
  10.        
  11.     if pl.Jumps==2 then return end
  12.        
  13.     pl.Jumps = pl.Jumps + 1
  14.     if pl.Jumps==2 then
  15.         local ang = pl:GetAngles()
  16.         local forward, right = ang:Forward(), ang:Right()
  17.                
  18.         local vel = -1 * pl:GetVelocity()
  19.         vel = vel + Vector(0, 0, 300)
  20.                
  21.         local spd = pl:GetMaxSpeed()
  22.                
  23.         if pl:KeyDown(IN_FORWARD) then
  24.             vel = vel + forward * spd
  25.         elseif pl:KeyDown(IN_BACK) then
  26.             vel = vel - forward * spd
  27.         end
  28.                
  29.         if pl:KeyDown(IN_MOVERIGHT) then
  30.             vel = vel + right * spd                                
  31.         elseif pl:KeyDown(IN_MOVELEFT) then
  32.             vel = vel - right * spd
  33.         end
  34.                
  35.         pl:SetVelocity(vel)
  36.     end
  37. end)
  38. if not Player:GetUserGroup() == "Owner" then      
  39.         end
  40. end

  • Print