ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 로블록스(Roblox) 코딩 실습 18 : 플레이어 분석과 게임 통계 시스템
    Roblox 코딩 2025. 2. 24. 23:36

    로블록스 코딩 실습: 플레이어 분석과 게임 통계 시스템 📊📈

    이번에는 플레이어 활동 분석, 접속 시간 통계, 점수 및 승률 통계, 인기 콘텐츠 분석, 실시간 통계 대시보드와 같은 플레이어 분석과 게임 통계 시스템을 구현해보겠습니다. 이러한 기능들은 플레이어의 행동을 분석하고 게임의 성과를 평가할 수 있게 하여 게임 개선과 운영 전략 수립에 큰 도움을 줍니다! 😊


    1️⃣ 플레이어 활동 분석 시스템 구현 📋

    플레이어의 행동(예: 이동 거리, 플레이 시간 등)을 분석하는 시스템을 구현해보겠습니다.

    1. 플레이어 활동 분석 스크립트 작성

    1. ServerScriptService에 "Insert Object" -> Script를 추가합니다.
    2. 다음 코드를 입력합니다:
    local Players = game:GetService("Players")
    local activityLog = {}
    
    Players.PlayerAdded:Connect(function(player)
        local startTime = os.time()
        local character = player.Character or player.CharacterAdded:Wait()
        local initialPosition = character.HumanoidRootPart.Position
    
        player.AncestryChanged:Connect(function()
            local endTime = os.time()
            local playTime = endTime - startTime
            local finalPosition = character.HumanoidRootPart.Position
            local distanceMoved = (finalPosition - initialPosition).magnitude
            
            activityLog[player.Name] = {
                playTime = playTime,
                distanceMoved = distanceMoved
            }
            
            print(player.Name .. "님의 활동 분석 결과:")
            print("플레이 시간: " .. playTime .. "초")
            print("이동 거리: " .. distanceMoved .. " 스터즈")
        end)
    end)
    

    코드 설명

    • os.time(): 현재 시간을 초 단위로 반환합니다.
    • magnitude: 플레이어의 이동 거리를 계산합니다.
    • playTime: 플레이어의 총 플레이 시간을 분석합니다.

    2️⃣ 접속 시간 통계 시스템 구현 ⏱️

    플레이어들의 접속 시간과 활동 시간을 분석하는 시스템을 구현해보겠습니다.

    1. 접속 시간 통계 스크립트 작성

    1. ServerScriptService에 "Insert Object" -> Script를 추가합니다.
    2. 다음 코드를 입력합니다:
    local Players = game:GetService("Players")
    local connectionTimes = {}
    
    Players.PlayerAdded:Connect(function(player)
        local connectTime = os.time()
        connectionTimes[player.UserId] = connectTime
        print(player.Name .. "님이 접속했습니다.")
    end)
    
    Players.PlayerRemoving:Connect(function(player)
        local disconnectTime = os.time()
        local sessionDuration = disconnectTime - connectionTimes[player.UserId]
        print(player.Name .. "님의 접속 시간: " .. sessionDuration .. "초")
        connectionTimes[player.UserId] = nil
    end)
    

    코드 설명

    • PlayerAdded: 플레이어가 접속할 때 시간을 기록합니다.
    • PlayerRemoving: 플레이어가 게임에서 나가면 접속 시간을 계산합니다.
    • os.time(): 현재 시간을 초 단위로 반환합니다.

    3️⃣ 점수 및 승률 통계 시스템 구현 🏆

    플레이어의 점수와 승률을 기록하고 분석하는 시스템을 구현해보겠습니다.

    1. 점수 및 승률 통계 스크립트 작성

    1. ServerScriptService에 "Insert Object" -> Script를 추가합니다.
    2. 다음 코드를 입력합니다:
    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.Parent = leaderstats
        
        local wins = Instance.new("IntValue")
        wins.Name = "Wins"
        wins.Parent = leaderstats
    end)
    
    game.Players.PlayerRemoving:Connect(function(player)
        local score = player:FindFirstChild("leaderstats"):FindFirstChild("Score")
        local wins = player:FindFirstChild("leaderstats"):FindFirstChild("Wins")
        
        if score and wins then
            local winRate = (wins.Value / math.max(score.Value, 1)) * 100
            print(player.Name .. "님의 승률: " .. winRate .. "%")
        end
    end)
    

    코드 설명

    • leaderstats: 플레이어의 점수와 승리 횟수를 저장합니다.
    • math.max(): 0으로 나누는 오류를 방지합니다.
    • 승률 계산: 플레이어의 승률을 출력합니다.

    4️⃣ 인기 콘텐츠 분석 시스템 구현 📊

    플레이어들이 가장 많이 참여한 콘텐츠를 분석하는 시스템을 구현해보겠습니다.

    1. 인기 콘텐츠 분석 스크립트 작성

    1. ServerScriptService에 "Insert Object" -> Script를 추가합니다.
    2. 다음 코드를 입력합니다:
    local popularContent = {}
    
    game.Players.PlayerAdded:Connect(function(player)
        player.Chatted:Connect(function(message)
            if message:sub(1, 6) == "!참여 " then
                local content = message:sub(7)
                popularContent[content] = (popularContent[content] or 0) + 1
                print(content .. " 콘텐츠의 참여자 수: " .. popularContent[content])
            end
        end)
    end)
    

    코드 설명

    • Chatted 이벤트: 플레이어가 "!참여 [콘텐츠명]"을 입력하면 참여를 기록합니다.
    • sub(): 메시지를 분석해 콘텐츠명을 추출합니다.
    • 참여자 수 기록: 콘텐츠의 참여 횟수를 기록하고 출력합니다.

    5️⃣ 실시간 통계 대시보드 시스템 구현 📈

    게임 내 주요 통계를 실시간으로 확인할 수 있는 통계 대시보드 시스템을 구현해보겠습니다.

    1. 통계 대시보드 UI 추가

    1. StarterGui에 "Insert Object" -> ScreenGui를 추가합니다.
    2. ScreenGui 안에 TextLabel을 추가하고 이름을 **"StatsDashboard"**로 설정합니다.

    2. 실시간 통계 대시보드 스크립트 작성

    1. StatsDashboard에 "Insert Object" -> LocalScript를 추가합니다.
    2. 다음 코드를 입력합니다:
    local statsDashboard = script.Parent
    
    while wait(5) do
        local totalPlayers = #game.Players:GetPlayers()
        statsDashboard.Text = "현재 접속자 수: " .. totalPlayers
        print("실시간 접속자 수: " .. totalPlayers)
    end
    

    코드 설명

    • game.Players:GetPlayers(): 현재 접속 중인 플레이어 목록을 가져옵니다.
    • while 루프: 5초마다 실시간 통계를 갱신합니다.

    마무리 ✨

    이번 실습에서는 플레이어 활동 분석, 접속 시간 통계, 점수 및 승률 통계, 인기 콘텐츠 분석, 실시간 통계 대시보드와 같은 플레이어 분석과 게임 통계 시스템을 구현해 보았습니다. 이러한 기능들은 게임의 성과를 평가하고 개선 방향을 찾는 데 도움을 주며, 운영 전략 수립에도 유용하게 활용될 수 있습니다! 😊 다음에는 게임 운영 자동화 시스템과 AI 기반 게임 관리 기능을 소개해드리겠습니다! 🚀


     

    반응형
Designed by Tistory.