首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >罗布洛快速调平系统RPG小游戏

问罗布洛快速调平系统RPG小游戏
EN

Stack Overflow用户
提问于 2021-12-14 20:23:46
回答 1查看 318关注 0票数 0

大家好,这是我第一次编写脚本,我正在考虑修复一个预先准备好的水准系统。这是一个非常快速的水准系统,问题是如果玩家已经超过了一次调平所需的经验,我如何才能像下面的例子那样立即做到这一点:

,我有一千万的经验,我只需要10,000,以达到水平。我如何使它立即达到100 K级?

因为我不希望玩家在我的游戏中有经验问题,所以请帮助。

代码语言:javascript
复制
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)

这就是剧本的样子。我应该添加什么才能“跳过”溢出体验,使玩家慢慢地达到水平?

这就是现在的水平。我在过去的一个小时里都不动(Td = 1+e42)

EN

回答 1

Stack Overflow用户

发布于 2021-12-14 22:50:32

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

当玩家获得大量经验时,您可以调用LevelUp函数。然后,当玩家有足够的经验时,提高玩家的水平。而循环将继续执行此循环,直到他们不再有足够的经验,以继续水平。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70355120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档