Peds Menu

GTA V Ped Selector Script

Overview

This GTA V script allows players to change their character’s gender and select from a list of predefined player models (peds). The script includes a user-friendly menu system and customization options.

Features

  • Gender Selection: Players can choose between male and female characters.
  • Ped Selection: Access a list of allowed peds based on the player’s identifier.
  • Walking Style Customization: The script automatically adjusts the player’s walking style based on the chosen gender.

Key Bindings

  • Press M to open the ped selector menu.

Installation

  1. Ensure you have the necessary dependencies installed, including ESX.
  2. Copy the script files to your server resources.
  3. Add the script to your server.cfg file.

Configuration

The script offers customization through the allowedPeds table in the script file. This table defines the allowed peds for each player.

Table containing allowed peds for each player
local allowedPeds = {
[“char1:iddemo”] = {“nameped_1”, “nameped_2”, “nameped_3”}, – User 1
[“char1:iddemo”] = {“nameped_1”} – User 2
}

List of allowed player identifiers access pedsmenu
local allowedIdentifiers = {
“char1:iddemo”, – User 1
“char1:iddemo” – User 2
}

Download

github.com/MobScript/mob_pedsmenu

Code is accessible Yes/No
Lines (approximately) 177
1 Like

Hey man! nice work!, love it!, can you make it for qbcore?

1 Like

I have never tried doing qbcore but I could try it

I’m not sure if it’s like that in qbcore but you could try @Knox-S
I don’t have enough experience in qbcore, if it works for you let me know
I plan to make a more interactive menu with a customizable design

-- Key bindings
local Keys = {
    ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
    ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
    ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
    ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
    ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
    ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
    ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
    ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
}

-- Framework detection
local ESX, QBCore
local frameworkDetected = nil

-- Table containing allowed peds for each player
local allowedPeds = {
    -- Add comments explaining the structure of the allowedPeds table
    ["char1:iddemo"] = {"nameped_1", "nameped_2", "nameped_3"},  -- User 1
    ["char1:iddemo"] = {"nameped_1"}  -- User 2
}

-- Detect ESX or QBCore
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(100)

        if ESX == nil then
            if IsESXLoaded() then
                frameworkDetected = "esx"
                ESX = exports['es_extended']:getSharedObject()
            elseif IsQBCoreLoaded() then
                frameworkDetected = "qbcore"
                QBCore = exports['qb-core']:getCoreObject()
            end
        end
    end
end)

-- Function to check if ESX is loaded
function IsESXLoaded()
    return exports['es_extended'] ~= nil
end

-- Function to check if QBCore is loaded
function IsQBCoreLoaded()
    return exports['qb-core'] ~= nil
end

-- Event to open the ped menu
RegisterNetEvent("mob_pedsmenu:pedmeny")
AddEventHandler("mob_pedsmenu:pedmeny", function()
    -- Call the function to open the gender selection menu
    OpenGenderMenu()
end)

-- Function to open the gender selection menu
function OpenGenderMenu()
    -- Get the current player's identifier
    local currentPlayerIdentifier = GetPlayerIdentifier()

    -- Check if the player has a list of allowed peds
    local playerAllowedPeds = allowedPeds[currentPlayerIdentifier]

    if playerAllowedPeds then
        -- Create elements for the gender selection menu
        local menuElements = {
            {
                ["label"] = "My Peds",
                ["action"] = "choose_gender",
                ["value"] = nil
            },
            {
                ["label"] = "Male Peds",
                ["action"] = "choose_gender",
                ["value"] = "male"
            },
            {
                ["label"] = "Female Peds",
                ["action"] = "choose_gender",
                ["value"] = "female"
            }
        }

        -- Open the default menu with gender options based on the detected framework
        if frameworkDetected == "esx" then
            ESX.UI.Menu.Open("default", GetCurrentResourceName(), "gender_menu", {
                ["title"] = "Gender",
                ["align"] = "center",
                ["elements"] = menuElements
            }, function(menuData, menuHandle)
                local action = menuData["current"]["action"]

                if action == "choose_gender" then
                    local chosenGender = menuData["current"]["value"]

                    if chosenGender then
                        -- Call the function to open the ped selection menu
                        OpenPedMenu(chosenGender, playerAllowedPeds)
                    end
                end
            end, function(menuData, menuHandle)
                menuHandle.close()
            end)
        elseif frameworkDetected == "qbcore" then
            QBCore.UI.Menu.Open("default", GetCurrentResourceName(), "gender_menu", {
                title = "Gender",
                align = "center",
                elements = menuElements
            }, function(menuData, menuHandle)
                local action = menuData.current.action

                if action == "choose_gender" then
                    local chosenGender = menuData.current.value

                    if chosenGender then
                        -- Call the function to open the ped selection menu
                        OpenPedMenu(chosenGender, playerAllowedPeds)
                    end
                end
            end, function(menuData, menuHandle)
                menuHandle.close()
            end)
        else
            -- Open standalone menu
            OpenStandaloneMenu(menuElements)
        end
    else
        -- Display a notification if the player has no allowed peds
        SendNotification('You don\'t have allowed peds.', "error")
    end
end

-- Function to open the ped selection menu
function OpenPedMenu(gender, allowedPedList)
    -- Create elements for the ped selection menu
    local menuElements = {
        {
            ["label"] = "Choose a ped to become",
            ["action"] = "choose_ped"
        }
    }

    -- Add each allowed ped to the menu elements
    for _, pedModel in ipairs(allowedPedList) do
        table.insert(menuElements, {
            ["label"] = pedModel,
            ["action"] = "choose_ped",
            ["value"] = pedModel
        })
    end

    -- Open the default menu with ped options based on the detected framework
    if frameworkDetected == "esx" then
        ESX.UI.Menu.Open("default", GetCurrentResourceName(), "ped_menu", {
            ["title"] = "Peds",
            ["align"] = "center",
            ["elements"] = menuElements
        }, function(menuData, menuHandle)
            local action = menuData["current"]["action"]

            if action == "choose_ped" then
                local pedModelChosen = menuData["current"]["value"]

                if IsModelInCdimage(pedModelChosen) then
                    while not HasModelLoaded(pedModelChosen) do
                        Citizen.Wait(5)
                        RequestModel(pedModelChosen)
                    end

                    -- Set the player model to the chosen ped
                    SetPlayerModel(PlayerId(), pedModelChosen)

                    -- Determine the player's gender
                    local isMale = gender == "male"

                    -- Change the walking style based on gender
                    if isMale then
                        SetPedMovementClipset(PlayerPedId(), "move_m@generic", 1.0)
                    else
                        SetPedMovementClipset(PlayerPedId(), "move_f@generic", 1.0)
                    end

                    menuHandle.close()
                else
                    -- Display a notification for an invalid ped
                    SendNotification('Invalid PED', "error")
                end
            end
        end, function(menuData, menuHandle)
            menuHandle.close()
        end)
    elseif frameworkDetected == "qbcore" then
        QBCore.UI.Menu.Open("default", GetCurrentResourceName(), "ped_menu", {
            ["title"] = "Peds",
            ["align"] = "center",
            ["elements"] = menuElements
        }, function(menuData, menuHandle)
            local action = menuData.current.action

            if action == "choose_ped" then
                local pedModelChosen = menuData.current.value

                if IsModelInCdimage(pedModelChosen) then
                    while not HasModelLoaded(pedModelChosen) do
                        Citizen.Wait(5)
                        RequestModel(pedModelChosen)
                    end

                    -- Set the player model to the chosen ped
                    SetPlayerModel(PlayerId(), pedModelChosen)

                    -- Determine the player's gender
                    local isMale = gender == "male"

                    -- Change the walking style based on gender
                    if isMale then
                        SetPedMovementClipset(PlayerPedId(), "move_m@generic", 1.0)
                    else
                        SetPedMovementClipset(PlayerPedId(), "move_f@generic", 1.0)
                    end

                    menuHandle.close()
                else
                    -- Display a notification for an invalid ped
                    SendNotification('Invalid PED', "error")
                end
            end
        end, function(menuData, menuHandle)
            menuHandle.close()
        end)
    else
        -- Open standalone menu
        OpenStandaloneMenu(menuElements)
    end
end

-- Function to check if the model is valid
function IsModelInCdimage(model)
    return IsModelInCdimage(GetHashKey(model))
end

-- Function to send notifications
function SendNotification(text, type)
    exports.pNotify:SendNotification({text = text, type = type, timeout = 200, layout = "bottomCenter", queue = "center"})
end

