【发布时间】:2020-11-17 10:53:19
【问题描述】:
此代码在游戏开始时在某个区域内的地图上生成 100 只鸡,但是玩家已经收集了所有 100 只鸡,没有剩余可收集所以我想知道如何重新生成另外 100 只鸡说一次剩下的数量已经下降到 10,所以玩家将有连续数量的鸡来收集,希望这是有道理的,在此先感谢。日本人
local newChicken = game.ServerStorage:FindFirstChild("ChickenOnePart")
local TopLeftCorner = Vector3.new(-187.64, 20.679, 106.2)
local BottomRightCorner = Vector3.new(201.12, 20.679, -241.45)
local numberOfChickens = 100
local counter = 0
local singleTonRandom = Random.new(tick())
local function GetRandom(Min,Max)
return singleTonRandom:NextNumber(Min,Max)
end
while counter < numberOfChickens do
local chicken = newChicken:Clone()
chicken.Anchored = true
chicken.Parent = game.Workspace
chicken.Name = "Chicken"
chicken.Position = Vector3.new(
GetRandom(TopLeftCorner.X,BottomRightCorner.X),
4,
GetRandom(TopLeftCorner.Z,BottomRightCorner.Z)
)
counter = counter + 1
end
此代码在玩家每次触摸鸡时将计数器加 1。我能从这里得到当前的鸡数吗?
if hitPart.Name == "Chicken" then
event:FireServer(hitPart)
local currentcount = playerGUI.ChickenGui.ChickenCounter.Text
playerGUI.ChickenGui.ChickenCounter.Text = currentcount + 1
hitPart:Destroy()
debounce = true
wait(0.1)
debounce = false
end
end)
以及用于更新领导者的代码。
local event = Instance.new("RemoteEvent")
event.Name = "CurrencyAdd"
event.Parent = game.ReplicatedStorage
event.OnServerEvent:Connect(function(plr,part)
local currency = plr.leaderstats.Chickens
currency.Value = currency.Value + 1
end)
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
local m = Instance.new("IntValue",ls)
m.Name = "Chickens"
ls.Parent = plr
local cash = Instance.new("IntValue",ls)
cash.Name = "Cash"
end)
@Piglet 谢谢你,我有点明白你的意思是什么?
local newChicken = game.ServerStorage:FindFirstChild("ChickenOnePart")
local TopLeftCorner = Vector3.new(-187.64, 20.679, 106.2)
local BottomRightCorner = Vector3.new(201.12, 20.679, -241.45)
local numberOfChickens = 100
local counter = 0
local singleTonRandom = Random.new(tick())
local function GetRandom(Min,Max)
return singleTonRandom:NextNumber(Min,Max)
end
for counter = 1, numberOfChickens do
local chicken = newChicken:Clone()
chicken.Anchored = true
chicken.Parent = game.Workspace
chicken.Name = "Chicken"
chicken.Position = Vector3.new(
GetRandom(TopLeftCorner.X,BottomRightCorner.X),
4,
GetRandom(TopLeftCorner.Z,BottomRightCorner.Z)
)
counter = counter + 1
end
function AddChicken(num)
for count = 10, num do
local chicken = newChicken:Clone()
chicken.Anchored = true
chicken.Parent = game.Workspace
chicken.Name = "Chicken"
chicken.Position = Vector3.new(
GetRandom(TopLeftCorner.X,BottomRightCorner.X),
4,
GetRandom(TopLeftCorner.Z,BottomRightCorner.Z)
)
end
end
AddChicken(90)
对不起,我只是在学习这一切
【问题讨论】:
-
您是否有任何代码可以检测玩家何时触摸鸡?
-
嗨,是的,我有你的意思的代码,我将它添加到操作中。希望这可以帮助。问候 jp
-
使用 for 循环而不是带计数器的 while 循环
-
嗨@Piglet 你能给我一个例子吗,因为我不是 100% 了解所使用的语法,我知道它类似于 (for i = 1,10,1 do) 但不确定在哪里把代码,soz
标签: loops while-loop lua roblox