Author Topic: Help with afk command  (Read 653 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 677
  • Karma: 34
    • View Profile
    • iViscosity Gaming
Help with afk command
« on: June 07, 2016, 02:17:05 PM »
I have a command that when someone uses it, it will put them in spectator mode. Right now I have:
Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2.  
  3.  
  4. function ulx.afk( calling_ply, should_afk )
  5.  
  6.  
  7.         if ( not should_afk ) then
  8.  
  9.  
  10.                 calling_ply:ConCommand( "ttt_spectator_mode 0" )
  11.                 ULib.tsay( calling_ply, "You have disabled spectator mode. You will return next round." )
  12.  
  13.  
  14.         elseif ( should_afk ) then
  15.  
  16.  
  17.                 calling_ply:ConCommand( "ttt_spectator_mode 1" )
  18.                 ULib.tsay( calling_ply, "You have enabled spectator mode." )
  19.  
  20.  
  21.         end
  22.        
  23. end
  24.  
  25.  
  26. local afk = ulx.command( CATEGORY_NAME, "ulx afk", ulx.afk, "!afk" )
  27. afk:defaultAccess( ULib.ACCESS_ALL )
  28. afk:help( "Set yourself to Spectator Mode." )
  29. afk:setOpposite( "ulx unafk", { _, _, 0 }, "!unafk" )


But no matter what I type, !afk or !unafk, it will always activates the "not should_afk" part.


Screenshot:





No errors, no nothing. Just that. I'm not good with setOpposite, what am I doing wrong here?




OT: When I'm on a listen server, do I have access to all commands even if I'm not in superadmin group?
« Last Edit: June 07, 2016, 02:18:45 PM by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

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 dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
    • View Profile
Re: Help with afk command
« Reply #1 on: June 07, 2016, 02:38:37 PM »
I'm pretty sure you only need one _ in set opposite. Why do you have should_afk in ()? Try getting rid of those. Using ! Instead of not can made your code more clear.

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 677
  • Karma: 34
    • View Profile
    • iViscosity Gaming
Re: Help with afk command
« Reply #2 on: June 07, 2016, 02:40:32 PM »
I've always used not and it's working on a command I just made recently. If I have only one _ in the setOpposite it tries to index target_ply as a number.

I mainly use the parentheses because JavaScript. I'm used to that and it works so not a big deal.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

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 dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
    • View Profile
Re: Help with afk command
« Reply #3 on: June 07, 2016, 03:01:52 PM »
You forgot to add a bool arg to the command. This should work:

Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2.  
  3. function ulx.afk( calling_ply, should_revoke )
  4.    
  5.  
  6.   if !should_revoke then
  7.  
  8.     calling_ply:ConCommand( "ttt_spectator_mode 0" )
  9.     ULib.tsay( calling_ply, "You have disabled spectator mode. You will return next round." )
  10.  
  11.   else
  12.  
  13.     calling_ply:ConCommand( "ttt_spectator_mode 1" )
  14.     ULib.tsay( calling_ply, "You have enabled spectator mode." )
  15.  
  16.   end
  17.  
  18. end
  19.  
  20.  
  21. local afk = ulx.command( CATEGORY_NAME,"ulx afk", ulx.afk, "!afk", true )
  22. afk:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  23. afk:defaultAccess( ULib.ACCESS_ALL )
  24. afk:help( "Set yourself to Spectator Mode." )
  25. afk:setOpposite("ulx unafk", { _, true }, "!unafk" )
  26.  

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 677
  • Karma: 34
    • View Profile
    • iViscosity Gaming
Re: Help with afk command
« Reply #4 on: June 07, 2016, 03:04:36 PM »
Ok, didn't know "true" could be in place of the 0.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

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 dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
    • View Profile
Re: Help with afk command
« Reply #5 on: June 07, 2016, 03:06:38 PM »
I don't really know what the true does, I just had it from another script. I believe the part you were missing was this:

afk:addParam{ type=ULib.cmds.BoolArg, invisible=true }

Offline Mr_Rippe

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Re: Help with afk command
« Reply #6 on: June 20, 2016, 03:40:36 PM »
I know this is necroing an old thread, but I'm curious: does this allow people to AFK others mid round? If not, what should be modified to allow inputting the parameter of the player's name?

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 677
  • Karma: 34
    • View Profile
    • iViscosity Gaming
Re: Help with afk command
« Reply #7 on: June 20, 2016, 03:57:24 PM »
This command lets you set only yourself to afk. You can go afk at any time.


Code: Lua
  1. function ulx.fspec( calling_ply, target_ply, should_revoke )
  2.  
  3.  
  4.   if should_revoke then
  5.    
  6.     target_ply:ConCommand( "ttt_spectator_mode 0" )
  7.     ulx.fancyLogAdmin( calling_ply, "#A has removed #T from Spectator-Only mode.", target_ply )
  8.  
  9.  
  10.   else
  11.  
  12.  
  13.     target_ply:ConCommand( "ttt_spectator_mode 1" )
  14.     ulx.fancyLogAdmin( calling_ply, "#A has forced #T to Spectator-Only mode.", target_ply )
  15.  
  16.  
  17.   end
  18.  
  19.  
  20. end
  21. local fspec = ulx.command( "Utility", "ulx fspec", ulx.fspec, "!fspec" )
  22. fspec:addParam{ type=ULib.cmds.PlayerArg, ULib.cmds.optional }
  23. fspec:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  24. fspec:help( "Sets a target into spectator mode." )
  25.  


This should work, if that's what you're looking for.
« Last Edit: September 13, 2016, 08:55:13 AM by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

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 allofmywutsteam

  • Full Member
  • ***
  • Posts: 133
  • Karma: 3
  • MNWO Owner
    • View Profile
    • Mo'nicas New World Order
Re: Help with afk command
« Reply #8 on: August 25, 2017, 09:37:12 PM »
Still learning here. I've used ulx afk (!afk) in the past, but now that'd ive added some of the same old ulx addons, I'm now NOT seeing ulx afk functioning, but now have to run fspec, which is cumbersome.

If I wanted to use ulx afk, is it as simple as changing the "ulx fspec" in your code to afk?

Edit: maybe i'll give this a try https://forums.ulyssesmod.net/index.php/topic,10011.msg51490.html#msg51490
« Last Edit: August 25, 2017, 09:39:13 PM by allofmywutsteam »
"Then Jesus said to his disciples, 'Whoever wants to be my disciple must deny themselves and take up their cross and follow me.'" - Matthew 16:24



MNWO: Steam | Discord | Website | Forums | Join Server