Author Topic: I need a bit of help with a Custom Auto-Hop command  (Read 407 times)

0 Members and 1 Guest are viewing this topic.

Offline Kowalski

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
I need a bit of help with a Custom Auto-Hop command
« on: February 12, 2018, 04:54:48 PM »
I've been trying to find any sort of a bunny hop command for ULX, but to no avail, so I thought I could make my own, I attempted to do it with this code:
Code: Lua
  1. function ulx.bhop( calling_ply, target_ply, amount)
  2.         for i=1, #target_ply do
  3.                 if target_ply():IsOnGround() and target_ply:KeyDown( IN_JUMP ) then
  4.                         target_ply:SendLua([[RunConsoleCommand("+jump")]])
  5.                         timer.simple(0.2, function() target_ply:SendLua([[RunConsoleCommand("-jump")]]) end)
  6.                 end
  7.         end
  8.         ulx.fancyLogAdmin( calling_ply, "#A enabled Sick-Hops on #T", target_ply, amount )
  9. end
  10. local bhop = ulx.command( "Fun", "ulx bhop", ulx.bhop, "!bhop" )
  11. bhop:addParam{ type=ULib.cmds.PlayerArg }
  12. bhop:addParam{ type=ULib.cmds.NumArg, min=0, max=1, hint="1 is on, 0 is off", ULib.cmds.round }
  13. bhop:defaultAccess( ULib.ACCESS_ALL )
  14. bhop:help( "Enables Auto Hop on the target." )
I referenced the "ulx.hp" or the HP command to get some sort of guide on how to find a player target and on setting a value(0, 255).
I'd like to only work if the player is holding their jump button as well.
This does not work sadly, I was wondering if I could get some assistance and possibly some pointers on what I did wrong?

I see someone else is also requesting the same thing, a fix on there could also help me just as well.
« Last Edit: February 12, 2018, 05:06:06 PM by Kowalski »

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 780
  • Karma: 51
Re: I need a bit of help with a Custom Auto-Hop command
« Reply #1 on: February 12, 2018, 05:51:44 PM »
Be sure that when you say something "does not work", you say both it's intended response (even if your question implies it) and what the expected response is (again, even if it's implied). Also be sure to say any errors you may be getting.

There's one thing with it, when you use this command on someone it will only do anything if, at that moment, they are holding down their jump key and are on the ground. You'd need something that does this at any time. (Also you have a param of "ULib.cmds.PlayerArg" when your code suggests that it should be "ULib.cmds.PlayersArg" (due to the #target_ply))

Another thing is that clientside logic takes precedence over serverside logic. For example, you telling the client to +jump can be overridden by a client's +jump. Also even if they jump, your -jump immediately just makes them stop. Overall, your code does nothing but makes the person jump.

Code: Lua
  1. function ulx.bhop( calling_ply, target_ply, should_bhop )
  2.     target_ply:SetNWBool( "bhop", should_bhop ) -- A networked bool allows you to access values on a specific player.
  3.     ulx.fancyLogAdmin( calling_ply, "#A enabled Sick-Hops on #T", target_ply ) -- You have the "amount" in your fancyLogAdmin(), which is not necessary.
  4. end
  5. local bhop = ulx.command( "Fun", "ulx bhop", ulx.bhop, "!bhop" )
  6. bhop:addParam{ type = ULib.cmds.PlayerArg }
  7. bhop:addParam{ type = ULib.cmds.BoolArg, invisible = true }
  8. bhop:defaultAccess( ULib.ACCESS_ALL ) -- I don't recommend this because this allows anyone to target anyone else (that their inheritance lets them)
  9. bhop:setOpposite( "ulx unbhop", { _, _, false }, "!unbhop" )
  10. bhop:help( "Enables Auto Hop on the target" )

And now you need something on the client to edit how a player moves. The best way to do this is by using GM:CreateMove. Now I'd recommend making the bhop key something that isn't their IN_JUMP key. This is because of what I said earlier: their logic will override CreateMove's logic, even if it's clientside. According to the CreateMove wiki:
Code: [Select]
Due to this hook being clientside only, it could be overridden by the user allowing them to completely skip your logic, it is recommended to use GM:StartCommand in a shared file instead.
Now, if you use something that isn't IN_JUMP, you don't have to worry about this.
For example:
Code: Lua
  1. if ( CLIENT ) then -- Put this in the same file as ulx.bhop() so you can do this
  2.     hook.Add( "CreateMove", "bhop", function( ucmd )
  3.         local ply = LocalPlayer() -- Just easier.
  4.         if ply:GetNWBool( "bhop" ) and ply:GetNWBool( "bhop" ) == true --[[ not necessary, but for more readability ]] and IsValid( ply ) and bit.band( ucmd:GetButtons(), IN_DUCK ) > 0 then -- bit.band performs bitwise "and" on GetButtons() and IN_DUCK (so basically, checks if IN_DUCK (their duck) is being performed).
  5.             if ply:OnGround() then -- If they're not on the ground, don't do anything
  6.                 ucmd:SetButtons( bit.bor( ucmd:GetButtons(), IN_JUMP ) ) -- Performs bitwise "or" on GetButtons() and IN_JUMP. Basically, sets their status to either crouch (IN_DUCK) or jump (IN_JUMP).
  7.             end
  8.         end
  9.     end )
  10. end

Sorry I kinda wrote it for you, I tried to comment it so you'd understand what it was, but that should work (it's actually taken from a separate addon I wrote that had this exact thing in it). Basically, you need something that is globally accessible, and actually does something after it ends the jump.
« Last Edit: February 12, 2018, 05:57:51 PM by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam Group (feel free to join!)

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline Kowalski

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: I need a bit of help with a Custom Auto-Hop command
« Reply #2 on: February 12, 2018, 06:21:04 PM »
Alright thanks! I might see if I can find a button that isn't used by default and isn't annoying to reach for to use the bunny-hop, some people don't like bunny-hopping while always crouched.\
Many thanks for the help and comments, hopefully I'll be able to work on some more stuff!