jesus took the wheel

i think this one is right
This commit is contained in:
gononono64 committed 2025-06-23 00:56:49 -05:00
1 parent 7a6d49393f
commit 8d17447f59
1 file changed
+146 -16
+146 -16
View File
@@ -1,6 +1,20 @@
---@diagnostic disable: duplicate-set-field
Skills = Skills or {}
Skills.All = Skills.All or {}
-- Helper function to get or create a skill object
local function getOrCreateSkill(src, skillName)
if not src or not skillName then return { totalXP = 0, xp = 0, level = 1, xpNeededForNextLevel = 0 } end
-- Get player skills
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
if not playerSkills[skillName] then
playerSkills[skillName] = { totalXP = 0, xp = 0, level = 1, xpNeededForNextLevel = 0 }
end
return playerSkills[skillName]
end
---This will get the name of the Skills system being being used.
---@return string
Skills.GetResourceName = function()
@@ -60,75 +74,191 @@ Skills.GetScaledXP = function(baseXP, playerLevel)
return math.floor(baseXP * (1 + playerLevel * 0.05))
end
-- Get skill level for a player
Skills.GetSkillLevel = function(src, skillName)
if not src or not skillName then return 1 end
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
local skill = playerSkills[skillName] or { xp = 0, level = 1 }
local skill = getOrCreateSkill(src, skillName)
return skill.level or 1
end
-- Set skill level directly (resets XP to start of level)
Skills.SetSkillLevel = function(src, skillName, level)
if not src or not skillName or not level or level < 1 then return false end
-- Create skill if it doesn't exist
if not Skills.All[skillName] then
Skills.All[skillName] = Skills.Create(skillName, 99, 50)
end
-- Get skill and metadata
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
local skill = playerSkills[skillName] or { xp = 0, level = 1 }
skill.level = math.min(Skills.All[skillName].maxLevel, level)
skill.xp = 0
local skill = playerSkills[skillName] or { totalXP = 0, xp = 0, level = 1 }
-- Clamp the level to valid range
level = math.min(math.max(1, level), Skills.All[skillName].maxLevel)
-- Set the level and reset level XP
local previousLevelXP = Skills.GetTotalXPForLevel(skillName, level - 1)
skill.level = level
skill.totalXP = previousLevelXP
skill.xp = 0
skill.xpNeededForNextLevel = Skills.GetTotalXPForLevel(skillName, level) - previousLevelXP
-- Save changes
playerSkills[skillName] = skill
Framework.SetPlayerMetadata(src, "community_bridge_skills", playerSkills)
return true
end
-- Add XP to a skill using the RuneScape algorithm
Skills.AddXP = function(src, skillName, xp)
if not src or not skillName then return false end
-- Create skill if it doesn't exist
if not Skills.All[skillName] then
Skills.All[skillName] = Skills.Create(skillName, 99, 50)
end
-- Default XP amount if not provided or invalid
if not xp or xp < 0 then
xp = Skills.GetScaledXP(Skills.All[skillName].baseXP, Skills.GetSkillLevel(src, skillName))
end
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
local skill = playerSkills[skillName] or { xp = 0, level = 1 }
skill.totalXP = (skill.totalXP or skill.xp or 0) + xp
skill.level = Skills.GetLevelFromXP(skillName, skill.totalXP)
local xpToReduce = Skills.GetTotalXPForLevel(skillName, skill.level - 1)
skill.xp = math.max(0, skill.totalXP - xpToReduce)
-- Get skill and metadata
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
local skill = playerSkills[skillName] or { totalXP = 0, xp = 0, level = 1 }
-- Store old level for detecting level up
local oldLevel = skill.level
-- Add XP to total
skill.totalXP = (skill.totalXP or 0) + math.max(0, xp)
-- Calculate new level based on total XP
skill.level = Skills.GetLevelFromXP(skillName, skill.totalXP)
-- Update current level XP and XP needed for next level
local previousLevelXP = Skills.GetTotalXPForLevel(skillName, skill.level - 1)
local nextLevelXP = Skills.GetTotalXPForLevel(skillName, skill.level)
skill.xp = skill.totalXP - previousLevelXP
skill.xpNeededForNextLevel = nextLevelXP - previousLevelXP
-- Handle level up
if skill.level > oldLevel then
-- You can uncomment this to trigger level-up events
-- TriggerEvent("Skills:LevelUp", src, skillName, skill.level, oldLevel)
end
-- Save changes
playerSkills[skillName] = skill
Framework.SetPlayerMetadata(src, "community_bridge_skills", playerSkills)
return true
end
-- Set total XP for a skill (recalculates level)
Skills.SetXP = function(src, skillName, xp)
if not src or not skillName or not xp or xp < 0 then return false end
-- Create skill if it doesn't exist
if not Skills.All[skillName] then
Skills.All[skillName] = Skills.Create(skillName, 99, 50)
end
-- Get skill and metadata
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
local skill = playerSkills[skillName] or { xp = 0, level = 1 }
local skill = playerSkills[skillName] or { totalXP = 0, xp = 0, level = 1 }
-- Set total XP
skill.totalXP = math.max(0, xp)
-- Recalculate level and XP values
skill.level = Skills.GetLevelFromXP(skillName, skill.totalXP)
local xpToReduce = Skills.GetTotalXPForLevel(skillName, skill.level - 1)
skill.xp = math.max(0, skill.totalXP - xpToReduce)
-- Update current level XP and XP needed for next level
local previousLevelXP = Skills.GetTotalXPForLevel(skillName, skill.level - 1)
local nextLevelXP = Skills.GetTotalXPForLevel(skillName, skill.level)
skill.xp = skill.totalXP - previousLevelXP
skill.xpNeededForNextLevel = nextLevelXP - previousLevelXP
-- Save changes
playerSkills[skillName] = skill
Framework.SetPlayerMetadata(src, "community_bridge_skills", playerSkills)
return true
end
-- Calculate XP needed for next level (helper function)
local function calculateXPInfo(src, skillName, skill)
-- Calculate XP needed for next level
local currentLevel = skill.level or 1
local nextLevel = math.min(currentLevel + 1, Skills.All[skillName].maxLevel)
local currentLevelMinXP = Skills.GetTotalXPForLevel(skillName, currentLevel)
local nextLevelMinXP = Skills.GetTotalXPForLevel(skillName, nextLevel)
local previousLevelMinXP = Skills.GetTotalXPForLevel(skillName, currentLevel - 1)
-- Current level XP
skill.xp = skill.totalXP - previousLevelMinXP
-- XP needed for next level
skill.xpNeededForNextLevel = nextLevelMinXP - currentLevelMinXP
-- Percentage to next level
local xpInCurrentLevel = skill.totalXP - previousLevelMinXP
local xpRequiredForNextLevel = nextLevelMinXP - previousLevelMinXP
skill.percentToNextLevel = math.min(100, math.floor((xpInCurrentLevel / xpRequiredForNextLevel) * 100))
return skill
end
-- Get all of a player's skill data
Skills.GetAll = function(src)
if not src then return {} end
return Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
end
-- Get a specific skill object with all properties
Skills.Get = function(src, skillName)
if not src or not skillName then return nil end
local skill = getOrCreateSkill(src, skillName)
return calculateXPInfo(src, skillName, skill)
end
-- Get the current level XP value (not total XP)
Skills.GetXP = function(src, skillName)
if not src or not skillName then return 0 end
local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {}
local skill = playerSkills[skillName] or { xp = 0, level = 1 }
local skill = getOrCreateSkill(src, skillName)
return skill.xp or 0
end
-- Get total accumulated XP
Skills.GetTotalXP = function(src, skillName)
if not src or not skillName then return 0 end
local skill = getOrCreateSkill(src, skillName)
return skill.totalXP or 0
end
-- Get XP required for next level
Skills.GetXPNeededForNextLevel = function(src, skillName)
if not src or not skillName then return 0 end
local skill = getOrCreateSkill(src, skillName)
return calculateXPInfo(src, skillName, skill).xpNeededForNextLevel or 0
end
-- if not BridgeSharedConfig.DebugLevel or BridgeSharedConfig.DebugLevel == 0 then return end
RegisterCommand('ClearSkills', function(source, args, rawCommand)
if not source or source == 0 then return end
local playerSkills = Framework.GetPlayerMetadata(source, "community_bridge_skills") or {}
for skillName in pairs(playerSkills) do
playerSkills[skillName] = { totalXP = 0, xp = 0, level = 1, xpNeededForNextLevel = 0 }
end
Framework.SetPlayerMetadata(source, "community_bridge_skills", playerSkills)
print("Cleared all skills for player: " .. source)
end, true)
-- Skills.AddSkillLevel = function(src, skillName, amount)
-- if not src or not skillName then return false end