Author Topic: Help with gui boxes  (Read 4382 times)

0 Members and 1 Guest are viewing this topic.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Help with gui boxes
« on: December 21, 2012, 08:12:19 PM »
helllooooo =33 I just made a script called getkarma, and despite the name, it SETS karma, and I wnt to make a ULX command that sets karma, I know how to put it in the XGUI but i dont know how to make a box of target players and a box of how much karma to set it to
Help?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Help with gui boxes
« Reply #1 on: December 22, 2012, 05:46:13 AM »
Look at other ULX commands for a template of how to create your own. You don't need to explicitly add it to XGUI as XGUI will intelligently figure out what you need on its own, assuming you create the command in ULX correctly!
Experiencing God's grace one day at a time.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Help with gui boxes
« Reply #2 on: December 22, 2012, 11:19:14 AM »
awesome thanks!

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Help with gui boxes
« Reply #3 on: December 22, 2012, 04:05:17 PM »
hey i got this so far


function ulx.setkarma( calling_ply, command, argv, args )
   if #argv < 2 then
      ULib.tsay( ply, ulx.LOW_ARGS, true )
      return
   end
   
   local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords
   if not targets then
      ULib.tsay( ply, err, true )
      return
   end
   
    local amount = tonumber( argv[ 2 ] ) or 1000;
 
        for k, v in pairs( player.GetAll() ) do
            if ( string.find(string.lower( v:Targets() ), targets) ) then
                v:SetLiveKarma(amount);
                v:SetBaseKarma(amount);
            end;
        end;
    end;
end
ulx.concommand( "setkarma", ulx.setkarma, "<user(s)> - Gives target(s) karma.", ULib.ACCESS_ADMIN, "!setkarma", _, ulx.ID_PLAYER_HELP )
ulx.addToMenu( ulx.ID_MCLIENT, "setkarma", "ulx setkarma" )


but i dont know where to go from here, can you help me?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with gui boxes
« Reply #4 on: December 22, 2012, 10:12:55 PM »
Seems you're looking at an OLD ulx command set up. We've not used that style in over a year, heck, perhaps two.
What version of ULX and Gmod are you running??

EDIT - See also - old vs new, with well documented comments.
http://forums.ulyssesmod.net/index.php/topic,4464.msg17838.html#msg17838
« Last Edit: December 22, 2012, 10:16:37 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Help with gui boxes
« Reply #5 on: December 26, 2012, 09:32:45 AM »
I have the newest one, can you help me out? This is the code for my setkarma script.


concommand.Add("ttt_setkarma", function(client, command, arguments)
    if ( IsValid(client) and client:IsAdmin() ) then
        if (!arguments[1]) then
            client:ChatPrint("Missing name!");
 
            return;
        elseif (!arguments[2]) then
            client:ChatPrint("Missing amount!");
 
            return;
        end;
 
        local name = string.lower(arguments[1]);
        local amount = tonumber(arguments[2]) or 1000;
 
        for k, v in pairs( player.GetAll() ) do
            if ( string.find(string.lower( v:Name() ), name) ) then
                v:SetLiveKarma(amount);
                v:SetBaseKarma(amount);
            end;
        end;
    end;
end);




How would I add this to ULX and get the xgui to make boxes to select the arguments

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with gui boxes
« Reply #6 on: December 26, 2012, 02:21:00 PM »
Before I go digging into it, does this command work for you as wanted from console (not using ULX of course)?
That is, you can type >ttt_setkarma <name> <amount#> , and it work?

I'm just asking, because you've got some variables/other miscellaneous code in it that 1) isn't necessary in your current example and 2) definitely won't be needed in a new ULX only example.
If I personally show you what the ULX command would look like, I'm going to clean it up (and trust me, you'll be like "That's it??? That's all that's required in the function????")
I want to make sure it works for you as is first.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Help with gui boxes
« Reply #7 on: December 26, 2012, 04:31:40 PM »
Yes it works! But for some reason there are times when it does not, it works about 90% of the time. The other 10 it resets after round end

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with gui boxes
« Reply #8 on: December 26, 2012, 09:00:50 PM »
Code: [Select]
function ulx.ttt_setkarma ( calling_ply, target_ply, amount )
target_ply:SetLiveKarma( amount )
target_ply:SetBaseKarma( amount )
ulx.fancyLogAdmin( calling_ply, "#A set TTT Karma for #T to #i", target_ply, amount )
end
local ttt_setkarma = ulx.command ( "TTT", "ulx ttt_setkarma", ulx.ttt_setkarma, "!ttt_setkarma" )
ttt_setkarma:addParam { type=ULib.cmds.PlayerArg } -- no S in PlayerSArg, limited to one target at a time
ttt_setkarma:addParam{ type=ULib.cmds.NumArg, min=0, max=5000, default=50, hint="karma", ULib.cmds.optional, ULib.cmds.round }
ttt_setkarma:defaultAccess( ULib.ACCESS_ADMIN )
ttt_setkarma:help ( "Sets TTT Karma for <target> to <amount>" )
ttt_setkarma:logString ( "#1s set TTT Karma on #2s to #3i" )

First, this is untested. It should 'just work' in ULX.
Most of it is, at least I think is, self explanatory. Change the numbers you want. Amount is optional (it will default to 50).
I've no idea what will be added to XGUI (ie, sliders/dropdowns, etc.) You'll need to research a bit on your own, as I don't have time to look at the XGUI structure right now.
The code was straight out of my head (I love ULib/ULX for this..every command is easy to set up. The command setup does all the input checking for you (ie, make sure player is entered, make sure default amount, if no amount, use a set default)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Help with gui boxes
« Reply #9 on: December 27, 2012, 10:16:19 AM »
Code: [Select]
ttt_setkarma:addParam { type=ULib.cmds.PlayerArg } -- no S in PlayerSArg, limited to one target at a time
ttt_setkarma:addParam{ type=ULib.cmds.NumArg, min=0, max=5000, default=50, hint="karma", ULib.cmds.optional, ULib.cmds.round }

These lines determine what XGUI will automatically put in the cmds tab for you-- you don't have to do anything at all!
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with gui boxes
« Reply #10 on: December 27, 2012, 04:48:27 PM »
These lines determine what XGUI will automatically put in the cmds tab for you-- you don't have to do anything at all!
Nice. Love it. I'd hoped it would do it from that.
Great, as always.
Now go turn Pylons into a gamemode for the new year.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming