Ulysses

Ulysses Stuff => General Chat & Help and Support => Topic started by: Haash on April 14, 2014, 06:52:40 PM

Title: Solved: ULib.cmds.TranslateCommand Not Hinting
Post by: Haash on April 14, 2014, 06:52:40 PM
Hi there,

Apologies for first post being a help request, I'll try and make it as complete as possible.

I'm currently looking at adding chat commands and hinting to Lexi's sourcebans script. The problem I'm having is that the console command is not being listed in client consoles for autocomplete options. The command isn't even being listed as valid (showing up in the list of commands hint below when typing), however you can still call it as a valid function. Couple of screenshots from console showing my problem.

Showing the autocomplete for the function names -> Does not show sm_ban

(http://i.imgur.com/d0vzOqM.jpg)

No Autocomplete options for command on first arg

(http://i.imgur.com/OwmtzKI.jpg)

No Autocomplete on second arg

(http://i.imgur.com/q658Fju.jpg)

Proof that the command does work

(http://i.imgur.com/ub1eb9E.jpg)

For reference, the relevant functions being used (in the load order as defined by ULib/ulx):

\lua\ulib\modules\sourcebans_shfunc.lua [Shared]
Code: [Select]
function sourcebans.addCommand( command, fn, say_cmd, hide_say, nospace )
local obj = ULib.cmds.TranslateCommand(command, fn, say_cmd, hide_say);
obj:addParam{ type=ULib.cmds.CallingPlayerArg };
return obj;
end

\lua\ulx\modules\sourcebans.lua [Serverside]
Code: [Select]

function sourcebans.ban( ply, pl, time, reason )
    if (not checkConnection()) then
        return complain(ply, "The database is not active at the moment. Your command could not be completed.");
    elseif (not authorised(ply, FLAG_BAN)) then
        return complain(ply, "You do not have access to this command!");
    end
    --local pl, time, reason = table.remove(args,1), table.remove(args,1), table.concat(args, " "):Trim();
    --pl = playerGet(pl);

--Time chat suffixes
local suffix = string.Right( time, 1 )

if suffix == "h" then
time = tonumber( string.sub( time, 1, string.len( time ) - 1 ) ) * 60
elseif suffix == "d" then
time = tonumber( string.sub( time, 1, string.len( time ) - 1 ) ) * 1440
elseif suffix == "w" then
time = tonumber( string.sub( time, 1, string.len( time ) - 1 ) ) * 10080
elseif suffix == "m" then
time = tonumber( string.sub( time, 1, string.len( time ) - 1 ) ) * 1440 * 30
elseif suffix == "y" then
time = tonumber( string.sub( time, 1, string.len( time ) - 1 ) ) * 1440 * 365
else
time = tonumber( time )
end

    if (not complainer(ply, pl, time, reason, usage)) then
        return;
    end
    local name = pl:Name();
    local function callback(res, err)
        if (res) then
            complain(ply, "sm_ban: " .. name .. " has been banned successfully.")
        else
            complain(ply, "sm_ban: " .. name .. " has not been banned. " .. err);
        end
    end
    sourcebans.BanPlayer(pl, time * 60, reason, ply, callback);
    complain(ply, "sm_ban: Your ban request has been sent to the database.");
end
local sm_ban = sourcebans.addCommand("sm_ban", sourcebans.ban, { "!sban" }, true);
sm_ban:addParam{ type=ULib.cmds.PlayerArg };
sm_ban:addParam { type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 };
sm_ban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine };
sm_ban:defaultAccess( ULib.ACCESS_ADMIN );

I feel like this is a really simple issue that is probably me being stupid and overlooking something. I have also tried using the ulx functions which also worked, however did not show any autocompletes/hints. (Exactly like this issue)

Any help would be greatly appreciated. If you need anything else, let us know :)

EDIT: Just for clarification, there are no errors pushed either serverside or clientside on use of the functions, or on load. Cheers!
Title: Re: ULib.cmds.TranslateCommand Not Hinting
Post by: JamminR on April 14, 2014, 09:22:12 PM
Seems, and forgive my lack of Ulib brain use for some years, that you're not giving/setting autocomplete table callback on the client side, only the server. [it's ignored if on server]
See the notes at http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.TranslateCommand.cmds.addCommand (http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.TranslateCommand.cmds.addCommand) for AddCommand.
Title: Re: ULib.cmds.TranslateCommand Not Hinting
Post by: Haash on April 14, 2014, 09:29:10 PM
Seems, from my lack of Ulib brain use for some years, that you're not setting autocomplete table on the client side, only the server. [it's ignored if on server]
See the notes at http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.TranslateCommand.cmds.addCommand (http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.TranslateCommand.cmds.addCommand) for AddCommand.

Thanks, might be so seeming as all the addParam functions are called on sourcebans.lua only. How would you reccomend fixing this? I could hardcode the parameters into the shfunc.lua file, however this would require an additional function for each command. Is there any method of pushing the parameters when used serverside into the shared file as well? (i.e. a table that is holding all the addParam arrays? If so, I might be able to call a function later that pushes this array to the clientside array as well.

Edit: Moving the sourcebans.ban and related args from sourcebans.lua [Serverside] -> sourcebans_shfunc.lua [Shared] seems to have fixed the problem. Huge thanks for the help, I knew it was something simple overlooked that I needed a pair of extra eyes on. I'll update the other commands and make sure that they all work, albeit I'll mark this as solved for the time being!