General > Developers Corner

Help with gui boxes

<< < (2/3) > >>

easer7:
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

JamminR:
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.

easer7:
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

JamminR:

--- Code: ---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" )
--- End code ---

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)

Stickly Man!:

--- Code: ---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 }
--- End code ---

These lines determine what XGUI will automatically put in the cmds tab for you-- you don't have to do anything at all!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version