SRP Character API

Simple server-side character management with persistent timers

Money

SRP.Characters.GetPlayerMoney(ply)

Command: srp_getmoney <player>
local money = SRP.Characters.GetPlayerMoney(ply)

SRP.Characters.AddPlayerMoney(ply, amount)

Command: srp_addmoney <player> <amount>
local success, newBalance = SRP.Characters.AddPlayerMoney(ply, 500)

SRP.Characters.RemovePlayerMoney(ply, amount)

Command: srp_removemoney <player> <amount>
local success, newBalance = SRP.Characters.RemovePlayerMoney(ply, 100)

SRP.Characters.SetPlayerMoney(ply, amount)

Command: srp_setmoney <player> <amount>
local success, amount = SRP.Characters.SetPlayerMoney(ply, 1000)

SRP.Characters.CanAfford(ply, amount)

if SRP.Characters.CanAfford(ply, 250) then
    -- player can afford it
end

Character Data

SRP.Characters.GetCharacterData(ply, path)

Command: srp_getcharacterdata <player> [path]
local money = SRP.Characters.GetCharacterData(ply, "data.money")

SRP.Characters.SetCharacterData(ply, path, value)

Command: srp_setcharacterdata <player> <path> <value>
SRP.Characters.SetCharacterData(ply, "data.customField", "value")

Character Info

SRP.Characters.GetCharacterName(ply)

Command: srp_getname <player>
local name = SRP.Characters.GetCharacterName(ply)

SRP.Characters.SetCharacterName(ply, name)

Command: srp_setname <player> <name>
local success = SRP.Characters.SetCharacterName(ply, "John Doe")

SRP.Characters.GetCharacterAlignment(ply)

Command: srp_getalignment <player>
local alignment = SRP.Characters.GetCharacterAlignment(ply)

SRP.Characters.SetCharacterAlignment(ply, alignment)

Command: srp_setalignment <player> <alignment>
local success = SRP.Characters.SetCharacterAlignment(ply, 50)

SRP.Characters.GetCharacterRole(ply)

Command: srp_getrole <player>
local role = SRP.Characters.GetCharacterRole(ply)

SRP.Characters.SetCharacterRole(ply, roleName)

Command: srp_setrole <player> <role>
local success = SRP.Characters.SetCharacterRole(ply, "Police Officer")

Character Attributes

SRP.Characters.GetCharacterAttributes(ply)

Command: srp_getattributes <player>
local attributes = SRP.Characters.GetCharacterAttributes(ply)

SRP.Characters.HasAttribute(ply, attributeId)

if SRP.Characters.HasAttribute(ply, "isMerchant") then
    -- player has merchant attribute
end

SRP.Characters.SetCharacterAttributes(ply, attributes)

local success = SRP.Characters.SetCharacterAttributes(ply, {"isPolice", "isAthletic"})

SRP.Characters.AddCharacterAttribute(ply, attributeId)

Command: srp_addattribute <player> <attribute>
local success = SRP.Characters.AddCharacterAttribute(ply, "isMerchant")

SRP.Characters.RemoveCharacterAttribute(ply, attributeId)

Command: srp_removeattribute <player> <attribute>
local success = SRP.Characters.RemoveCharacterAttribute(ply, "isPolice")

Character Appearance

SRP.Characters.GetCharacterModel(ply)

Command: srp_getmodel <player>
local model = SRP.Characters.GetCharacterModel(ply)

SRP.Characters.SetCharacterModel(ply, model)

Command: srp_setmodel <player> <model>
local success = SRP.Characters.SetCharacterModel(ply, "models/player/group01/female_01.mdl")

SRP.Characters.GetCharacterBodygroups(ply)

Command: srp_getbodygroups <player>
local bodygroups = SRP.Characters.GetCharacterBodygroups(ply)

SRP.Characters.SetCharacterBodygroups(ply, bodygroups)

