Ulysses
General => Developers Corner => Topic started by: easer7 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?
-
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!
-
awesome thanks!
-
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?
-
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
-
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
-
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.
-
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
-
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)
-
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!
-
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.