전투 스크립트
Coddy의 Roblox 게임: 배틀그라운드 코스 레슨. 25개 중 1번째.
이 강좌에서는 검, 키보드 키와 휴대폰 버튼으로 사용하는 능력, 콤보와 막기, 그리고 경기장 곳곳에서 플레이어를 쫓는 봇이 있는 배틀그라운드 게임을 만듭니다.
게임에는 스크립트가 두 개 있습니다. Script인 BattleServer는 Roblox 서버에서 실행되며 모든 규칙을 관리합니다. HUD 안의 LocalScript인 BattleClient는 각 플레이어의 기기에서 실행되며, 2장까지 주석만 들어 있습니다. 게임 밸런스를 조정하는 모든 숫자는 ReplicatedStorage.Settings에 있습니다.
검은 Tool입니다. 플레이어의 도구는 Backpack에 들어 있으며, 플레이어가 다시 생성될 때마다 Backpack이 비워집니다. 따라서 검은 플레이어가 게임에 참가할 때 한 번 지급하는 것이 아니라, 매번 CharacterAdded에서 지급합니다:
player.CharacterAdded:Connect(function()
local sword = ServerStorage.Sword:Clone()
sword.Parent = player.Backpack
end)1을 누르거나 화면 아래쪽의 검을 탭해 검을 들 수 있습니다.
챌린지
쉬움전투 스크립트인 BattleServer를 시작하고 검을 지급하세요.
- 설정을 불러오세요:
local Settings = require(game.ReplicatedStorage.Settings). "Swords deal " .. Settings.SwordDamage .. " damage"를 출력하세요.Players.PlayerAdded에서player.CharacterAdded가 발생할 때마다ServerStorage.Sword를 복제해player.Backpack에 넣으세요.
‘플레이’를 누르고 1을 누르세요. Output에 Swords deal 10 damage가 표시되고 검을 들게 됩니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
-- BattleServer: 서버에서 게임을 실행하는 Script.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
-- 1. 설정을 불러옵니다: ModuleScript를 require합니다
-- game.ReplicatedStorage.Settings
-- 2. Settings.SwordDamage를 사용해 검 공격의 피해량을 출력합니다
-- 3. 플레이어가 접속하면: 캐릭터가 생성될 때마다
-- ServerStorage.Sword의 복사본을 해당 플레이어의 Backpack에 넣습니다
Roblox 게임: 배틀그라운드의 모든 레슨
직접 연습해 보세요: Roblox 플레이그라운드