如何在roblox上制作排行榜?
答案 0 :(得分:2)
在每个玩家需要插入一个名为'leaderstats'的值,使用带有PlayerAdded事件的脚本。在leaderstats值中,您可以放置IntValues - 它们的名称将显示为标题,它们的值将显示为玩家的统计数据。
要更改这些统计信息,您需要向创建leaderstats值的脚本添加不同的函数和/或事件。
答案 1 :(得分:2)
将脚本插入工作区,然后在代码中输入:
function Onplayerentered(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Parent = player
leaderstats.Value = 0
leaderstats.Name = "leaderstats"
local stat = Instance.new("IntValue")
stat.Name = "" -- Put name here in between the quotations
stat.Value = -- Put the starting Value#
end
game:GetService("Players").ChildAdded:Connect(Onplayerentered)
答案 2 :(得分:0)
答案 3 :(得分:0)
Roblox排行榜是一个非常长的脚本,谢天谢地,该脚本允许我们轻松添加和删除leadertats。要添加排行榜,请在玩家对象内部插入IntValue,以便在leadestats中添加stat插入IntValue。
Roblox上的大多数游戏都希望每个玩家拥有相同的排行榜。所以大多数人使用PlayerAdded事件并创建排行榜
答案 4 :(得分:0)
功能Onplayererntered(播放器)
local leaderstats = Instance.new("IntValue")
leaderstats.Pareny = player
leaderstats.Value = 0
leaderstats.Name = "leaderboard"
local stat = Instance.new("IntValue")
statname = "Cash"
stat.Value = 100
端
答案 5 :(得分:0)
将脚本插入ServerScriptService并粘贴以下代码:
plrEntered = function(plr)
local ls = Instance.new('IntValue') --Leaderstats
ls.Parent = plr
ls.Value = 0
ls.Name = 'leaderstats'
local stat = Instance.new('IntValue')
stat.Name = 'Money' -- Change to the value you want
stat.Value = 0 -- Add the starting value
end
game:GetService'Players'.PlayerAdded(plrEntered)
答案 6 :(得分:0)
ROBLOX将排行榜定义为一个名为' leaderstats'并位于播放器对象中。排行榜统计信息被定义为leaderstats对象内的值对象(Player> leaderstats> ValueObject)。因此,让我们编写一个功能,创建一个带有'现金的排行榜。玩家的统计数据。
local function createLeaderboard(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
stats.Parent = player
end
然后我们需要做这项工作。我们需要将此功能连接到' PlayerAdded'来自'玩家的活动'对象
local players = game:WaitForChild("Players")
players.PlayerAdded:connect(createLeaderboard)
基本上就是这样。 请注意,上面直接显示的代码中的第3行等同于:
players.PlayerAdded:connect(function(player)
createLeaderboard(player)
end)
整个脚本看起来像这样:
local players = game:WaitForChild("Players")
local function createLeaderboard(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
stats.Parent = player
end
players.PlayerAdded:connect(createLeaderboard)
建议将脚本放在' ServerScriptService'。
中答案 7 :(得分:-1)
// pure virt. interface, remember about virtual dtor
class coffeeStorage {
public:
virtual ~coffeeStorage() = default;
virtual void takeCoffeeStorage() = 0;
virtual void setWaterStorage(int amount) = 0;
virtual void setBeansStorage(int amount) = 0;
virtual void emptyTrashStorage() = 0;
virtual int checkWater() = 0;
virtual int checkBeans() = 0;
virtual int checkTrashStorage() = 0;
};
class coffeeStockService {
public:
virtual ~coffeeStockService() = default;
virtual void restockWater(coffeeStorage& storeage) = 0;
};
class coffeeMachine {
public:
coffeeMachine(coffeeStorage* CoffeeStorage, coffeeStockService* CoffeeStockService);
void fillTank() {
CoffeeStockService->restockWater(*CoffeeStorage);
}
void takeCoffee() {
if (CoffeeStorage->checkWater() == 0 || CoffeeStorage->checkBeans() == 0) {
coffeeServed = false;
}
else {
coffeeServed = true;
CoffeeStorage->takeCoffeeStorage();
}
}
bool isCoffeeServed() {
return coffeeServed;
}
private:
coffeeStorage* CoffeeStorage;
coffeeStockService* CoffeeStockService;
bool coffeeServed{false};
};
coffeeMachine::coffeeMachine(coffeeStorage* CoffeeStorage_, coffeeStockService* CoffeeStockService_)
: CoffeeStorage{CoffeeStorage_}
, CoffeeStockService{CoffeeStockService_} {}
class mockCoffeeStorage : public coffeeStorage {
public:
MOCK_METHOD0(takeCoffeeStorage, void());
MOCK_METHOD1(setWaterStorage, void(int amount));
MOCK_METHOD1(setBeansStorage, void(int amount));
MOCK_METHOD0(emptyTrashStorage, void());
MOCK_METHOD0(checkWater, int());
MOCK_METHOD0(checkBeans, int());
MOCK_METHOD0(checkTrashStorage, int());
};
class mockCoffeeStockService : public coffeeStockService {
public:
MOCK_METHOD1(restockWater, void(coffeeStorage& storeage));
};
struct MockObjTest : public testing::Test {
mockCoffeeStorage mockedCoffeeStorage;
mockCoffeeStockService mockedCoffeeStockService;
coffeeMachine coffeeTest = coffeeMachine(&mockedCoffeeStorage, &mockedCoffeeStockService);
};
TEST_F(MockObjTest, When_FillingTank_Then_RestocksWater) {
// assert
EXPECT_CALL(mockedCoffeeStockService, restockWater(testing::Ref(mockedCoffeeStorage)));
// act
coffeeTest.fillTank();
}
TEST_F(MockObjTest, Given_NoWater_When_TakingCoffee_Then_CoffeeNotServed) {
// arrange
EXPECT_CALL(mockedCoffeeStorage, checkWater()).WillOnce(testing::Return(0));
// act
coffeeTest.takeCoffee();
// assert
ASSERT_FALSE(coffeeTest.isCoffeeServed());
}
TEST_F(MockObjTest, Given_EnoughWaterWaterAndBeans_When_TakingCoffee_Then_takeCoffeeStorageAndCoffeeServed) {
// arrange
EXPECT_CALL(mockedCoffeeStorage, checkWater()).WillOnce(testing::Return(1));
EXPECT_CALL(mockedCoffeeStorage, checkBeans()).WillOnce(testing::Return(1));
EXPECT_CALL(mockedCoffeeStorage, takeCoffeeStorage()); // this is more of the 'assert' part, but it cannot be moved to the end of the test
// act
coffeeTest.takeCoffee();
// assert
ASSERT_TRUE(coffeeTest.isCoffeeServed());
}