local success = SRP.Characters.SetCharacterBodygroups(ply, {head = 1, body = 2})

SRP.Characters.SetCharacterBodygroup(ply, bodygroup, value)

Command: srp_setbodygroup <player> <bodygroup> <value>
local success = SRP.Characters.SetCharacterBodygroup(ply, "head", 1)

SRP.Characters.GetCharacterBodygroup(ply, bodygroup)

local value = SRP.Characters.GetCharacterBodygroup(ply, "head")

Status

SRP.Characters.IsArrested(ply)

Command: srp_arreststatus <player>
if SRP.Characters.IsArrested(ply) then
    -- player is arrested
end

SRP.Characters.SetArrested(ply, arrested)

Commands: srp_arrest <player> / srp_unarrest <player>
SRP.Characters.SetArrested(ply, true)  -- Starts 30-minute timer
SRP.Characters.SetArrested(ply, false) -- Clears timer

SRP.Characters.IsWanted(ply)

Command: srp_wantedstatus <player>
if SRP.Characters.IsWanted(ply) then
    -- player is wanted
end

SRP.Characters.SetWanted(ply, wanted)

Commands: srp_setwanted <player> / srp_clearwanted <player>
SRP.Characters.SetWanted(ply, true)  -- Starts 24-hour timer
SRP.Characters.SetWanted(ply, false) -- Clears timer

SRP.Characters.IsDead(ply)

Command: srp_deathstatus <player>
if SRP.Characters.IsDead(ply) then
    -- player is dead
end

SRP.Characters.SetDead(ply, dead)

Commands: srp_kill <player> / srp_revive <player>
SRP.Characters.SetDead(ply, true)  -- Starts 10-minute timer
SRP.Characters.SetDead(ply, false) -- Clears timer

SRP.Characters.GetArrestTimeRemaining(ply)

local timeLeft = SRP.Characters.GetArrestTimeRemaining(ply)
if timeLeft > 0 then
    ply:ChatPrint("Arrested for " .. SRP.Characters.FormatTime(timeLeft))
end

SRP.Characters.GetWantedTimeRemaining(ply)

local timeLeft = SRP.Characters.GetWantedTimeRemaining(ply)

SRP.Characters.GetDeathTimeRemaining(ply)

local timeLeft = SRP.Characters.GetDeathTimeRemaining(ply)

Timer Management

SRP.TimeKeeper.SetDeathTimer(ply)

local success = SRP.TimeKeeper.SetDeathTimer(ply)

Sets a death timer (default 10 minutes) and marks character as dead.

SRP.TimeKeeper.SetArrestTimer(ply)

local success = SRP.TimeKeeper.SetArrestTimer(ply)

Sets an arrest timer (default 30 minutes) and marks character as arrested.

SRP.TimeKeeper.SetWantedTimer(ply)

local success = SRP.TimeKeeper.SetWantedTimer(ply)

Sets a wanted timer (default 24 hours) and marks character as wanted.

SRP.TimeKeeper.ClearDeathTimer(ply)

local success = SRP.TimeKeeper.ClearDeathTimer(ply)

Manually clears the death timer and status.

SRP.TimeKeeper.ClearArrestTimer(ply)

local success = SRP.TimeKeeper.ClearArrestTimer(ply)

Manually clears the arrest timer and status.

SRP.TimeKeeper.ClearWantedTimer(ply)

local success = SRP.TimeKeeper.ClearWantedTimer(ply)

Manually clears the wanted timer and status.

SRP.TimeKeeper.GetDeathTimeRemaining(ply)

local seconds = SRP.TimeKeeper.GetDeathTimeRemaining(ply)

Returns remaining time in seconds for death timer.

SRP.TimeKeeper.GetArrestTimeRemaining(ply)

local seconds = SRP.TimeKeeper.GetArrestTimeRemaining(ply)

Returns remaining time in seconds for arrest timer.

