搜索
开启左侧

我的桌子模型显示不出来,可以帮我看看什么问题么

[复制链接]
ketk0429 发表于 2025-2-20 06:54:45 | 显示全部楼层 |阅读模式

-- client.lua

local playerCards = {}
local isGameStarted = false
local currentPlayer = nil
local landlord = nil

-- 显示手牌
local function showCards()
    SendNUIMessage({
        type = "updateHandCards",
        cards = playerCards
    })
end

-- 更新游戏状态
local function updateGameStatus(status)
    SendNUIMessage({
        type = "updateGameStatus",
        status = status
    })
end

-- 更新当前出牌玩家
local function updateCurrentPlayer(player)
    SendNUIMessage({
        type = "updateCurrentPlayer",
        player = player
    })
end

-- 更新上家出的牌
local function updateLastPlayedCards(cards)
    SendNUIMessage({
        type = "updateLastPlayedCards",
        cards = cards
    })
end

-- 游戏开始
RegisterNetEvent("doudizhu:startGameClient")
AddEventHandler("doudizhu:startGameClient", function(cards)
    playerCards = cards
    isGameStarted = true
    showCards()
    updateGameStatus("游戏进行中...")
end)

-- 设置地主
RegisterNetEvent("doudizhu:setLandlord")
AddEventHandler("doudizhu:setLandlord", function(landlordId)
    landlord = landlordId
    if landlordId == GetPlayerServerId(PlayerId()) then
        updateGameStatus("你是地主!")
    else
        updateGameStatus("玩家 " .. landlordId .. " 是地主。")
    end
end)

-- 设置当前出牌玩家
RegisterNetEvent("doudizhu:setCurrentPlayer")
AddEventHandler("doudizhu:setCurrentPlayer", function(playerId)
    currentPlayer = playerId
    if playerId == GetPlayerServerId(PlayerId()) then
        updateCurrentPlayer("你")
    else
        updateCurrentPlayer("玩家 " .. playerId)
    end
end)

-- 游戏结束
RegisterNetEvent("doudizhu:gameOver")
AddEventHandler("doudizhu:gameOver", function(winnerId)
    if winnerId == GetPlayerServerId(PlayerId()) then
        updateGameStatus("你赢了!")
    else
        updateGameStatus("玩家 " .. winnerId .. " 赢了!")
    end
    isGameStarted = false
end)

-- 处理出牌请求
RegisterNUICallback("playCards", function(data, cb)
    if isGameStarted and currentPlayer == GetPlayerServerId(PlayerId()) then
        TriggerServerEvent("doudizhu:playCards", data.cards)
    else
        print("It's not your turn!")
    end
    cb("ok")
end)

-- 处理超时
RegisterNUICallback("timeout", function(data, cb)
    if isGameStarted and currentPlayer == GetPlayerServerId(PlayerId()) then
        TriggerServerEvent("doudizhu:timeout")
    end
    cb("ok")
end)

-- 处理提示出牌
RegisterNUICallback("hintCards", function(data, cb)
    if isGameStarted and currentPlayer == GetPlayerServerId(PlayerId()) then
        TriggerServerEvent("doudizhu:hintCards")
    end
    cb("ok")
end)

local isSitting = false

-- 玩家坐下
local function sitAtTable()
    local playerPed = PlayerPedId()
    local tableCoords = vector3(0.0, 0.0, 70.0)  -- 桌子的坐标
    TaskStartScenarioAtPosition(playerPed, "PROP_HUMAN_SEAT_CHAIR_MP_PLAYER", tableCoords.x, tableCoords.y, tableCoords.z, 0.0, 0, true, true)
    isSitting = true
    SendNUIMessage({ type = "showUI" })  -- 显示 UI
end

-- 玩家离开
local function leaveTable()
    local playerPed = PlayerPedId()
    ClearPedTasks(playerPed)
    isSitting = false
    SendNUIMessage({ type = "hideUI" })  -- 隐藏 UI
end

-- 检测玩家是否靠近桌子
local function checkNearTable()
    local playerCoords = GetEntityCoords(PlayerPedId())
    local tableCoords = vector3(0.0, 0.0, 70.0)  -- 桌子的坐标
    if #(playerCoords - tableCoords) < 2.0 then
        return true
    end
    return false
end

-- 按 E 坐下或离开
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if checkNearTable() then
            if not isSitting then
                DrawText3D(tableCoords.x, tableCoords.y, tableCoords.z, "按 [E] 坐下")
                if IsControlJustReleased(0, 38) then  -- 38 是 E 键
                    sitAtTable()
                end
            else
                DrawText3D(tableCoords.x, tableCoords.y, tableCoords.z, "按 [E] 离开")
                if IsControlJustReleased(0, 38) then  -- 38 是 E 键
                    leaveTable()
                end
            end
        end
    end
end)

-- 显示 3D 文字
function DrawText3D(x, y, z, text)
    local onScreen, _x, _y = World3dToScreen2d(x, y, z)
    if onScreen then
        SetTextScale(0.35, 0.35)
        SetTextFont(4)
        SetTextProportional(1)
        SetTextColour(255, 255, 255, 215)
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
        DrawText(_x, _y)
    end
end

-- 游戏结束
RegisterNetEvent("doudizhu:gameOver")
AddEventHandler("doudizhu:gameOver", function(winnerId)
    if winnerId == GetPlayerServerId(PlayerId()) then
        print("你赢了!")
    else
        print("玩家 " .. winnerId .. " 赢了!")
    end
    isSitting = false
    SendNUIMessage({ type = "hideUI" })  -- 隐藏 UI
end)


回复 论坛版权

使用道具 举报

ChatGPT 发表于 2025-2-20 06:54:51 | 显示全部楼层
看起来你的代码中涉及到玩家坐下和桌子模型的显示。如果桌子模型没有显示出来,可能有以下几个原因:

1. **桌子模型未加载**:你需要确保桌子模型已经在游戏中正确加载。如果模型没有被加入到资源中,或者模型 ID 不正确,那么就无法显示。

2. **坐标问题**:你使用的桌子坐标是 `vector3(0.0, 0.0, 70.0)`。请确认这个坐标在游戏世界中是有效的,并且桌子的位置确实存在。可以使用一些调试方法,比如打印出坐标,看看玩家是否真的在那个位置。

3. **NUI 界面未激活**:确保 NUI 界面(即用户界面)是正常工作的,并且在合适的时机显示。例如,在玩家坐下时调用 `SendNUIMessage({ type = "showUI" })` 是对的,但如果某些条件不满足可能不会触发。

4. **检查事件的触发**:确认所有相关的事件是否在服务器与客户端之间正常通信,尤其是你在服务端触发事件后,客户端是否能够正确接收并处理这些事件。

5. **模型的透明度或层级问题**:确保桌子模型没有设置成透明状态,或者在层级上没有被其他物体遮挡。

如果以上都不能解决问题,可以尝试添加一些调试信息,例如在 `sitAtTable` 函数里,打印出是否成功进入该函数,或者在加载模型的地方添加日志,看是否执行到了那一步。

最后,请确保在 `client.lua` 中放置所有与客户端相关的代码,逻辑和事件都是放在客户端文件中的。
回复

使用道具 举报

文明发言,和谐互动
文明发言,和谐互动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|首页 ( 冀ICP备2021005225号-1 ) |网站地图

GMT+8, 2025-3-13 02:38 , Processed in 0.087587 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2013 ELITE论坛【技术无价-分享快乐】

快速回复 返回顶部 返回列表