[CLOSED] Spawn NPC's Serversided or set a specific npc look

Hey first of all sorry for my bad english. I’m creating a npc script to spawn npc’s like drugdealers or shop employees for example.
So i used the hash 0x80E59F2E / a_m_y_acult_02 for my drugdealer but the npc does have another looking for every player…

Code i use: (client.lua)

Citizen.CreateThread(function()
  dealermodel = 0x80E59F2E
  RequestModel(dealermodel)
  while not HasModelLoaded(dealermodel) do
       Wait(1)
  end
  createDEALER()
end)

function createDEALER()
	created_ped = CreatePed(4, dealermodel , 3619.57,5019.58,11.36 - 1, 198.25, false, true)
	SetEntityHeading(created_ped, 198.25)
	FreezeEntityPosition(created_ped, true)
	SetEntityInvincible(created_ped, true)
	SetBlockingOfNonTemporaryEvents(created_ped, true)
	TaskStartScenarioInPlace(created_ped, "WORLD_HUMAN_DRUG_DEALER_HARD", 0, true)
end

So now to my question: Is there a way how to spawn the ped serversided or how to set a specific ped looking?

Thanks for your help <3

On Server Side:

spawns = {
   vector4(0.0, 0.0, 0.0, 0.0),
   vector4(1.0, 1.0, 1.0, 1.0)
}

TriggerClientEvent('client:spawnNPC', source, 0x80E59F2E, spawns[math.random(#spawns)])

On Client Side:

RegisterNetEvent('client:spawnNPC')

AddEventHandler('client:spawnNPC', function(model, coords)
   -- do the things here
end)

I guess that i could to help you (:

1 Like

I have the solution to make the peds the same

client.lua

Citizen.CreateThread(function()
  TriggerServerEvent("checkSpawnedNpcs") 
end)

RegisterNetEvent("spawnNpcs")
AddEventHandler("spawnNpcs", function()
    Citizen.CreateThread(function()
        -- Spawning the npc
    end)
end)

And the server.lua

local npcsHaveSpawned = false 

RegisterServerEvent("checkSpawnedNpcs")
AddEventHandler("checkSpawnedNpcs", function()
    if not npcsHaveSpawned then 
        npcsHaveSpawned = true 
        TriggerClientEvent("spawnNpcs", source)
    end 
end)

This is merely an example. What this does is everytime a player joins, it runs an event to the server to see if the npcs you want to spawn are already spawned. If that is false it triggers an event back to the client to make the npcs spawn (Note if you spawn a npc spawn it with isNetwork = true) . And for the next player that joins the npc is already spawned.

2 Likes