PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: Schumbot on 30 June, 2026, 23:20:04

Title: TriviaMod v2.3.0
Post by: Schumbot on 30 June, 2026, 23:20:04
[size=18]TriviaMod v2.3.0 — Advanced Trivia Script for PtokaX[/size]

Hi everyone,

I am releasing TriviaMod v2.3.0, a heavily improved version of the classic Trivia script originally written by chill, then extended by NRJ (Quiz 1.6). This release is the result of a long rework session covering bugs, encoding, translation, and a set of new features.

[size=14]Compatibility[/size]

[size=14]What is new compared to the original v1.02d[/size]

Core fixes
Question file flexibility
Visual improvements

New commands
Rank system
Team mode (optional)
Team multiplier — System C
[size=14]Installation[/size]
[list=1]
scripts/
  Trivia_Mod.lua
  TriviaMod/
    settings.lu
    questions.txt
    Data/
    Functions/
[size=14]Question file format[/size]

The script accepts three equivalent formats:
{Category} Question text *Answer
{Category}*Question text *Answer
{Category} *Question text *Answer

Multiple valid answers are separated by additional * characters:
{Category} *Question *Answer1 *Answer2
The {...} category tag is optional. Lines without it are read as plain Question *Answer entries.

[size=14]Commands summary[/size]

Players
!trivhelp         — help
!trivmytop        — your personal stats and rank
!trivscore        — top scorers
!trivstats        — top N player stats
!trivtoptime      — top by average response time
!trivtopanswers   — top by correct answer count
!trivtopstreak    — top by streak
!trivskip         — skip current question
!trivhint         — request a hint
!trivreport       — report an error in a question
!trivgrades       — show rank table
!trivteamscore    — show team ranking (if team mode active)
!login / !logout  — join / leave the game (PM mode)

Admin
!trivstart        — start the quiz
!trivstop         — stop the quiz
!trivpause        — announce a break
!trivcontinue     — resume after break
!trivbreakskip    — skip current break
!trivquestion N   — jump to question number N
!trivconfskip     — toggle question skip on/off
!trivhint         — toggle hints on/off
!trivchangemode   — toggle sequential/random mode
!trivmain / !trivpm — switch main chat / PM mode
!trivaddquestion  — add a question live
!trivshowreport   — show error reports
!resetscores      — reset all scores

[size=14]Credits[/size]
Based on the original thread: http://mydc.ru/topic1377.html

[size=14]Feedback[/size]

Please report any bugs, suggestions or question file issues in this thread.
Tested on PtokaX 0.5.x with Lua 5.4 on Windows.

Enjoy the quiz! :)
Title: Re: TriviaMod v2.3.0
Post by: jim124 on 05 July, 2026, 07:46:16
nice work
Title: Re: TriviaMod v2.3.0
Post by: b_e on 24 August, 2026, 22:29:58
Hi!

Nice script.

I have just checked your code and while I have not evaluated the overall design, I could not help but notice that you are giving yourself a hard time: there is waaaaaay too much nesting.

Don't get me wrong, I'm sure your code works fine, but the above makes your code difficult to work with.

Since this platform is not too fit to post huge Lua chunks (and seems to allow no Markdown code either), I have decided to amend your code and implent early returns rather than nested if-then-else.

In general, if there are more than 4 lines after your if ... then statement, consider an early return.

Your original logic is completely unchanged, except for the added empty string check at the beginning. Please find attached the corrected file. I have implemented a timer reset local minifunction, but the sole purpose of that is to reuse the same chunk of yours at different spots.

Note that this is a proof of concept, it throws no syntax errors in the lua interpreter, but I have not tested it with PtokaX.

If you get my point, you can check your MainTimer and SendMsgToPlayers functions yourself, because I only rearranged ParseData :P

Also, instead of
string.lower(str) just use
str:lower()

Likewise:
string.find(str) --> str:find
string.match(str) -->  str:match
string.gsub(str) --> str:gsub

-- The nested str:gsub():gsub():gsub() syntax is super cool. :D
.
It is also good practice to keep line lengths at 80 columns max, so that your script can be edited even on terminals.

Hope you are not offended; trying to help so that you can enjoy coding more.

Keep up the good work!

Title: Re: TriviaMod v2.3.0
Post by: b_e on 24 August, 2026, 23:11:10
Also whacked this together so that you can see where I am coming from:
-- These all do the same: check if a number is a positiven integer between 1 and 100 (inclusive)
-- Return true if all above conditions are met
-- Return false on error, and a string describing the error

-- Early return version: this is the most readable and efficient
function check(n)
    if n < 0 then return false, "negative" end
    if n ~= math.floor(n) then return false, "not an integer" end
    if n >= 1 and n <= 100 then return true end
    return false, "out of range" 
end

-- Nested `if`: twice as many lines
function check_if(n)
    if n > 0 then
        if n == math.floor(n) then
            if n >= 1 and n <= 100 then
                return true
            else
                return false, "out of range"
            end
        else
            return false, "not an integer"
        end
    end
    return false, "negative"
end

-- Even if you collate into one if check, you are still on par with early return
-- but this is not as easy to interpret as the early return version
--
-- and there is a HUGE limitation: this way you cannot tell the caller what the
-- problem is
function check_if2(n)
    if n > 0 and n == math.floor(n) and n >= 1 and n <= 100 then
        return true
    end
    return false, "not an integer or negative or outta range, dunno man"
end