Snippet - /bed Command


#1

A person on the FiveM Discord asked for a /bed command, probably due to the influx of popular Twitch streamers lately using this command.

Good for hospital :rp:

Here’s a snippet of my version of the /bed command. I believe it’s not complicated enough for the #development:releases category, so I’ll put it here.

Video: https://streamable.com/eaosk
Screenshot: https://i.d0p3t.nl/u/0ihxvZ5V3y.png
Download: bedcommand.zip (1.2 KB)

Snippet:

bedNames = { 'v_med_bed1', 'v_med_bed2'} -- Add more model strings here if you'd like
bedHashes = {}
animDict = 'missfbi5ig_0'
animName = 'lyinginpain_loop_steve'
isOnBed = false

CreateThread(function()
    for k,v in ipairs(bedNames) do
        table.insert( bedHashes, GetHashKey(v))
    end
end)

RegisterCommand('bed', function()
    Citizen.CreateThread(function()
        local playerPed = PlayerPedId()
        if isOnBed then
            ClearPedTasksImmediately(playerPed)
            isOnBed = false
            return
        end

        local playerPos = GetEntityCoords(playerPed, true)

        local bed = nil

        for k,v in ipairs(bedHashes) do
            bed = GetClosestObjectOfType(playerPos.x, playerPos.y, playerPos.z, 4.0, v, false, false, false)
            if bed ~= 0 then
                break
            end
        end

        if bed ~= nil and DoesEntityExist(bed) then
            if not HasAnimDictLoaded(animDict) then
                RequestAnimDict(animDict)
            end
            local bedCoords = GetEntityCoords(bed)

            SetEntityCoords(playerPed, bedCoords.x , bedCoords.y, bedCoords.z, 1, 1, 0, 0)
            SetEntityHeading(playerPed, GetEntityHeading(bed) + 180.0)
            TaskPlayAnim(playerPed,animDict, animName, 8.0, 1.0, -1, 45, 1.0, 0, 0, 0)

            isOnBed = true
        end
    end)
end, false)

The models I used for this are from [Release] Hospital props

On the second bed the player does hover due to collision. Up to you to fix this if you want to, I just put this together real quick.


#2

vRP & ESX versions coming?

gud release… 6 starts
:star::star::star::star::star::star:


#3

Strong Release! I would give you six out of five stars if it was already in C# but most plebs use lua sadly so it still dominates. I love little improvements like this given they make such a large impact to an RP scene.

EDIT; I would mention people only need to use this as a client resource in the __resource.lua file.


#4

I would if it were to be something more elaborate :slight_smile:

For those that can’t figure this out, I’ve included a 1.2KB ready-to-go resource :stuck_out_tongue_winking_eye:


#5

@d0p3t Is there a way for us to do /bed ID TIME and people stay on the bed for that ammount of time ?