-- Example script to add reputation XP for mining
local playerId = 1
local category = 'mining'
local amount = 50
-- Add XP (single character)
exports['b2_reputation']:addReputationXPSingle(playerId, category, amount)
-- Add XP (multi-character)
exports['b2_reputation']:addReputationXPMulti(playerId, category, amount)
-- Get XP
local xpSingle = exports['b2_reputation']:getReputationXPSingle(playerId, category)
local xpMulti = exports['b2_reputation']:getReputationXPMulti(playerId, category)
-- Calculate reputation level
local levelSingle = exports['b2_reputation']:calculateReputationLevel(playerId, category)
local levelMulti = exports['b2_reputation']:calculateReputationLevel(playerId, category)
print("Single Character - XP: ", xpSingle, "Level: ", levelSingle)
print("Multi Character - XP: ", xpMulti, "Level: ", levelMulti)
Client-side Example
Since the exports are server-side, you would typically call them from the server and handle client notifications or updates accordingly.
-- Client script to show reputation level
RegisterNetEvent('b2_reputation:showReputationLevel')
AddEventHandler('b2_reputation:showReputationLevel', function(level)
-- Replace with your preferred notification system
print("Your reputation level is: ", level)
end)
Initializing Player Data
To ensure player data is initialized correctly on first connection, make sure the following event handler is included:
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local src = source
local id = getPlayerIdentifierOrCharId(src)
if not id then
return
end
if Config.MultiCharacter then
MySQL.Async.execute('INSERT IGNORE INTO user_reputation (character_id, mining, fishing, weed_harvesting) VALUES (@id, 0, 0, 0)', {
['@id'] = id
})
else
MySQL.Async.execute('INSERT IGNORE INTO player_reputation (player_id, mining, fishing, weed_harvesting) VALUES (@id, 0, 0, 0)', {
['@id'] = id
})
end
end)
Conclusion
The B2 Reputation System is a flexible and powerful tool for managing player reputations in your FiveM server. By following the steps outlined in this guide, you can easily integrate it into your server and customize it to meet your specific needs. If you have any questions or need further assistance, feel free to reach out.