搜索
开启左侧

[有效回答] 代码

[复制链接]
lizhuoda 发表于 昨天 10:59 | 显示全部楼层 |阅读模式
local xOffset = 2 --这个变量决定了玩家在离开座位后,玩家将传送到部件位置向左偏移多少后的位置(= 0将使玩家传送到部件位置)

--[[
注:
文中提到的部件皆指装载ProximityPrompt对象的这个部件。
玩家离开座位时将会传送到这个部件的坐标系(CFrame)的位置加上负xOffset后的位置。
请务必确保车辆座位的朝向与该部件的朝向一致,否则玩家传送后的位置与朝向会出现异常!
若发现玩家离开座位后被卡在车里,尝试将部件旋转180度,增大xOffset变量,并且确认部件是贴在车门上的!
]]
-------------------------------
local playersService = game:GetService("Players")
local marketPlaceService = game:GetService("MarketplaceService")
local userInputService = game:GetService("UserInputService")
local prompt = script.Parent
local part = prompt.Parent
local car = part.Parent.Parent
local gamePass = car:GetAttribute("gamePass")
local seat = car.DriveSeat
local currentOccupant

local playerFKeyStatus = {}

prompt.ActionText = "按F准备上车"
prompt.KeyboardKeyCode = Enum.KeyCode.F

local function onFKeyPressed(player)
        playerFKeyStatus[player] = true
        prompt.ActionText = "按E上车"
        prompt.KeyboardKeyCode = Enum.KeyCode.E
end

local function onFKeyReleased(player)
end

local function sit(player:Player)
        if not playerFKeyStatus[player] then
                onFKeyPressed(player)
                return
        end

        local canSit = false
        if (not gamePass or (gamePass and gamePass == 0)) then
                canSit = true
        else
                local isOwned = marketPlaceService:UserOwnsGamePassAsync(player.UserId,gamePass)
                if not isOwned and _G.playerGamePassPurchased[gamePass] and table.find(_G.playerGamePassPurchased[gamePass],player) then
                        isOwned = true
                end
                if isOwned then
                        canSit = true
                else
                        marketPlaceService:PromptGamePassPurchase(player,gamePass)
                end
        end

        if canSit then
                seat:Sit(player.Character.Humanoid)
                playerFKeyStatus[player] = false
                prompt.ActionText = "按F准备上车"
                prompt.KeyboardKeyCode = Enum.KeyCode.F
        end
end

local function onOccupantChanged()
        local humanoid:Humanoid = seat.Occupant
        if humanoid then
                local player = playersService:GetPlayerFromCharacter(humanoid.Parent)
                if gamePass and gamePass ~= 0 then
                        local isOwned = marketPlaceService:UserOwnsGamePassAsync(player.UserId,gamePass)
                        if not isOwned and _G.playerGamePassPurchased[gamePass] and table.find(_G.playerGamePassPurchased[gamePass],player) then
                                isOwned = true
                        end
                        if not isOwned then
                                humanoid.Jump = true
                                marketPlaceService:PromptGamePassPurchase(player,gamePass)
                        end
                end
                prompt.Enabled = false
                currentOccupant = humanoid
        else
                local character:Model = currentOccupant.Parent
                character:PivotTo(CFrame.new((part.CFrame * CFrame.new(-xOffset,0,0)).Position) * CFrame.Angles(seat.CFrame:ToEulerAnglesXYZ()))
                character.PrimaryPart.AssemblyLinearVelocity = Vector3.new(0,0,0)
                prompt.Enabled = true
                if currentOccupant then
                        local player = playersService:GetPlayerFromCharacter(currentOccupant.Parent)
                        if player then
                                playerFKeyStatus[player] = false
                                prompt.ActionText = "按F准备上车"
                                prompt.KeyboardKeyCode = Enum.KeyCode.F
                        end
                end
        end
end

prompt.Triggered:Connect(sit)
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)

playersService.PlayerRemoving:Connect(function(player)
        playerFKeyStatus[player] = nil
end)

回复 论坛版权

使用道具 举报

ChatGPT 发表于 昨天 11:00 | 显示全部楼层
此帖仅作者可见

使用道具 举报

 楼主| lizhuoda 发表于 昨天 11:11 | 显示全部楼层
此帖仅作者可见

使用道具 举报

ChatGPT 发表于 昨天 11:11 | 显示全部楼层
此帖仅作者可见

使用道具 举报

 楼主| lizhuoda 发表于 昨天 11:15 | 显示全部楼层
此帖仅作者可见

使用道具 举报

ChatGPT 发表于 昨天 11:16 | 显示全部楼层
此帖仅作者可见

使用道具 举报

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

本版积分规则

QQ|Archiver|手机版|小黑屋|FiveM技术教程分享 ( 冀ICP备2021005225号-1 ) |网站地图

GMT+8, 2025-6-28 05:51 , Processed in 0.126148 second(s), 8 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

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

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