Streaming del Ped
INFO
Dopo aver creato il modello e il meta, devi far apparire il ped in gioco. Questo avviene tramite script Lua.
| Obiettivo | Dettagli |
|---|---|
| Cosa imparerai | • Scrivere script Lua per spawnare il ped • Usare i nativi CreatePed e SetPlayerModel • Diagnosticare errori di streaming comuni |
| Prerequisiti | • YFT, YTD e YMT del ped pronti • Conoscenza base Lua per FiveM • Server FiveM per test |
Risorsa Completa
custom_ped/
├── fxmanifest.lua
├── client.lua
└── stream/
├── u_m_m_custom_npc.yft ← Modello
├── u_m_m_custom_npc.ytd ← Texture
└── u_m_m_custom_npc.ymt ← Meta Ped
fxmanifest
-- fxmanifest.lua
fx_version 'cerulean'
game 'gta5'
author 'TuoNome'
description 'Ped Custom - NPC Custom'
version '1.0.0'
data_file 'PED_METADATA_FILE' 'stream/*.ymt'
client_script 'client.lua'Client Lua — Spawn del Ped
-- client.lua
local pedHash = GetHashKey('u_m_m_custom_npc')
local isLoaded = false
-- Thread di caricamento
Citizen.CreateThread(function()
-- Richiedi il modello al gioco
RequestModel(pedHash)
-- Aspetta che sia caricato
local attempts = 0
while not HasModelLoaded(pedHash) and attempts < 100 do
Citizen.Wait(100)
attempts = attempts + 1
end
if HasModelLoaded(pedHash) then
isLoaded = true
print('^2[PED] Modello caricato con successo')
else
print('^1[PED] ERRORE: Modello non caricato dopo 10 secondi')
end
end)
-- Comando per spawnare il ped
RegisterCommand('spawnped', function()
if not isLoaded then
print('^1[PED] Modello non ancora caricato')
return
end
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local heading = GetEntityHeading(playerPed)
-- Crea il ped
local spawnedPed = CreatePed(
0, -- Ped type: 0=civile
pedHash, -- Hash del modello
playerCoords.x + 2.0,
playerCoords.y + 2.0,
playerCoords.z,
heading + 180, -- Di fronte al giocatore
true, -- Register as network
false -- Script managed
)
-- Imposta caratteristiche
SetEntityInvincible(spawnedPed, false)
SetPedCanRagdoll(spawnedPed, true)
TaskStandStill(spawnedPed, -1) -- Fermo
end, false)
-- Comando per spawnare come giocatore (cambia il tuo ped)
RegisterCommand('myped', function()
if not isLoaded then
print('^1[PED] Modello non ancora caricato')
return
end
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
-- Cambia il modello del giocatore
SetPlayerModel(PlayerId(), pedHash)
SetModelAsNoLongerNeeded(pedHash)
print('^2[PED] Modello giocatore cambiato!')
end, false)TIP
Usa
CreatePedper NPC eSetPlayerModelper trasformare il giocatore nel ped.
Tipi di Spawn
| Metodo | Descrizione | Nativo |
|---|---|---|
CreatePed | Crea un NPC nel mondo | CreatePed(type, hash, x, y, z, heading, network, script) |
SetPlayerModel | Cambia il modello del giocatore | SetPlayerModel(player, hash) |
ClonePedToTarget | Copia ped su altro ped | (avanzato) |
Parametri CreatePed
| Parametro | Valori | Descrizione |
|---|---|---|
type | 0=Civile, 1=Polizia, 4=Gangster, 6=Animale | Tipo di ped |
hash | Hash del modello | Nome dell’YFT |
heading | 0-360 | Rotazione iniziale |
network | true/false | Se è visibile in rete |
Verifica Streaming
Console Comandi
# In console F8
/ spawnped
# O dalla console server
status
Errori Comuni
WARNING
La maggior parte degli errori di streaming deriva da nomi non corrispondenti tra YFT, YMT e fxmanifest.
| Errore | Causa | Soluzione |
|---|---|---|
| ”Model does not exist” | Nome errato o YFT non caricato | Controlla fxmanifest e nome nello YMT |
| Ped invisibile | YTD mancante o texture non trovata | Controlla che il .ytd esista |
| Ped T-pose | Rigging mancante | Verifica weight painting |
| Crash allo spawn | YMT malformato | Valid XML check |
| Nessuna texture | YTD non collegata allo YFT | Controlla Export Options |
TIP
Prossimo passo: 06 - Pedvariation.meta
Torna alla: Indice Generale