Peds
CLIENT SIDE ONLY
A standalone ped manager system for dynamically managing ped creation and behaviors. It allows for creating, customizing, and removing peds with optional animations, scenarios, and weapon configurations. This system operates independently of any framework.
Functions
create_ped
Creates a ped based on provided data.
Function
local function create_ped(data)
local base_data = data.base_data or {}
utils.requests.model(GetHashKey(base_data.model))
local ped = CreatePed(4, GetHashKey(base_data.model), base_data.coords.x, base_data.coords.y, base_data.coords.z - 1, base_data.coords.w, base_data.networked or false, true)
SetEntityInvincible(ped, true)
SetBlockingOfNonTemporaryEvents(ped, true)
FreezeEntityPosition(ped, true)
if data.animation_data then
utils.requests.anim(animation_data.dict)
TaskPlayAnim(ped, data.animation_data.dict, data.animation_data.anim, data.animation_data.blend_in or 8.0, data.animation_data.blend_out or -8.0, data.animation_data.duration or -1, data.animation_data.flag or 0, data.animation_data.playback_rate or 1.0, false, false, false)
elseif base_data.scenario then
TaskStartScenarioInPlace(ped, base_data.scenario, 0, true)
end
local weapon_data = data.weapon_data or {}
if weapon_data.weapon_name then
give_weapon(ped, weapon_data.weapon_name, weapon_data.ammo, weapon_data.equip_now, weapon_data.is_hidden, weapon_data.accuracy, weapon_data.invincible)
end
created_peds[#created_peds + 1] = { id = base_data.id, ped = ped, category = base_data.category }
return ped
end
exports('create_ped', create_ped)
utils.peds.create_ped = create_ped
Example
--- Define ped data
local ped_data = {
base_data = {
model = "a_m_m_business_01", -- Model of the ped
coords = vector3(-254.09, -971.48, 31.22), -- Coordinates where the ped will be spawned
scenario = "WORLD_HUMAN_AA_COFFEE", -- Scenario the ped will be using (optional)
networked = false -- Whether the ped is networked or not
},
animation_data = { -- Optional
dict = "amb@world_human_aa_coffee@base", -- Animation dictionary
anim = "base", -- Animation name
blend_in = 8.0, -- Blend in speed
blend_out = -8.0, -- Blend out speed
duration = -1, -- Duration of the animation
flag = 49, -- Animation flag
playback_rate = 1.0 -- Playback rate of the animation
},
weapon_data = { -- Optional
weapon_name = "WEAPON_PISTOL", -- Weapon to give to the ped
ammo = 100, -- Amount of ammo
equip_now = true, -- Equip the weapon immediately
is_hidden = false, -- Weapon is hidden or not
accuracy = 100.0, -- Accuracy of the ped with the weapon
invincible = true -- Ped is invincible or not
}
}
--- Utils object
local your_ped = utils.peds.create_ped(ped_data)
--- Direct export
local your_ped = exports.boii_utils:create_ped(ped_data)
create_peds
Creates multiple peds from a table of ped data.
Function
local function create_peds(ped_config)
for _, ped_data in ipairs(ped_config) do
create_ped(ped_data)
end
end
exports('create_peds', create_peds)
utils.peds.create_peds = create_peds
Example
--- Define peds
local peds = {
{
base_data = {
model = "a_f_y_hipster_01",
coords = vector4(-250.00, -970.00, 31.22, 0.0),
scenario = "WORLD_HUMAN_SMOKING",
networked = false
}
},
{
base_data = {
model = "a_m_m_beach_01",
coords = vector4(-260.00, -975.00, 31.22, 0.0),
scenario = "WORLD_HUMAN_MUSCLE_FLEX",
networked = false
},
weapon_data = {
weapon_name = "WEAPON_BAT",
equip_now = true
}
}
}
--- Utils object
utils.peds.create_peds(peds)
--- Direct export
exports.boii_utils:create_peds(peds)
remove_ped
Removes a single ped.
Function
local function remove_ped(ped)
DeleteEntity(ped)
for i = #created_peds, 1, -1 do
if created_peds[i].ped == ped then
table.remove(created_peds, i)
break
end
end
end
exports('remove_ped', remove_ped)
utils.peds.remove_ped = remove_ped
Example
--- Specify ped to remove
local ped_to_remove = ped
--- Utils object
utils.peds.remove_ped(ped_to_remove)
--- Direct export
exports.boii_utils:remove_ped(ped_to_remove)
remove_all_peds
Removes all created peds.
Function
local function remove_all_peds()
for _, ped_data in ipairs(created_peds) do
remove_ped(ped_data.ped)
end
created_peds = {}
end
exports('remove_all_peds', remove_all_peds)
utils.peds.remove_all_peds = remove_all_peds
Example
--- Utils object
utils.peds.remove_all_peds()
--- Direct export
exports.boii_utils:remove_all_peds()
remove_peds_by_categories
Removes peds by specified categories. Useful for resource clean up.
Function
local function remove_peds_by_categories(categories)
print("Starting ped removal for categories:", table.concat(categories, ", "))
local count = #created_peds
local removed = 0
for i = #created_peds, 1, -1 do
local ped_data = created_peds[i]
for _, category in ipairs(categories) do
if ped_data.category == category then
remove_ped(ped_data.ped)
removed = removed + 1
break
end
end
end
end
exports('remove_peds_by_categories', remove_peds_by_categories)
utils.peds.remove_peds_by_categories = remove_peds_by_categories
Example
--- Specify categories
local categories_to_remove = { 'garage_peds', 'hospital_peds' }
--- Utils object
utils.peds.remove_peds_by_categories(categories_to_remove)
--- Direct export
exports.boii_utils:remove_peds_by_categories(categories_to_remove)
Last updated