• Print

Author Topic: Color3 argument to a command?  (Read 4464 times)

0 Members and 1 Guest are viewing this topic.

Offline jakej78b

  • Newbie
  • *
  • Posts: 26
  • Karma: 4
Color3 argument to a command?
« on: June 20, 2014, 07:37:41 pm »
I've kinda got a start on th is, I'm new to using string.gmatch so I'm not sure if this is right or not.
Also, is there like a HUD element to create a color3 picker like the one on the Colour tool in the spawn menu?
I'd like to somehow add that into xgui.
Code: Lua
  1. function ulx.tag( calling_ply, tag, color)
  2.         local r,g,b
  3.         for i,word in string.gmatch(color, ",") do
  4.                 if i == 1 then
  5.                         r = word
  6.                 elseif i == 2 then
  7.                         g = word
  8.                 elseif i == 3 then
  9.                         b = word
  10.                 elseif i > 4
  11.                         ULib.tsayError( calling_ply, "Invalid color format. Use !tag <r,g,b> <tag text>", true )
  12.                 end
  13.         end
  14.                
  15.         end
  16.         ulx.fancyLogAdmin( calling_ply, "#A changed their tag to #s with Color(#s)", tag, color )
  17.  
  18.  
  19. end
  20. local tag = ulx.command( "Fun", "ulx tag", ulx.tag, "!tag" )
  21. tag:addParam{ type=ULib.cmds.StringArg, hint="color" }
  22. tag:addParam{ type=ULib.cmds.StringArg, hint="text", ULib.cmds.takeRestOfLine }
  23. tag:defaultAccess( ULib.ACCESS_ADMIN )
  24. tag:help( "Sets tag with color and text." )
  25.  

Also, is there a max length property I could apply to a string, or would I need to add this in the code? I wanted to max out the length they could set their tag to about 10.
« Last Edit: June 20, 2014, 08:09:14 pm by jakej78b »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Color3 argument to a command?
« Reply #1 on: June 21, 2014, 10:14:45 am »
I personally think it would be better to use NumArg, with each min=0 and max=255 if you want people to have the full RGB range. Then you could easy just set it to like: "Color( r, g, b )".

When it comes to the string length, I don't think StringArg has any "max_chars" (or similar) to it. So you'd have to use something like string.len in your code.
« Last Edit: June 21, 2014, 10:16:24 am by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline jakej78b

  • Newbie
  • *
  • Posts: 26
  • Karma: 4
Re: Color3 argument to a command?
« Reply #2 on: June 23, 2014, 04:45:04 pm »
Could I still do that with just One Number argument though? Or would I need to use 3. I'd prefer to use 1 just to keep it as simple as possible but I suppose 3 would be alright.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Color3 argument to a command?
« Reply #3 on: June 23, 2014, 05:55:10 pm »
Not really. I mean, there is string.Comma, but it returns a string, which wouldn't directly work using Color().

Even then, you'd have to make sure the number has at least 9 characters (so string.Comma works as it should), which is possible, but then you'd most likely have to use string.len again to count... but that's for a string, not numbers.

As I see it, using 3 arguments would be the best, someone else might have a better idea though.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Color3 argument to a command?
« Reply #4 on: June 23, 2014, 07:03:46 pm »
Use 1 stringarg (i.e. "255 255 255 255"), and use string.ToColor to get a color argument from it.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Color3 argument to a command?
« Reply #5 on: June 24, 2014, 01:24:25 pm »
Also, is there like a HUD element to create a color3 picker like the one on the Colour tool in the spawn menu?
I'd like to somehow add that into xgui.

There is not currently a way to implement a color picker on the Cmds tab in XGUI. You could create a module for XGUI and use it elsewhere, but that's a bit more work.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline jakej78b

  • Newbie
  • *
  • Posts: 26
  • Karma: 4
Re: Color3 argument to a command?
« Reply #6 on: June 24, 2014, 09:40:13 pm »
I'll probably just write a module and place it in the 'Settings' looking off of a base module to get the skeleton. I'm sure I'll need some help after I run into problems.

  • Print