SRP.TimeKeeper.GetWantedTimeRemaining(ply)

local seconds = SRP.TimeKeeper.GetWantedTimeRemaining(ply)

Returns remaining time in seconds for wanted timer.

SRP.TimeKeeper.IsTimerActive(ply, timerType)

if SRP.TimeKeeper.IsTimerActive(ply, "death") then
    -- player has active death timer
end

Check if a specific timer type is active. Types: "death", "arrest", "wanted"

SRP.TimeKeeper.FormatTime(seconds)

local formatted = SRP.TimeKeeper.FormatTime(3661)
-- Returns: "1h 1m 1s"

Formats seconds into readable time format.

SRP.TimeKeeper.SetConfig(configTable)

SRP.TimeKeeper.SetConfig({
    deathDuration = 300,    -- 5 minutes
    arrestDuration = 600,   -- 10 minutes
    wantedDuration = 7200   -- 2 hours
})

Updates timer durations. All values are in seconds.

SRP.TimeKeeper.GetConfig()

local config = SRP.TimeKeeper.GetConfig()

Returns current timer configuration.

Firearm Registration

SRP.Characters.GetRegisteredFirearms(ply)

Command: srp_getfirearms <player>
local firearms = SRP.Characters.GetRegisteredFirearms(ply)

SRP.Characters.AddRegisteredFirearm(ply, firearm)

Command: srp_addfirearm <player> <firearm>
local success = SRP.Characters.AddRegisteredFirearm(ply, "pistol_001")

SRP.Characters.RemoveRegisteredFirearm(ply, firearm)

Command: srp_removefirearm <player> <firearm>
local success = SRP.Characters.RemoveRegisteredFirearm(ply, "pistol_001")

SRP.Characters.ClearRegisteredFirearms(ply)

Command: srp_clearfirearms <player>
local success = SRP.Characters.ClearRegisteredFirearms(ply)

Financial

SRP.Characters.GetFines(ply)

Command: srp_getfines <player>
local fines = SRP.Characters.GetFines(ply)

SRP.Characters.ModifyFines(ply, amount)

Command: srp_addfines <player> <amount>
SRP.Characters.ModifyFines(ply, 50)  -- Add $50 fine
SRP.Characters.ModifyFines(ply, -25) -- Remove $25 fine

SRP.Characters.SetFines(ply, amount)

Command: srp_setfines <player> <amount>
local success = SRP.Characters.SetFines(ply, 100)

Transactions

SRP.Characters.Transaction(fromPlayer, toPlayer, amount, reason)

Command: srp_transaction <from_player> <to_player> <amount> [reason]
local success, result = SRP.Characters.Transaction(buyer, seller, 200, "Item Purchase")
if success then
    print("Transaction successful!")
    print("Buyer new balance:", result.from)
    print("Seller new balance:", result.to)
end

Utility Functions

SRP.Characters.FormatTime(seconds)

local timeString = SRP.Characters.FormatTime(3600)
-- Returns: "1h"

-- Example usage:
local arrestTime = SRP.Characters.GetArrestTimeRemaining(ply)
if arrestTime > 0 then
    local timeLeft = SRP.Characters.FormatTime(arrestTime)
    ply:ChatPrint("You are arrested for " .. timeLeft)
end

Formats seconds into a readable time string (e.g., "1d 2h 3m 4s").

SRP.Characters.UpdateCharacterFull(ply, updates)

local updates = {
    name = "New Name",
    alignment = 75,
    model = "models/player/group01/female_02.mdl"
}
local success = SRP.Characters.UpdateCharacterFull(ply, updates)

SRP.Characters.GetActiveCharacter(ply)

local character = SRP.Characters.GetActiveCharacter(ply)

SRP.Characters.GetActiveCharacterUID(ply)

local uid = SRP.Characters.GetActiveCharacterUID(ply)

Character Overview

Complete Character Information

Command: srp_charinfo <player>

