• Print

Author Topic: Need help, again.  (Read 11095 times)

0 Members and 1 Guest are viewing this topic.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Need help, again.
« on: July 29, 2016, 10:41:08 pm »
A ulx command that will display the player's role to me/superadmins, eg. !role (player) "(player)'s role is (role). Also a command that'll just print a message to said players HUD/chat.


Role code
Code: Lua
  1. function ulx.ranks( calling_ply, target_plys)
  2.         for _, v in ipairs( target_plys ) do
  3.                 PrintMessage( HUD_PRINTTALK, ply:GetRole() )
  4.         end
  5. end
  6. local tttrole = ulx.command( CATEGORY_NAME , "ulx ranks", ulx.ranks, "!ranks" )
  7. ranks:defaultAccess( ULib.ACCESS_SUPERADMIN )
  8. ranks:help( "Show all time-based ranks" )
  9.  

Message code
Code: Lua
  1. function ulx.role( calling_ply, target_plys)
  2.         for _, v in ipairs( target_plys ) do
  3.                 PrintMessage( HUD_PRINTTALK, ply:GetRole() )
  4.         end
  5. end
  6. local role = ulx.command( CATEGORY_NAME , "ulx role", ulx.role, "!role" )
  7. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  8. role:help( "Show all time-based ranks" )
  9.  

Both don't work because I'm stupid.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Need help, again.
« Reply #1 on: July 29, 2016, 11:32:06 pm »
First of all, you can't put "CATEGORY_NAME" unless you specify CATEGORY_NAME. Sometimes I just feel it's not worth it, so I'm going to put it in a random category, you can change it to whatever you want.


Secondly, you practically wrote the same code twice and changed a few words, I don't really know what you were trying to do there.

Code: Lua
  1. function ulx.role( calling_ply, target_plys )
  2.  
  3.     for k,v in pairs( target_plys ) do
  4.  
  5.         ulx.fancyLogAdmin( "#T is a(n) " .. v:GetUserGroup() .. ".", target_plys )
  6.  
  7.     end
  8.  
  9. end
  10. local role = ulx.command( "Utility", "ulx role", ulx.role, "!role" )
  11. role:addParam{ type=ULib.cmds.PlayersArg }
  12. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  13. role:help( "Show all time-based ranks." )
  14.  

I believe this will work, it's 2:30 AM for me so kind of tired but I believe it should work.
« Last Edit: July 30, 2016, 01:49:50 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Need help, again.
« Reply #2 on: July 29, 2016, 11:37:50 pm »
First of all, you can't put "CATEGORY_NAME" unless you specify CATEGORY_NAME. Sometimes I just feel it's not worth it, so I'm going to put it in a random category, you can change it to whatever you want.


Secondly, you practically wrote the same code twice and changed a few words, I don't really know what you were trying to do there.

Code: Lua
  1. function ulx.role( calling_ply, target_plys )
  2.  
  3.     for k,v in pairs( target_plys ) do
  4.  
  5.         ulx.fancyLogAdmin( "#T is a(n) " .. v:GetUserGroup() .. ".", target_plys )
  6.  
  7.     end
  8.  
  9. end
  10. local role = ulx.command( "Utility", "ulx role", ulx.role, "!role" )
  11. role:addParam( type=ULib.cmds.PlayersArg )
  12. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  13. role:help( "Show all time-based ranks." )
  14.  

I believe this will work, it's 2:30 AM for me so kind of tired but I believe it should work.

I did have a category I only copied the function.

EDIT: I barely know anything about lua so I tried because as they were somewhat similar functions.
« Last Edit: July 29, 2016, 11:40:24 pm by [?] The Last Centurion »

Offline .gdraw

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Steam
Re: Need help, again.
« Reply #3 on: July 30, 2016, 12:03:31 am »
function ulx.role( calling_ply, target_plys )
    for k,v in pairs( target_plys ) do
        ulx.fancyLogAdmin( "#T is a(n) " .. v:GetUserGroup() .. ".", target_plys )
    end
