Author Topic: How does fancyLogAdmin work?  (Read 4043 times)

0 Members and 1 Guest are viewing this topic.

Offline RussEfarmer

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
  • Computer Choreographer
How does fancyLogAdmin work?
« on: January 30, 2022, 11:32:06 AM »
I'm making some ULX commands and I've been having trouble with is fancyLogAdmin... how exactly do you use it? I've been guessing based off of what other ULX commands do. Some commands do it really simple, like whip:
Code: [Select]
ulx.fancyLogAdmin( calling_ply, "#A whipped #T #i times with #i damage", affected_plys, times, dmg )But then you look at something like the ban command and it's just... really weird. Mostly the last half:
Code: [Select]
ulx.fancyLogAdmin( calling_ply, str, target_ply, minutes ~= 0 and ULib.secondsToStringTime( minutes * 60 ) or reason, reason )
Is there a reference on how to use it? I'm still not 100% on lua so I could be missing some concept that makes this function super obvious to people that understand it.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How does fancyLogAdmin work?
« Reply #1 on: January 30, 2022, 02:47:11 PM »
There's a tiny bit of reference.
https://ulyssesmod.net/ulx_docs/ulx-module#fancy-logging

Summarized, FancyLogAdmin can be passed various strings that can then be filled in with table info.
Depending on what the first bits of information are, it deciphers what to output using normal Lua capability.
That example within ban you're having trouble with is evaluated mid-process. Break it down.
Looking closer, you'll see that what you're confused about is actually being turned into most of your example you somewhat understand - "#A banned #T " (permanently) OR (for #S) " in lines 92 to 95 of the ban command.
https://github.com/TeamUlysses/ulx/blob/afca346273a12c8267227b843bee646e5ec947ed/lua/ulx/modules/sh/util.lua#L86

str becomes the string from 92 to 95.
minutes ~= 0 and ULib.secondsToStringTime (minutes = 60) becomes a string of the number someone typed, IF someone typed a number else it's set to default ban and the reason is used,  else the time and the reason are passed.
If someone typed a number, the ban command then uses that number to replace #S in what becomes "for #S".

I could see as a beginner in Lua how that might be confusing.
Though there is no 'indepth' reference, you may find the function ulx.fancyLogAdmin code helpful.
https://github.com/TeamUlysses/ulx/blob/afca346273a12c8267227b843bee646e5ec947ed/lua/ulx/log.lua#L409
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming