Giter Site home page Giter Site logo

devyn-backitems's Introduction

devyn-backitems

FiveM Lua Script for displaying items on the players back. NOTE: I do not provide any support for this. Just posted because a lot of people asked for it.

image

If you want to add/remove/change model/backplacement it can be done in the BackItems.lua.

Spawn Setup

qb-spawn Setup

In qb-spawn in client.lua, edit the function PostSpawnPlayer and add TriggerEvent("backitems:start") to the last line.

    local function PostSpawnPlayer(ped)
    FreezeEntityPosition(ped, false)
    RenderScriptCams(false, true, 500, true, true)
    SetCamActive(cam, false)
    DestroyCam(cam, true)
    SetCamActive(cam2, false)
    DestroyCam(cam2, true)
    SetEntityVisible(PlayerPedId(), true)
    Wait(500)
    DoScreenFadeIn(250)
    TriggerEvent("backitems:start")
    end

cd_spawnselect Setup

If you use cd_spawnselect you need to edit the function "HasFullySpanwedIn" in the client_customize_me.lua and add TriggerEvent("backitems:start")

image

Clothing Setup

qb-clothing Setup

If you use qb-clothing you need to add the follow event to the openMenu function.

TriggerEvent("backitems:displayItems", false)

It should now look like this.

   function openMenu(allowedMenus)
    TriggerEvent("backitems:displayItems", false)
    previousSkinData = json.encode(skinData)
    creatingCharacter = true

    local PlayerData = QBCore.Functions.GetPlayerData()
    local trackerMeta = PlayerData.metadata["tracker"]

    GetMaxValues()
    SendNUIMessage({
        action = "open",
        menus = allowedMenus,
        currentClothing = skinData,
        hasTracker = trackerMeta,
    })
    SetNuiFocus(true, true)
    SetCursorLocation(0.9, 0.25)

    FreezeEntityPosition(PlayerPedId(), true)

    enableCam()
end

Also add TriggerEvent("backitems:displayItems", true) to the close NUI callback

RegisterNUICallback('close', function()
    SetNuiFocus(false, false)
    creatingCharacter = false
    disableCam()
    TriggerEvent("backitems:displayItems", true)
    FreezeEntityPosition(PlayerPedId(), false)
end)

fivem-appearance Setup

If you use fivem-appearance you need to add the triggers whenever you call the startPlayerCustomization export

	TriggerEvent("backitems:displayItems", false)
	exports['fivem-appearance']:startPlayerCustomization(function (appearance)
		if appearance then
			TriggerServerEvent('fivem-appearance:save', appearance)
			print('Player Clothing Saved')
		else
			print('Canceled')
		end
		TriggerEvent("backitems:displayItems", true)
	end, config)

Show Again Client Event

fivem-appearance Setup

If you are using fivem-appearance, you must add the triggers when you call the LoadPlayerUniform() export

local function LoadPlayerUniform()
    QBCore.Functions.TriggerCallback("fivem-appearance:server:getUniform", function(uniformData)
        if not uniformData then
            return
        end
        if Config.BossManagedOutfits then
            QBCore.Functions.TriggerCallback("fivem-appearance:server:getManagementOutfits", function(result)
                local uniform = nil
                for i = 1, #result, 1 do
                    if result[i].name == uniformData.name then
                        uniform = {
                            type = uniformData.type,
                            name = result[i].name,
                            model = result[i].model,
                            components = result[i].components,
                            props = result[i].props,
                            disableSave = true,
                        }
                        break
                    end
                end

                if not uniform then
                    TriggerServerEvent("fivem-appearance:server:syncUniform", nil) -- Uniform doesn't exist anymore
                    return
                end
    
                TriggerEvent("fivem-appearance:client:changeOutfit", uniform)
            end, uniformData.type, getGender())
        else
            local outfits = Config.Outfits[uniformData.jobName][uniformData.gender]
            local uniform = nil
            for i = 1, #outfits, 1 do
                if outfits[i].name == uniformData.label then
                    uniform = outfits[i]
                    break
                end
            end

            if not uniform then
                TriggerServerEvent("fivem-appearance:server:syncUniform", nil) -- Uniform doesn't exist anymore
                return
            end

            uniform.jobName = uniformData.jobName
            uniform.gender = uniformData.gender

            TriggerEvent("qb-clothing:client:loadOutfit", uniform)
            TriggerEvent("backitems:showagain")
        end
    end)
end

You must also add the trigger to the reloadSkin Client Event:

RegisterNetEvent('fivem-appearance:client:reloadSkin', function()
    if InCooldown() or CheckPlayerMeta() then
        QBCore.Functions.Notify("You cannot use reloadskin right now", "error")
        return
    end

    reloadSkinTimer = GetGameTimer()
    local playerPed = PlayerPedId()
    local health = GetEntityHealth(playerPed)
    local maxhealth = GetEntityMaxHealth(playerPed)
    local armour = GetPedArmour(playerPed)

    QBCore.Functions.TriggerCallback('fivem-appearance:server:getAppearance', function(appearance)
        if not appearance then
            return
        end
        exports[resourceName]:setPlayerAppearance(appearance)
        TriggerEvent("backitems:showagain")
        if Config.PersistUniforms then
            TriggerServerEvent("fivem-appearance:server:syncUniform", nil)
        end
        playerPed = PlayerPedId()
        SetPedMaxHealth(playerPed, maxhealth)
        Wait(1000) -- Safety Delay
        SetEntityHealth(playerPed, health)
        SetPedArmour(playerPed, armour)
        ResetRechargeMultipliers()
    end)
end)

qb-apartment Fix / Setup

Add the event to your EnterApartment and LeaveApartment functions after TriggerServerEvent("QBCore:Server:SetMetaData", "currentapartment", nil)

Something like this:

  • EnterApartment (Twice)
            TriggerServerEvent("QBCore:Server:SetMetaData", "currentapartment", CurrentApartment)
            TriggerEvent("backitems:showagain")
        end
  • LeaveApartment
        TriggerServerEvent("QBCore:Server:SetMetaData", "currentapartment", nil)
        TriggerEvent("backitems:showagain")
    end)

devyn-backitems's People

Contributors

arssanto avatar darktrovx avatar dexter9006 avatar noobysloth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.