end
local role = ulx.command( CATEGORY_NAME, "ulx role", ulx.role, "!role" )
role:addParam( type=ULib.cmds.PlayersArg )
role:defaultAccess( ULib.ACCESS_SUPERADMIN )
role:help( "Show the role of a player." )

The command isn't showing up in my ULX menu and i get the error
Code: [Select]
[ERROR] addons/ulx-v3_71/lua/ulx/modules/sh/role.lua:25: ')' expected near '='
  1. unknown - addons/ulx-v3_71/lua/ulx/modules/sh/role.lua:0

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Need help, again.
« Reply #4 on: July 30, 2016, 01:45:22 am »
You're either going to have to give us the entire role.lua file or tell us which live is line 25, because that function is only 9 lines long.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Need help, again.
« Reply #5 on: July 30, 2016, 01:47:05 am »
I think I know. I accidentally put the addParam in parentheses and not brackets. Just replace the () after addParam with {}.

EDIT: I will edit my original post, just copy and paste it into a clean file.
« Last Edit: July 30, 2016, 01:49:12 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline .gdraw

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Steam
Re: Need help, again.
« Reply #6 on: July 30, 2016, 02:44:42 am »
So I get no errors now, but the command doesn't actually do anything, afaik.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Need help, again.
« Reply #7 on: July 30, 2016, 04:13:18 am »
So I get no errors now, but the command doesn't actually do anything, afaik.

Can you give us the code and where you're putting it?
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline .gdraw

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Steam
Re: Need help, again.
« Reply #8 on: July 30, 2016, 10:15:02 am »
Can you give us the code and where you're putting it?

I'm putting it in
Code: [Select]
ulx/lua/ulx/modules/sh
Code: Lua
  1. --- ROLE ---
  2. function ulx.role( calling_ply, target_plys )
  3.     for k,v in pairs( target_plys ) do
  4.         ulx.fancyLogAdmin( "#T is a(n) " .. v:GetUserGroup() .. ".", target_plys )
  5.     end
  6. end
  7. local role = ulx.command( "TTT Utility", "ulx role", ulx.role, "!role" )
  8. role:addParam{ type=ULib.cmds.PlayersArg }
  9. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  10. role:help( "Show's the role of the targeted player." )
  11.  

I also have this that is doing the same thing.
Code: Lua
  1. --- RANKS ---
  2. function ulx.ranks( calling_ply )
  3.                 ply:PrintMessage([[1 hour = Player
  4.                 5 hour = Member
  5.                 24 hour = Regular
  6.                 72 hour = Respected
  7.                 168 hour = Highly Respected
  8.                 336 hour = Expert]])
  9. end
  10. local ranks = ulx.command( "TTT Utility" , "ulx ranks", ulx.ranks, "!ranks" )
  11. ranks:defaultAccess( ULib.ACCESS_ALL )
  12. ranks:help( "Show all time-based ranks." )
  13.  

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Need help, again.
« Reply #9 on: July 30, 2016, 01:12:05 pm »
I think it would be better to just make it a single target person, instead of multiple.

Code: Lua
  1. --- ROLE ---
  2. function ulx.role( calling_ply, target_ply )
  3.     ulx.fancyLogAdmin( {calling_ply}, "#T is a(n) " .. target_ply:GetUserGroup() .. ".", target_ply ) -- This will make it show to ONLY the caling_ply. Remove the "calling_ply" from the function variables and the "{calling_ply}" from the fancyLogAdmin to make it show to everyone.
  4. end
  5. local role = ulx.command( "TTT Utility", "ulx role", ulx.role, "!role" )
  6. role:addParam{ type=ULib.cmds.PlayerArg }
  7. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  8. role:help( "Show's the role of the targeted player." )
  9.  

