大家好,这是我第一次编写脚本,我正在考虑修复一个预先准备好的水准系统。这是一个非常快速的水准系统,问题是如果玩家已经超过了一次调平所需的经验,我如何才能像下面的例子那样立即做到这一点:
,我有一千万的经验,我只需要10,000,以达到水平。我如何使它立即达到100 K级?
因为我不希望玩家在我的游戏中有经验问题,所以请帮助。
local LevelUp = function(plr, Level, XP)
if XP.Value >= Level.Value * 25 then
-- Leveling
XP.Value = XP.Value - Level.Value * 25
Level.Value = Level.Value + 1
-- Health
if (not plr.Character) then return end
local hum = plr.Character:WaitForChild("Humanoid")
hum.MaxHealth = hum.MaxHealth + 10
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
local hum = chr:WaitForChild("Humanoid",10)
local leaderstats = plr:WaitForChild("leaderstats")
local Level = leaderstats:WaitForChild("Level")
repeat wait() until plr:FindFirstChild("DataLoaded")~=nil
hum.MaxHealth = Level.Value * 10 + 100
hum.Health = hum.MaxHealth
end)
local leaderstats = plr:WaitForChild("leaderstats")
local Level = leaderstats:WaitForChild("Level")
local XP = leaderstats:WaitForChild("XP")
Level.Changed:Connect(function() wait() LevelUp(plr, Level, XP) end)
XP.Changed:Connect(function() wait() LevelUp(plr, Level, XP) end)
end)这就是剧本的样子。我应该添加什么才能“跳过”溢出体验,使玩家慢慢地达到水平?
发布于 2021-12-14 22:50:32
时间循环将是这里使用的一个简单工具。
当玩家获得大量经验时,您可以调用LevelUp函数。然后,当玩家有足够的经验时,提高玩家的水平。而循环将继续执行此循环,直到他们不再有足够的经验,以继续水平。
local function LevelUp(plr, Level, XP)
-- find the player's humanoid
local hum = nil
if (plr.Character) then
hum = plr.Character:WaitForChild("Humanoid")
end
local currentLevel = Level.Value
local currentExp = XP.Value
local targetExp = Level.Value * 25
while (curentExp >= targetExp) do
-- Leveling
currentExp -= targetExp
currentLevel += 1
-- Recalculate how much experience we need for the next level
targetExp = currentLevel * 25
-- Increase the Player's health
if (hum) then
hum.MaxHealth = hum.MaxHealth + 10
end
end
-- update the NumberValues at the end so we don't kick off endless while loops
if (currentLevel ~= Level.Value) then
Level.Value = currentLevel
end
if (currentExp ~= XP.Value) then
XP.Value = currentExp
end
endhttps://stackoverflow.com/questions/70355120
复制相似问题