Code
Code — Lua
Function
lua
local function getPlayerState(src)
if not src or src <= 0 then
return nil
end
return Player(src).state.exampleFlag or false
endLine highlight {2,4-6}
lua
local function payPlayer(src, amount)
if amount <= 0 then return false end
local char = exports['pcore-core']:GetCharacter(src)
if not char then return false end
return char:addMoney('cash', amount)
endClient event
lua
RegisterNetEvent('pcore:client:notify', function(message, nType)
exports['pcore-hud']:Notify(message, nType or 'info')
end)Server event
lua
RegisterNetEvent('pcore:server:giveItem', function(itemName, count)
local src = source
count = math.floor(tonumber(count) or 0)
if count < 1 then return end
exports['pcore-inventory']:AddItem(src, itemName, count)
end)Export (client)
lua
exports('OpenMenu', function(menuId)
SendNUIMessage({ action = 'openMenu', id = menuId })
SetNuiFocus(true, true)
end)Export (server)
lua
exports('GetCharacter', function(src)
return Characters[src]
end)Usage from another resource
lua
local char = exports['pcore-core']:GetCharacter(source)
local ok = exports['pcore-core']:AddMoney(source, 'bank', 500)Command
lua
RegisterCommand('example', function(source, args)
if source == 0 then
print('Console only debug')
return
end
TriggerClientEvent('pcore:client:notify', source, 'Command ran', 'success')
end, false)Callback (client → server)
lua
-- client
local result = lib.callback.await('pcore:server:getBalance', false)
-- server
lib.callback.register('pcore:server:getBalance', function(source)
local char = exports['pcore-core']:GetCharacter(source)
return char and char:getBalance('bank') or 0
end)Statebag
lua
-- server
Player(src).state:set('isCuffed', true, true)
-- client
AddStateBagChangeHandler('isCuffed', ('player:%s'):format(cache.serverId), function(_, _, value)
LocalPlayer.state.isCuffed = value
end)Thread / loop
lua
CreateThread(function()
while true do
local sleep = 1000
if cache.vehicle then
sleep = 0
end
Wait(sleep)
end
end)Code — tabs (code-group)
lua
RegisterNetEvent('pcore:client:syncWeather', function(weather)
SetWeatherTypeNowPersist(weather)
end)lua
RegisterNetEvent('pcore:server:setWeather', function(weather)
TriggerClientEvent('pcore:client:syncWeather', -1, weather)
end)lua
Config = {
defaultWeather = 'CLEAR',
}Code — other languages
JSON (NUI message)
json
{
"action": "setVisible",
"visible": true,
"data": {
"cash": 1200,
"bank": 45000
}
}fxmanifest
lua
fx_version 'cerulean'
game 'gta5'
name 'pcore-example'
description 'P Studio'
author 'P Studio'
version '1.0.0'
shared_scripts {
'@pcore-core/shared/config.lua',
}
client_scripts {
'client/main.lua',
}
server_scripts {
'server/main.lua',
}
dependencies {
'pcore-core',
}SQL
sql
SELECT id, citizenid, money
FROM characters
WHERE citizenid = $1
LIMIT 1;Shell / server start
bash
npm run docs:devpowershell
Set-Location -LiteralPath '.\pcore-docs'
npm run docs:buildTypeScript (NUI / tooling)
ts
export interface HudPayload {
cash: number
bank: number
hunger: number
}
window.addEventListener('message', (event: MessageEvent<HudPayload>) => {
if (event.data.action === 'update') {
renderHud(event.data)
}
})YAML-style config block
yaml
debug: false
locale: fr
modules:
inventory: true
jobs: true