I believe it should work. Also, don't put it in the default ULX folder. Make a new folder in
Code: [Select]
garrysmod/garrysmod/addons/
It won't break anything if it's in there, but it will make it a pain in the ass to update if it is in there.
« Last Edit: July 30, 2016, 01:14:52 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Need help, again.
« Reply #10 on: July 30, 2016, 01:41:06 pm »
-snip-
Uhh... You do realize he's trying to get the TTT role of the target player, not the usergroup, right? Or am I misunderstanding things here?
bw81@ulysses-forums ~ % whoami
Homepage

Offline .gdraw

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Steam
Re: Need help, again.
« Reply #11 on: July 30, 2016, 03:14:28 pm »
Uhh... You do realize he's trying to get the TTT role of the target player, not the usergroup, right? Or am I misunderstanding things here?

He might be tired or not paying attention, but I could easily just copy+paste and make it it's own function just because, and I think I know what to change to make it show the role (if I'm not stupid).

-boop

I made a new folder under addons I don't know if it works yet, but I moved all of my custom commands to said folder, so that they do not get deleted/corrupted via a ULX update.
Code: [Select]
addons\ulx_custom\lua\ulx\modules\sh -- This is correct, yes?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Need help, again.
« Reply #12 on: July 30, 2016, 03:39:29 pm »
Oh... sorry I wasn't paying attention. The thing about TTT Roles is that if you just use "GetRole()" it will display a number and not the actual role.

Code: Lua
  1. --- ROLE ---
  2. function ulx.role( calling_ply, target_ply )
  3.     if target_ply:GetRole() == ROLE_TRAITOR then
  4.         ulx.fancyLogAdmin( {calling_ply}, "#T is a Traitor!", target_ply, true, true )
  5.     elseif target_ply:GetRole() == ROLE_INNOCENT then
  6.         ulx.fancyLogAdmin( {calling_ply}, "#T is an Innocent!", target_ply, true, true )
  7.     elseif target_ply:GetRole() == ROLE_DETECTIVE then
  8.         ulx.fancyLogAdmin( {calling_ply}, "#T is a Detective!", target_ply, true, true )
  9.     end
  10. end
  11. local role = ulx.command( "TTT Utility", "ulx role", ulx.role, "!role" )
  12. role:addParam{ type=ULib.cmds.PlayerArg }
  13. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  14. role:help( "Show's the role of the targeted player." )

Sorry about that.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline .gdraw

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Steam
Re: Need help, again.
« Reply #13 on: July 30, 2016, 03:45:13 pm »
-boop

Is there any way to add colour to the output? Eg. Red for Traitor, Blue for Detective, etc.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Need help, again.
« Reply #14 on: July 30, 2016, 04:00:31 pm »

I'm not sure if fancyLogAdmin accepts color, but you could try something like this:

Code: Lua
  1. --- ROLE ---
  2. function ulx.role( calling_ply, target_ply )
  3.     if target_ply:GetRole() == ROLE_TRAITOR then
  4.         ulx.fancyLogAdmin( calling_ply, "#T is a ", Color( 200, 25, 25 ), "Traitor!", target_ply, true, true )
  5.     elseif target_ply:GetRole() == ROLE_INNOCENT then
  6.         ulx.fancyLogAdmin( {calling_ply}, "#T is an ", Color( 25, 200, 25 ), "Innocent!", target_ply, true, true )
  7.     elseif target_ply:GetRole() == ROLE_DETECTIVE then
  8.         ulx.fancyLogAdmin( {calling_ply}, "#T is a ", Color( 25, 25, 200 ), "Detective!", target_ply, true, true )
  9.     end
  10. end
  11. local role = ulx.command( "TTT Utility", "ulx role", ulx.role, "!role" )
  12. role:addParam{ type=ULib.cmds.PlayerArg }
  13. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  14. role:help( "Show's the role of the targeted player." )


Again, not sure if ulx.fancyLogAdmin supports color, but if it does that's how you would use it.


EDIT: If this doesn't work, you'd have to use ULib.tsayColor (I believe) which I don't know if it supports #T targetting.
« Last Edit: July 30, 2016, 04:03:48 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print