-- Function to open the standalone menu
function OpenStandaloneMenu(menuElements)
    -- Implement the standalone menu opening logic here
    -- ...
end

-- Function to get the player identifier
function GetPlayerIdentifier()
    if frameworkDetected == "esx" then
        return ESX.GetPlayerData().identifier
    elseif frameworkDetected == "qbcore" then
        local player = QBCore.Functions.GetPlayerData()
        return player.identifier
    else
        -- Implement standalone logic to get player identifier
        -- ...
    end
end

-- List of allowed player identifiers
local allowedIdentifiers = {
    "char1:iddemo",  -- User 1
    "char1:iddemo"   -- User 2
}

-- Main thread to check for key press and open the ped menu
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1)

        local currentPlayerIdentifier = GetPlayerIdentifier()

        if IsControlJustReleased(0, Keys['M']) then
            for _, allowedIdentifier in ipairs(allowedIdentifiers) do
                if currentPlayerIdentifier == allowedIdentifier then
                    Wait(500)
                    -- Trigger the event to open the ped menu
                    TriggerEvent("mob_pedsmenu:pedmeny")
                    break
                end
            end
        end
    end
end)


Nice ChatGPT code :cold_face:

1 Like

yep hahahahaha :rofl: :rofl:

clearly didnt read the release guidelines lol.

this code is literally terrible and has practices from 2018, the FiveM script data that ChatGPT trained on

As long as it works for me I have no problem xd hahaha :grin:

If anyone wants to update it, it is totally free of charge since it is on GitHub for free use.

if that code works for you, your on super old versions of resources, with big security vulnerabilities and terrible performance anyway.

So, if you like, you are free to update it ^^

this code is what I see in my nightmares.

Here is better written version I just made. It will work on all frameworks as long as you use ox_lib.

@Bikuta-san You can use my version and just change the menu with ESX MENU. its much safer and optimized.

pedmenu.rar (1.4 KB)

Client Side :

RegisterNetEvent('bbv-peds',function()
    exports['ox_lib']:registerContext({
        id = 'ped_menu',
        title = 'Ped Selector',
        menu = 'peds',
        options = {
          {
            title = 'Ped Selector: ',
            icon = 'hand',
            disabled = true
          },
          {
            title = 'Male ped: ',
            description = 'switch to male ped',
            event = 'bbv-switchped',
            args = {
              ped = 'a_m_m_farmer_01'
            }
          },
          {
            title = 'Female ped: ',
            description = 'switch to female ped',
            event = 'bbv-switchped',
            args = {
              ped = 'a_f_m_beach_01'
            }
          },
        --   {
        --     title = 'Example ped: ',
        --     description = 'switch to Example ped',
        --     event = 'bbv-switchped',
        --     args = {
        --       ped = 'Example'
        --     }
        --   },
        }
      })
     
    exports['ox_lib']:showContext('ped_menu')
end)

RegisterNetEvent('bbv-switchped',function(data)
    local player = PlayerId()
    local model = GetHashKey(data.ped)

    RequestModel(model)
    while not HasModelLoaded(model) do
        Wait(100)
    end

    if not IsModelInCdimage(model) then return end
    SetPlayerModel(player, model)
    SetModelAsNoLongerNeeded(model)
end)

Server Side :

RegisterCommand('pedmenu', function(source)
    local src = source
    local myid = Identifiers(src)
    for k,v in pairs(Config.Allowed) do 
        if v == myid.discord or Config.Permissions == false then 
            TriggerClientEvent('bbv-peds', src)
            return
        end
    end
end)

function Identifiers(src)
    local identifiers = {
        steam = "",
        ip = "",
        discord = "",
        license = "",
        xbl = "",
        live = ""
    }

    for i = 0, GetNumPlayerIdentifiers(src) - 1 do
        local id = GetPlayerIdentifier(src, i)

        if string.find(id, "steam") then
            identifiers.steam = id
        elseif string.find(id, "ip") then
            identifiers.ip = id
        elseif string.find(id, "discord") then
            identifiers.discord = id
        elseif string.find(id, "license") then
            identifiers.license = id
        elseif string.find(id, "xbl") then
            identifiers.xbl = id
        elseif string.find(id, "live") then
            identifiers.live = id
        end
    end

    return identifiers
end

config & manifest are in the rar file.

1 Like

good job^^