宠物脚本
Coddy Roblox 游戏:宠物模拟器 课程的第 1 课,共 20 课。
在这门课程中,你将制作一款宠物模拟器:打破金币堆,孵化蛋,收集会跟着你并让挖掘速度更快的宠物,开启新区域,并保存所有进度。
这款游戏有两个脚本。PetServer 是一个 Script,在 Roblox 的服务器上运行:它管理金币、宠物和所有规则。PetClient 是 HUD 中的一个 LocalScript,在每位玩家自己的设备上运行,并绘制他们的屏幕。你会在第 2 章接触客户端;现在,它的文件里只有一条注释。
用于平衡游戏的数值存放在一个 ModuleScript 中:ReplicatedStorage.Settings:
local Settings = require(game.ReplicatedStorage.Settings)
print("An egg costs " .. Settings.EggPrice) --> 一个蛋售价 25挑战
简单启动游戏的服务器脚本 PetServer。
- 加载设置:
local Settings = require(game.ReplicatedStorage.Settings)。 - 打印
"A Meadow pile gives " .. Settings.PileValue .. " coins"。 - 玩家加入时,为其创建一个包含名为
Coins的 IntValue 的leaderstats文件夹。
按“开始”:输出会显示 A Meadow pile gives 5 coins,排行榜上会出现 Coins。然后按“检查”。
亲手试试
-- PetServer:在服务器上运行游戏的 Script。
local Players = game:GetService("Players")
-- 1. 加载设置:使用 require 加载 ModuleScript
-- game.ReplicatedStorage.Settings
-- 2. 使用 Settings.PileValue 输出 Meadow 堆能提供什么
-- 3. 在排行榜上为每位玩家添加一个 Coins 值
-- (一个名为 leaderstats 的 Folder,其中包含一个名为 Coins 的 IntValue)
Roblox 游戏:宠物模拟器中的所有课
自己练习: Roblox 在线编辑器