NPC keeps having green Hair

So, there are a few scripts that let you spawn NPCs. But I couldn’t find any that let you change their clothes. So I decided to code my own one. My NPC can have clothes and even hair using the SetPedComponentVariation native. But then I noticed that this native doesn’t have the option to change the hair color. So I searched for another native and found SetPedHairColor . It worked for my character when I did SetPedHairColor(GetPlayerPed(-1), hair_color, 0) , but when I tried SetPedHairColor(npcPed, 0, 0) , it didn’t work for my NPC. This is my first own script, so if anything in the code doesn’t make sense - just don’t ask.

This is my code:

    local characterModel = GetHashKey('mp_m_freemode_01')
    local spawnPos = vector4(-372.6020, -273.4057, 32.9582, 323.7569)

    local npcPed = CreatePed(4, characterModel, spawnPos.x, spawnPos.y, spawnPos.z, spawnPos.w, false, false)

    SetPedComponentVariation(npcPed, 2, 18, 0, 1)
    SetPedHairTint(npcPed, 0, 0)
    SetPedComponentVariation(npcPed, 11, 190, 0, 2)
    SetPedComponentVariation(npcPed, 8, 56, 1, 2)
    SetPedComponentVariation(npcPed, 3, 85, 0, 2)
    SetPedComponentVariation(npcPed, 4, 35, 0, 2)
    SetPedComponentVariation(npcPed, 6, 25, 0, 2)
    SetPedComponentVariation(npcPed, 5, 52, 2, 2)
    SetPedComponentVariation(npcPed, 9, 64, 0, 2)
    SetPedComponentVariation(npcPed, 10, 44, 0, 2)
    SetPedComponentVariation(npcPed, 7, 8, 0, 2)

    FreezeEntityPosition(npcPed, true)

    SetEntityInvincible(npcPed, true)

    SetPedCanRagdoll(npcPed, false)
    SetBlockingOfNonTemporaryEvents(npcPed, true)
end)

image
Thanks in advance

SetPedHairColor(npcPed, 0, 0) might be influenced by the order of operations.

Here’s a quick snippet you can try:

-- Assuming npcPed is created and other components are set
SetPedComponentVariation(npcPed, 2, 18, 0, 1) -- Ensure this is a valid hair style
SetPedHairColor(npcPed, 0, 0)  -- Attempt to set hair color again

Also try using different color like SetPedHairColor(npcPed, 1, 1) to see if there’s any change at all.

SetPedComponentVariation(npcPed, 2, 18, 0, 1)
SetPedHairColor(npcPed, 1, 1)

It’s like this now but sadly it didn’t change anything. Hair is still green

Okay, I found it out myself. Just putting SetPedHeadBlendData(npcPed, 0, 0, 0, 0, 0, 0, 0, 0, 0, false) in the code fixed it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.