Sal’s Kewl Korner

Home / Documentation / Report developer guide

Sal's Kewl Report — developer guide

For any script, ours or anyone else's: say what the player is doing and where, so a report about your script arrives with the details you need, and staff get Go to the scene and Recreate buttons for it.

documents resource version 0.2.0

Overview

Make your script work with in-game problem reports. With a few lines, a report made while a player is using your script:

  • has your script picked on the form automatically;
  • carries what the player was doing in your words (the incident, their role, whatever helps you debug);
  • carries the spot, so staff can press Go to the scene;
  • can carry your own replay data, so staff can press Recreate and your script sets the situation up again for them to watch.

Everything here is optional, and every call is safe if sals_kewlreport is not installed: wrap it as shown. You never pass your resource name; FiveM tells us who is calling (GetInvokingResource), so one script cannot speak for another.


1. Say what the player is doing (server)

Call it when your activity starts, again whenever it changes, and clear it when it ends.

local function reportContext(src, data)
    if GetResourceState('sals_kewlreport') ~= 'started' then return end
    pcall(function() exports.sals_kewlreport:SetContext(src, data) end)
end

local function reportClear(src)
    if GetResourceState('sals_kewlreport') ~= 'started' then return end
    pcall(function() exports.sals_kewlreport:ClearContext(src) end)
end

-- A player starts working one of your incidents:
reportContext(src, {
    summary = 'Working a structure fire',                -- one line, shown first
    lines   = {                                          -- up to 8 label/value pairs
        { 'Incident', 'FIRE-2291' },
        { 'Role',     'Engine 12, interior attack' },
        { 'Stage',    'Fully involved' },
    },
    coords  = vector3(-47.25, -1757.5, 29.42),           -- the scene (vector3/vector4 or {x,y,z,h})
    label   = 'Corner Mart, 1402 Elgin Ave',             -- what to call it
    replay  = { incident = 'fire_2291', preset = 'kitchen', stage = 3 },  -- yours, see section 3
})

-- ...and when they are done with it:
reportClear(src)
Field Type Limits Shown to
summary string 200 characters the player (on the form), staff, Discord
lines { { label, value }, ... } 8 pairs; 60 / 300 characters staff, Discord, the developer write-up
coords vector3/vector4 or {x,y,z,h} staff (Go to the scene)
label string 120 characters staff, the developer write-up
replay plain table (no functions) 8 KB as JSON nobody; handed back to your ReportReplay
active boolean default true false = context only, do not pre-select your script

Rules that keep it cheap and honest:

  • Set it as often as you like; the newest one replaces the last.
  • It is forgotten when you clear it, when the player leaves, when your resource stops, or after 30 minutes without being set again. Re-set it periodically for long activities.
  • Several scripts can describe the same player at once. The most recently set active one is the one suggested on the form; all of them are saved.
  • Only send what you would show a server's staff. Never put tokens, IPs or personal data in a context.

Prefer events over exports? These do the same and cannot be sent from a player's game:

TriggerEvent('sals_kewlreport:setContext', src, data)
TriggerEvent('sals_kewlreport:clearContext', src)

2. From the player's game (client)

Client-side scripts can do the same without a server round trip of their own:

if GetResourceState('sals_kewlreport') == 'started' then
    exports.sals_kewlreport:SetContext({ summary = 'Using the hose', lines = { { 'Nozzle', 'Fog 30°' } } })
    -- later
    exports.sals_kewlreport:ClearContext()
end

These are always about the local player, are rate limited (10 per 10 seconds), and are marked from the client for staff, since a player's game can be modified. Use the server export for anything that matters.

3. Let staff recreate it

Export ReportReplay from your server side. Staff see Recreate (Your Script) on any report that carries your replay data, and pressing it calls:

exports('ReportReplay', function(adminSrc, replay, info)
    -- replay: exactly the table you gave SetContext (after a JSON round trip)
    -- info:   { n = report number, coords = {x,y,z,h} or nil, label = string or nil,
    --           player = the reporter's server ID at the time (may have left) }
    local fire = StartFireFromPreset(replay.preset, info.coords, replay.stage)
    if not fire then
        return false, 'no free fire slot right now'      -- shown to staff
    end
    return true, ('Fire %s restarted at %s.'):format(replay.incident, info.label or 'the scene')
end)

Return true (and a short message), or false and a reason. Keep it to setting things up: staff decide what to do next. Check your own permissions in it if your script has them; the report panel has already checked that the caller is staff.

4. Open the form from your own menu

-- client
exports.sals_kewlreport:Open({ script = true, text = 'The hose stopped spraying' })

script = true picks your script on the form (or pass another resource's name), and text starts the description for them. The screenshot is taken the moment you call it, so call it before opening any menu of your own over the screen. exports.sals_kewlreport:Open() with nothing opens the form just like /report.

5. Being asked instead (pull)

If you would rather not keep anything up to date, export ReportContext and you are asked at the moment a report is made. Same shape as SetContext (summary, lines, active); return nil if you have nothing to say.

exports('ReportContext', function(src)            -- server; the client version takes no src
    local job = activeJobs[src]
    if not job then return nil end
    return { active = true, summary = 'Towing a vehicle', lines = { { 'Job', job.id } } }
end)

Pull is asked only of Sal's Kewl scripts and of scripts the server owner lists in Config.Scripts.Names; push (SetContext) works for everyone.

What happens to your data

It is saved with the report on the server that runs your script, shown to that server's staff, and included in the write-up they can copy for you. If they use Discord, the summary and lines are in the post. It is not sent to Sal's Kewl Korner: when a server sends us a report about one of our scripts, other scripts' contexts are left out.

Testing it

  1. ensure sals_kewlreport after your resource, and give yourself add_ace identifier.license:xxxx sals_kewlreport.admin allow.
  2. Start your activity, then /report testing my integration.
  3. Open /reports: your script should be picked, your summary and lines under What the scripts said, and Go to the scene / Recreate among the buttons.

Didn’t find it? Ask Squawky, or open a ticket on Discord and tell us what you already tried.