Upgrade Scripts Docs

#Server

Server-side exports for linking the rewards system into your own resources.

local rewards = exports['upgrade-rewards']

Every export takes a target, which is either a server id (the player must be online) or a rewards identifier string - the license value shown in the admin panel. Passing an identifier works for offline players too.

Amounts are whole numbers. Points and XP are independent: points are the shop currency, XP only moves the level bar.

These exports key on the resource's folder name. If you renamed the folder, use that name in place of upgrade-rewards.

#Reading

#GetPoints

Returns the player's current points balance, or nil if they have no rewards record yet.

local points = exports['upgrade-rewards']:GetPoints(source)

if points and points >= 500 then
    -- they can afford it
end

#GetLevel

Returns the player's current level, starting at 1, or nil if they have no record.

if (exports['upgrade-rewards']:GetLevel(source) or 1) >= 10 then
    -- unlock something
end

#GetLevelData

Returns everything about a player's progress in one call, or nil if they have no record.

local data = exports['upgrade-rewards']:GetLevelData(source)
{
    license     = 'license:abc...',
    level       = 7,
    experience  = 340,     -- XP into the current level
    nextLevelXp = 2000,    -- XP needed to leave it (0 at max level)
    title       = 'Rookie',
    points      = 1250,
    playtime    = 51420,   -- seconds, live value if they are online
}

#Changing

Each of these writes an entry to the player's points history, posts to the ExportPoints or ExportXP Discord webhook naming your resource, and refreshes the player's menu if they have it open.

#AddPoints

local result = exports['upgrade-rewards']:AddPoints(source, 250, 'Race win')
-- { success = true, points = 1500, previous = 1250 }

#RemovePoints

Fails rather than taking the balance negative.

local result = exports['upgrade-rewards']:RemovePoints(source, 500, 'Bought a garage slot')

if not result.success then
    print(result.message)  -- 'insufficient points', with result.points = current balance
end

#AddXP

local result = exports['upgrade-rewards']:AddXP(source, 100, 'Completed a heist')
-- { success = true, leveled_up = false, old_level = 7, new_level = 7, title = 'Rookie' }

if result.leveled_up then
    -- they just levelled
end

Level-up rewards, the notification and the LevelUp webhook all fire normally when XP granted this way crosses a threshold.

#The reason argument

reason is optional on all three. It becomes the description in the player's points history. Left out, the entry reads "Points added by <resource>" or "XP granted by <resource>".

#Failure

Every changing export returns { success = false, message = '...' } when something goes wrong. The messages are fixed strings you can branch on:

  • unknown player
  • no rewards record for player
  • amount must be a positive number
  • insufficient points

#Legacy exports

These still work and now route through the exports above. New integrations should use the names above instead.

#addexp

exports['upgrade-rewards']:addexp(playerid, amount)

#addpoints

exports['upgrade-rewards']:addpoints(playerid, amount)

A negative amount passed to addpoints now correctly removes points and records it as a deduction in the player's history. Both return false on failure.