Displays a comprehensive overview of a character's information including UID, name, money, role, alignment, fines, attributes, and status conditions.

Available Hooks

SRP_PlayerDeathTimerSet

hook.Add("SRP_PlayerDeathTimerSet", "MyAddon", function(ply, duration)
    print(ply:Nick() .. " death timer set for " .. duration .. " seconds")
end)

Called when a death timer is set for a player.

SRP_PlayerArrestTimerSet

hook.Add("SRP_PlayerArrestTimerSet", "MyAddon", function(ply, duration)
    print(ply:Nick() .. " arrest timer set for " .. duration .. " seconds")
end)

Called when an arrest timer is set for a player.

SRP_PlayerWantedTimerSet

hook.Add("SRP_PlayerWantedTimerSet", "MyAddon", function(ply, duration)
    print(ply:Nick() .. " wanted timer set for " .. duration .. " seconds")
end)

Called when a wanted timer is set for a player.

SRP_PlayerDeathTimerCleared

hook.Add("SRP_PlayerDeathTimerCleared", "MyAddon", function(ply)
    print(ply:Nick() .. " death timer manually cleared")
end)

Called when a death timer is manually cleared.

SRP_PlayerArrestTimerCleared

hook.Add("SRP_PlayerArrestTimerCleared", "MyAddon", function(ply)
    print(ply:Nick() .. " arrest timer manually cleared")
end)

Called when an arrest timer is manually cleared.

SRP_PlayerWantedTimerCleared

hook.Add("SRP_PlayerWantedTimerCleared", "MyAddon", function(ply)
    print(ply:Nick() .. " wanted timer manually cleared")
end)

Called when a wanted timer is manually cleared.

SRP_PlayerDeathTimerExpired

hook.Add("SRP_PlayerDeathTimerExpired", "MyAddon", function(ply)
    print(ply:Nick() .. " death timer expired - player respawned")
    ply:Spawn()
end)

Called when a death timer expires naturally.

SRP_PlayerArrestTimerExpired

hook.Add("SRP_PlayerArrestTimerExpired", "MyAddon", function(ply)
    print(ply:Nick() .. " arrest timer expired - player released")
end)

Called when an arrest timer expires naturally.

SRP_PlayerWantedTimerExpired

hook.Add("SRP_PlayerWantedTimerExpired", "MyAddon", function(ply)
    print(ply:Nick() .. " wanted status expired")
end)

Called when a wanted timer expires naturally.

Command List

All commands require admin privileges and follow the format: command <required> [optional]

Money Management

srp_getmoney <player>
srp_addmoney <player> <amount>
srp_removemoney <player> <amount>
srp_setmoney <player> <amount>

Character Data

srp_getcharacterdata <player> [path]
srp_setcharacterdata <player> <path> <value>
srp_charinfo <player>

Character Information

srp_getname <player>
srp_setname <player> <name>
srp_getalignment <player>
srp_setalignment <player> <alignment>
srp_getrole <player>
srp_setrole <player> <role>

Character Appearance

srp_getmodel <player>
srp_setmodel <player> <model>
srp_getbodygroups <player>
srp_setbodygroup <player> <bodygroup> <value>

Character Attributes

srp_getattributes <player>
srp_addattribute <player> <attribute>
srp_removeattribute <player> <attribute>

Status Management

srp_arrest <player>
srp_unarrest <player>
srp_arreststatus <player>
srp_setwanted <player>
srp_clearwanted <player>
srp_wantedstatus <player>
srp_kill <player>
srp_revive <player>
srp_deathstatus <player>

Firearm Registration

srp_getfirearms <player>
srp_addfirearm <player> <firearm>
srp_removefirearm <player> <firearm>
srp_clearfirearms <player>

Financial

srp_getfines <player>
srp_setfines <player> <amount>
srp_addfines <player> <amount>

Transactions

srp_transaction <from_player> <to_player> <amount> [reason]