Common Patterns
Checking police on duty
lua
-- Server
local cops = st.jobscache:getJobCount('police')
if cops < 2 then
st.s_notify(source, { type = 'error', description = 'Ikke nok betjente online' })
return
endGive item and notify
lua
-- Server
local user = st.framework:getUser(source)
local success = user:AddItem('water', 1)
if success then
st.s_notify(source, {
type = 'success',
title = 'Item modtaget',
description = 'Du modtog 1x Vand',
duration = 3000,
})
endHook into player load (server)
lua
st.hook.registerAction('playerLoaded', function(playerId)
local user = st.framework:getUser(playerId)
print(('Player loaded: %s (%s)'):format(user:getName(), user.identifier))
end)Scheduled daily reset
lua
st.cron.new('0 6 * * *', function(task, date)
-- Reset daily counters at 06:00
MySQL.update.await('UPDATE my_resource_data SET daily_count = 0', {})
st.print.info('Daily reset completed')
end, { debug = true })