-
로블록스(Roblox) 코딩 실습 12 : 더욱 심화된 AI 기능과 실시간 멀티플레이 요소Roblox 코딩 2025. 2. 24. 22:11
로블록스 코딩 실습: 더욱 심화된 AI 기능과 실시간 멀티플레이 요소 🚀🤖🎮
이번에는 패턴 기반 AI 공격, 팀 기반 전투 시스템, 실시간 채팅 시스템, 글로벌 랭킹 시스템과 같은 더욱 심화된 AI 기능과 실시간 멀티플레이 요소를 구현해보겠습니다. 이러한 기능들은 게임의 전략성, 실시간 상호작용, 경쟁 요소를 극대화할 수 있습니다! 😊
1️⃣ 패턴 기반 AI 공격 시스템 구현 ⚔️
적 AI가 일정한 패턴에 따라 다양한 공격을 수행하는 시스템을 구현해보겠습니다.
1. 적 캐릭터 추가
- Explorer 창에서 Workspace에 "Insert Object" -> Model을 추가하고 이름을 **"PatternEnemy"**로 변경합니다.
- Model 안에 Humanoid와 Head를 추가하고 HumanoidRootPart를 설정하세요.
2. 패턴 기반 AI 스크립트 작성
- PatternEnemy에 "Insert Object" -> Script를 추가합니다.
- 다음 코드를 입력합니다:
local enemy = script.Parent local humanoid = enemy:FindFirstChild("Humanoid") local attackPattern = {"Punch", "Kick", "Fireball"} -- 공격 패턴 리스트 local function performAttack(attackType) if attackType == "Punch" then print("적이 주먹 공격을 합니다!") elseif attackType == "Kick" then print("적이 발차기 공격을 합니다!") elseif attackType == "Fireball" then print("적이 불꽃 공격을 합니다!") end end while wait(2) do local randomAttack = attackPattern[math.random(1, #attackPattern)] performAttack(randomAttack) end
코드 설명
- attackPattern: 적의 공격 패턴 목록입니다.
- math.random(): 무작위로 공격 패턴을 선택합니다.
- performAttack(): 선택된 공격 패턴에 따라 동작을 수행합니다.
2️⃣ 팀 기반 전투 시스템 구현 🏅
플레이어가 서로 다른 팀에 배정되어 전투를 벌이는 시스템을 구현해보겠습니다.
1. 팀 설정하기
- Explorer 창에서 Teams 폴더를 추가합니다.
- Teams 폴더에 "Insert Object" -> Team을 추가하고 이름을 **"RedTeam"**과 **"BlueTeam"**으로 설정합니다.
- RedTeam: TeamColor를 빨간색으로 설정
- BlueTeam: TeamColor를 파란색으로 설정
2. 팀 전투 스크립트 작성
- ServerScriptService에 "Insert Object" -> Script를 추가합니다.
- 다음 코드를 입력합니다:
local Players = game:GetService("Players") local Teams = game:GetService("Teams") Players.PlayerAdded:Connect(function(player) if #Teams.RedTeam:GetPlayers() <= #Teams.BlueTeam:GetPlayers() then player.Team = Teams.RedTeam print(player.Name .. "님이 RedTeam에 배정되었습니다!") else player.Team = Teams.BlueTeam print(player.Name .. "님이 BlueTeam에 배정되었습니다!") end end)
코드 설명
- Teams:GetPlayers(): 해당 팀에 속한 플레이어 목록을 가져옵니다.
- player.Team: 플레이어의 팀을 설정합니다.
- PlayerAdded: 새로운 플레이어가 게임에 참여할 때 호출됩니다.
3️⃣ 실시간 채팅 시스템 구현 💬
플레이어들이 게임 내에서 실시간으로 채팅할 수 있는 시스템을 구현해보겠습니다.
1. 채팅 UI 추가
- StarterGui에 "Insert Object" -> ScreenGui를 추가합니다.
- ScreenGui 안에 TextBox와 TextLabel을 추가하고 이름을 각각 **"ChatInput"**과 **"ChatLog"**로 변경합니다.
2. 채팅 스크립트 작성
- ChatInput에 "Insert Object" -> LocalScript를 추가합니다.
- 다음 코드를 입력합니다:
local chatInput = script.Parent local chatLog = chatInput.Parent:WaitForChild("ChatLog") chatInput.FocusLost:Connect(function(enterPressed) if enterPressed then local message = chatInput.Text chatLog.Text = chatLog.Text .. "\n" .. message chatInput.Text = "" end end)
코드 설명
- FocusLost: 입력 필드에서 포커스를 잃을 때 호출됩니다.
- enterPressed: 엔터 키가 눌렸는지 확인합니다.
- chatLog.Text: 입력된 메시지를 채팅 로그에 추가합니다.
4️⃣ 글로벌 랭킹 시스템 구현 🏆
플레이어들의 점수를 기반으로 글로벌 랭킹을 표시하는 시스템을 구현해보겠습니다.
1. 랭킹 스크립트 작성
- ServerScriptService에 "Insert Object" -> Script를 추가합니다.
- 다음 코드를 입력합니다:
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local score = Instance.new("IntValue") score.Name = "Score" score.Value = math.random(0, 1000) -- 테스트용 랜덤 점수 score.Parent = leaderstats end) while wait(5) do print("글로벌 랭킹:") local scores = {} for _, player in pairs(Players:GetPlayers()) do local score = player:FindFirstChild("leaderstats"):FindFirstChild("Score") if score then table.insert(scores, {Name = player.Name, Score = score.Value}) end end table.sort(scores, function(a, b) return a.Score > b.Score end) for i, entry in ipairs(scores) do print(i .. "위: " .. entry.Name .. " - " .. entry.Score .. "점") end end
코드 설명
- table.insert(): 점수 데이터를 리스트에 추가합니다.
- table.sort(): 점수를 기준으로 내림차순 정렬합니다.
- 글로벌 랭킹 출력: 5초마다 전체 순위를 출력합니다.
마무리 ✨
이번 실습에서는 패턴 기반 AI 공격, 팀 기반 전투 시스템, 실시간 채팅 시스템, 글로벌 랭킹 시스템과 같은 더욱 심화된 AI 기능과 실시간 멀티플레이 요소를 구현해 보았습니다. 이러한 요소들은 게임의 전략성, 실시간 상호작용, 경쟁 요소를 강화해줍니다! 😊 다음에는 더욱 고급스러운 게임 메커니즘과 최적화 기법을 소개해드리겠습니다! 🚀
반응형'Roblox 코딩' 카테고리의 다른 글
로블록스(Roblox) 코딩 실습 14 : 더욱 창의적인 게임 디자인과 플레이어 맞춤형 콘텐츠 (0) 2025.02.24 로블록스(Roblox) 코딩 실습 13 : 더욱 고급스러운 게임 메커니즘과 최적화 기법 (0) 2025.02.24 로블록스(Roblox) 코딩 실습 11 : 더욱 창의적이고 인터랙티브한 게임 메커니즘과 협력 플레이 기능 (0) 2025.02.24 로블록스(Roblox) 코딩 실습 10 : 더욱 복잡한 AI 기능과 플레이어 맞춤형 게임 메커니즘 (0) 2025.02.24 로블록스(Roblox) 코딩 실습 9 : 더욱 흥미로운 게임 메커니즘과 AI 기능 (0) 2025.02.24