【问题标题】:Quick Levelling System on Roblox RPG gamesRoblox RPG 游戏的快速调平系统
【发布时间】:2022-01-18 03:12:00
【问题描述】:

大家好,这几乎是我第一次编写脚本,我正在寻找修复一个预制的调平系统。这是一个非常快速的升级系统,问题是如果玩家的经验远远超过升级 1 次所需的经验,我怎样才能像这个例子那样立即实现:

我有1000万经验,我只需要10k就可以升级。我怎样才能立即实现这一目标并达到 100k 级?

由于我不希望玩家在我的游戏中遇到体验问题,所以请帮忙。

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)

这就是脚本的样子。我应该添加什么才能“跳过”溢出体验,导致玩家升级缓慢?

This is what the levels looks like right now. I'm staying still for the past hour now (Td = 1+e42)

【问题讨论】:

  • 我理解的对吗?您想将数字四舍五入?

标签: lua roblox levels


【解决方案1】:

while 循环将是一个在这里使用的简单工具。

当玩家获得大量经验时,您调用LevelUp 函数。然后,在玩家有足够经验的同时,提高玩家等级。 while-loop 会继续执行这个循环,直到他们不再有足够的经验继续练级。

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
end

【讨论】:

    猜你喜欢
    • 2020-12-17
    • 2011-10-16
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 2011-03-15
    • 1970-01-01
    相关资源
    最近更新 更多