Ulysses

General => Developers Corner => Topic started by: jakej78b on September 04, 2014, 09:15:15 PM

Title: Possible to over-ride ULX commands and ULib functions?
Post by: jakej78b on September 04, 2014, 09:15:15 PM
Just curious, I was wanting to add a reason to slay. I have done so successfully before, but I want to do it without editing core files. (Been using Falco's ways for too long)
Title: Re: Possible to over-ride ULX commands and ULib functions?
Post by: Avoid on September 04, 2014, 09:23:37 PM
Hello there,
I'd probably add a string param and give an output using ulx.fancyLogAdmin.

Also without editing core files? You could add an extra command slayres - just take a look at ulx.kick:
Code: [Select]
function ulx.kick( calling_ply, target_ply, reason )
        if reason and reason ~= "" then
                ulx.fancyLogAdmin( calling_ply, "#A kicked #T (#s)", target_ply, reason )
        else
                reason = nil
                ulx.fancyLogAdmin( calling_ply, "#A kicked #T", target_ply )
        end
        ULib.kick( target_ply, reason, calling_ply )
end
local kick = ulx.command( CATEGORY_NAME, "ulx kick", ulx.kick, "!kick" )
kick:addParam{ type=ULib.cmds.PlayerArg }
kick:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
kick:defaultAccess( ULib.ACCESS_ADMIN )
kick:help( "Kicks target." )
Title: Re: Possible to over-ride ULX commands and ULib functions?
Post by: JamminR on September 04, 2014, 11:23:12 PM
Avoid, there's better ways than making new commands.

Likely two most helpful in this instance;
ULibCommandCalled (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibCommandCalled) (called on server before any Ulib command actually runs(which ULX uses of course)
ULibPostTranslatedCommand (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibPostTranslatedCommand) - Server hook - runs after a ulib command call - this one could look for slay, then run the additional logging code/whatever code you wanted after slay.

If I were wanting to do any additional commands in ULX but not actually change our project code...those are what I'd use.
Title: Re: Possible to over-ride ULX commands and ULib functions?
Post by: Avoid on September 05, 2014, 07:21:58 AM
Oh,
thanks for pointing those two functions out, yes always have a read through the documentation first! :)
Title: Re: Possible to over-ride ULX commands and ULib functions?
Post by: jakej78b on September 05, 2014, 08:33:50 PM
Thanks, JamminR. I'll be sure to give that a shot and report back!