[OLD] [Release] NPCLife v1.0.0 - Put life into your stores

Did you put 209.0 or just 209? You need the .0

1 Like

If you give them weapons they will not flee :stuck_out_tongue:
I’m working on putting a timer before reappearing the killed npc :slight_smile:

if you want to freeze npc for ever replace this:

-- Spawn NPC
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
	
	if (not generalLoaded) then
	  
	  for i=1, #ShopClerk do
        RequestModel(GetHashKey(ShopClerk[i].modelHash))
        while not HasModelLoaded(GetHashKey(ShopClerk[i].modelHash)) do
          Wait(1)
        end
		
        ShopClerk[i].id = CreatePed(2, ShopClerk[i].modelHash, ShopClerk[i].x, ShopClerk[i].y, ShopClerk[i].z, ShopClerk[i].heading, false, true)
        SetPedFleeAttributes(ShopClerk[i].id, 0, 0)
		SetAmbientVoiceName(ShopClerk[i].id, ShopClerk[i].Ambiance)
		SetPedDropsWeaponsWhenDead(ShopClerk[i].id, false)
		SetPedDiesWhenInjured(ShopClerk[i].id, false)
		GiveWeaponToPed(ShopClerk[i].id, ShopClerk[i].Weapon, 2800, false, true)
        -- freeze npc here
        SetBlockingOfNonTemporaryEvents(ShopClerk[i].id, true)
		
      end
      generalLoaded = true
		
    end
	
  end
end)

Does it work with vrp framework?
Normally this should work, it is a code that has to adapt to everything (there is no server event)

Indicate the exact position of the npc (x, y, z and heading) {in first time, try to replace 209 by 209.0, As Briglair told you}
Download this: coordsaver.zip (1.3 KB)

I have slightly modified the script to get the Heading position of the player
(command in game is /pos2)

It’d be nice if the peds somehow synced up with other players. For example, one NPC might have died (say a store robbery) but when another player arrives to the scene the shop keep is standing normal like nothing happened.

1 Like

It is more realistic that the ped is dead as soon as a player kills it (for all player)

he meant it currently does not sync. so whena player kills the ped, if someone who comes in 1 second later they currently see the ped like nothing happend. It would be more realistic if the ped was dead for all players, which is what he was saying.

1 Like

Oh ok, I did not understand, I will try to correct this.

its all good bro! and thank you for making a great script!

2 Likes

how do i add an animation like dancing to the ped?

1 Like

If you want to replace the hello emote

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
		RequestAnimDict("mini@strip_club@lap_dance@ld_girl_a_accept")
		while (not HasAnimDictLoaded("mini@strip_club@lap_dance@ld_girl_a_accept")) do 
			Citizen.Wait(0) 
		end

        RequestAnimDict("random@shop_gunstore")
		while (not HasAnimDictLoaded("random@shop_gunstore")) do 
			Citizen.Wait(0) 
		end
		
		for i=1, #ShopClerk do
			distance = GetDistanceBetweenCoords(ShopClerk[i].x, ShopClerk[i].y, ShopClerk[i].z, GetEntityCoords(GetPlayerPed(-1)))
			if distance < 4 and PlayingAnim ~= true then
                --emote is here:
				TaskPlayAnim(ShopClerk[i].id,"mini@strip_club@lap_dance@ld_girl_a_accept","ld_girl_a_accept_cam", 1.0, -1.0, 4000, 0, 1, true, true, true)
				PlayAmbientSpeech1(ShopClerk[i].id, ShopClerk[i].VoiceName, "SPEECH_PARAMS_FORCE", 1)
				PlayingAnim = true
				Citizen.Wait(4000)
				if PlayingAnim == true then
					TaskPlayAnim(ShopClerk[i].id,"random@shop_gunstore","_idle_b", 1.0, -1.0, -1, 0, 1, true, true, true)
					Citizen.Wait(40000)
				end
			else
				--don't touch this
				--TaskPlayAnim(ShopClerk[i].id,"random@shop_gunstore","_idle", 1.0, -1.0, -1, 0, 1, true, true, true)
			end
			if distance > 5.5 and distance < 6 then
				PlayingAnim = false
			end


		end
  end
end)

If you want to change the emote after the npc said hello:

if PlayingAnim == true then
    TaskPlayAnim(ShopClerk[i].id,"mini@strip_club@lap_dance@ld_girl_a_accept","ld_girl_a_accept_cam", 1.0, -1.0, -1, 0, 1, true, true, true)
end

Also modify this:

RequestAnimDict("mini@strip_club@lap_dance@ld_girl_a_accept")
while (not HasAnimDictLoaded("mini@strip_club@lap_dance@ld_girl_a_accept")) do 
	Citizen.Wait(0) 
end

list of animation:

1 Like

Update to 1.0.1

  • Fix Syncronization bug, Normally, all npcs are syncronized.
1 Like

i want to add it for a specific npc like stripper for example i don’t want it to overlap with the other npcs

1 Like

Create a new table like this:

local ILoveDance= {
  -- ID: id of NPC | name: Name of Blip | BlipID: Icone of Blip | VoiceName: NPC Talk When near it | Ambiance: Ambiance of Shop | Weapon: Hash of Weapon | modelHash: Model | X: Position x | Y: Position Y | Z: Position Z | heading: Where Npc look
	{id = 1, name = "Dancer", BlipID = 52, VoiceName = "SHOP_GREET", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "mp_m_shopkeep_01", x = -2511.16479492188, y = 3616.90478515625, z = 13.6422147750854, heading = 245.000457763672}, 
	{id = 2, name = "Dancer", BlipID = 52, VoiceName = "SHOP_GREET", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "mp_m_shopkeep_01", x = 24.392505645752, y = -1345.41369628906, z = 29.4970207214355, heading = 264.900115966797},
	{id = 3, name = "Dancer", BlipID = 52, VoiceName = "SHOP_GREET", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "mp_m_shopkeep_01", x = -47.3110542297363, y = -1758.62475585938, z = 29.4209995269775, heading = 48.1558074951172},
}

add a new “for” in spawn npc

local PlayingAnim = false
local PlayingAnimDance = false

-- Spawn NPC
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
	
	if (not generalLoaded) then
	  
	  for i=1, #ShopClerk do
        RequestModel(GetHashKey(ShopClerk[i].modelHash))
        while not HasModelLoaded(GetHashKey(ShopClerk[i].modelHash)) do
          Wait(1)
        end
		
        ShopClerk[i].id = CreatePed(2, ShopClerk[i].modelHash, ShopClerk[i].x, ShopClerk[i].y, ShopClerk[i].z, ShopClerk[i].heading, true, true)
        SetPedFleeAttributes(ShopClerk[i].id, 0, 0)
		SetAmbientVoiceName(ShopClerk[i].id, ShopClerk[i].Ambiance)
		SetPedDropsWeaponsWhenDead(ShopClerk[i].id, false)
		SetPedDiesWhenInjured(ShopClerk[i].id, false)
		GiveWeaponToPed(ShopClerk[i].id, ShopClerk[i].Weapon, 2800, false, true)
		
      end

      -- your new loop for here
      for i=1, #ILoveDance do
        RequestModel(GetHashKey(ILoveDance[i].modelHash))
        while not HasModelLoaded(GetHashKey(ILoveDance[i].modelHash)) do
          Wait(1)
        end
		
        ShopClerk[i].id = CreatePed(2, ILoveDance[i].modelHash, ILoveDance[i].x, ILoveDance[i].y, ILoveDance[i].z, ILoveDance[i].heading, true, true)
        SetPedFleeAttributes(ILoveDance[i].id, 0, 0)
		SetAmbientVoiceName(ILoveDance[i].id, ILoveDance[i].Ambiance)
		SetPedDropsWeaponsWhenDead(ILoveDance[i].id, false)
		SetPedDiesWhenInjured(ILoveDance[i].id, false)
		GiveWeaponToPed(ILoveDance[i].id, ILoveDance[i].Weapon, 2800, false, true)
		
      end
      generalLoaded = true
		
    end
	
  end
end)

an add new for in action npc

-- Action when player Near NPC (or not)
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
		RequestAnimDict("random@shop_gunstore")
		while (not HasAnimDictLoaded("random@shop_gunstore")) do 
			Citizen.Wait(0) 
		end
		
		for i=1, #ShopClerk do
			distance = GetDistanceBetweenCoords(ShopClerk[i].x, ShopClerk[i].y, ShopClerk[i].z, GetEntityCoords(GetPlayerPed(-1)))
			if distance < 4 and PlayingAnim ~= true then
				TaskPlayAnim(ShopClerk[i].id,"random@shop_gunstore","_greeting", 1.0, -1.0, 4000, 0, 1, true, true, true)
				PlayAmbientSpeech1(ShopClerk[i].id, ShopClerk[i].VoiceName, "SPEECH_PARAMS_FORCE", 1)
				PlayingAnim = true
				Citizen.Wait(4000)
				if PlayingAnim == true then
					TaskPlayAnim(ShopClerk[i].id,"random@shop_gunstore","_idle_b", 1.0, -1.0, -1, 0, 1, true, true, true)
					Citizen.Wait(40000)
				end
			else
				--don't touch this
				--TaskPlayAnim(ShopClerk[i].id,"random@shop_gunstore","_idle", 1.0, -1.0, -1, 0, 1, true, true, true)
			end
			if distance > 5.5 and distance < 6 then
				PlayingAnim = false
			end

             -- FOR loop ILoveDance here
             for i=1, #ILoveDance do
			distance = GetDistanceBetweenCoords(ILoveDance[i].x, ILoveDance[i].y, ILoveDance[i].z, GetEntityCoords(GetPlayerPed(-1)))
			if distance < 4 and PlayingAnimDance ~= true then
				TaskPlayAnim(ILoveDance[i].id,"random@shop_gunstore","_greeting", 1.0, -1.0, 4000, 0, 1, true, true, true)
				PlayAmbientSpeech1(ILoveDance[i].id, ILoveDance[i].VoiceName, "SPEECH_PARAMS_FORCE", 1)
				PlayingAnimDance = true
				Citizen.Wait(4000)
				if PlayingAnimDance == true then
					TaskPlayAnim(ILoveDance[i].id,"random@shop_gunstore","_idle_b", 1.0, -1.0, -1, 0, 1, true, true, true)
					Citizen.Wait(40000)
				end
			else
				--don't touch this
				--TaskPlayAnim(ILoveDance[i].id,"random@shop_gunstore","_idle", 1.0, -1.0, -1, 0, 1, true, true, true)
			end
			if distance > 5.5 and distance < 6 then
				PlayingAnimDance = false
			end


		end
  end
end)

Normally, by creating new loops and a new array, nothing should hinder other npc
(This is just an example to show you how to do)

I tried to edit the code to put cops inside of the police stations, and none of the peds are spawning, can someone take a look at my code and see where i fucked up. thanks!

-------------------------------------------------------------------------------------------------
---------------------------------- DON'T EDIT THESES LINES --------------------------------------
-------------------------------------------------------------------------------------------------

local generalLoaded = false
local PlayingAnim = false

-------------------------------------------------------------------------------------------------
----------------------------------- YOU CAN EDIT THIS LINES -------------------------------------
-------------------------------------------------------------------------------------------------

local ShopClerk = {
  -- ID: id of NPC | name: Name of Blip | BlipID: Icone of Blip | VoiceName: NPC Talk When near it | Ambiance: Ambiance of Shop | Weapon: Hash of Weapon | modelHash: Model | X: Position x | Y: Position Y | Z: Position Z | heading: Where Npc look
	{id = 1, name = "Shop", BlipID = 52, VoiceName = "SHOP_GREET", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "mp_m_shopkeep_01", x = -2511.16479492188, y = 3616.90478515625, z = 13.6422147750854, heading = 245.000457763672}, 
	{id = 2, name = "Shop", BlipID = 52, VoiceName = "SHOP_GREET", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "mp_m_shopkeep_01", x = 24.392505645752, y = -1345.41369628906, z = 29.4970207214355, heading = 264.900115966797},
	{id = 3, name = "Shop", BlipID = 52, VoiceName = "SHOP_GREET", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "mp_m_shopkeep_01", x = -47.3110542297363, y = -1758.62475585938, z = 29.4209995269775, heading = 48.1558074951172},
	{id = 4, name = "Ammunation", BlipID = 110, VoiceName = "GENERIC_HI", Ambiance = "AMMUCITY", Weapon = 0x1D073A89, modelHash = "s_m_y_ammucity_01", x = 841.843566894531, y = -1035.70556640625, z = 28.1948642730713, heading = 3.31448912620544},
}

local Police= {
  -- ID: id of NPC | name: Name of Blip | BlipID: Icone of Blip | VoiceName: NPC Talk When near it | Ambiance: Ambiance of Shop | Weapon: Hash of Weapon | modelHash: Model | X: Position x | Y: Position Y | Z: Position Z | heading: Where Npc look
	{id = 1, name = "Sandy Shores Sheriff Station", BlipID = 137, VoiceName = "GENERIC_HOWS_IT_GOING", Ambiance = "AMMUCITY", Weapon = 0x5EF9FEC4, modelHash = "csb_prolsec", x = 1852.88, y = 3688.95, z = 34.27, heading = 209.0},
	{id = 2, name = "Paleto Bay Police Station", BlipID = 137, VoiceName = "GENERIC_HOWS_IT_GOING", Ambiance = "AMMUCITY", Weapon = 0x5EF9FEC4, modelHash = "csb_prolsec", x = -448.33, y = 6012.64, z = 31.72, heading = 312.0}
	{id = 3, name = "Paleto Bay Bank Security", BlipID = 2, VoiceName = "GENERIC_HI", Ambiance = "AMMUCITY", Weapon = 0xA2719263, modelHash = "s_m_m_armoured_01", x = -118.42, y = 6469.75, z = 31.63, heading = 228.75}
}

-------------------------------------------------------------------------------------------------
---------------------------------- DON'T EDIT THESES LINES --------------------------------------
-------------------------------------------------------------------------------------------------

-- Blip For NPC
Citizen.CreateThread(function()
	for k,v in pairs(ShopClerk)do
		local blip = AddBlipForCoord(v.x, v.y, v.z)
		SetBlipSprite(blip, v.BlipID)
		SetBlipScale(blip, 0.8)
		SetBlipAsShortRange(blip, true)
		BeginTextCommandSetBlipName("STRING")
		AddTextComponentString(v.name)
		EndTextCommandSetBlipName(blip)
	end
end)

-------------------------------------------------------------------------------------------------
---------------------------------- DON'T EDIT THESES LINES --------------------------------------
-------------------------------------------------------------------------------------------------

-- Spawn NPC
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
	
	if (not generalLoaded) then
	  
	  for i=1, #ShopClerk do
        RequestModel(GetHashKey(ShopClerk[i].modelHash))
        while not HasModelLoaded(GetHashKey(ShopClerk[i].modelHash)) do
          Wait(1)
        end
		
        ShopClerk[i].id = CreatePed(2, ShopClerk[i].modelHash, ShopClerk[i].x, ShopClerk[i].y, ShopClerk[i].z, ShopClerk[i].heading, true, true)
        SetPedFleeAttributes(ShopClerk[i].id, 0, 0)
		SetAmbientVoiceName(ShopClerk[i].id, ShopClerk[i].Ambiance)
		SetPedDropsWeaponsWhenDead(ShopClerk[i].id, false)
		SetPedDiesWhenInjured(ShopClerk[i].id, false)
		GiveWeaponToPed(ShopClerk[i].id, ShopClerk[i].Weapon, 2800, false, true)
		
      end
	  
	    for i=1, #Police do
        RequestModel(GetHashKey(Police[i].modelHash))
        while not HasModelLoaded(GetHashKey(Police[i].modelHash)) do
          Wait(1)
        end
		
        ShopClerk[i].id = CreatePed(2, Police[i].modelHash, Police[i].x, Police[i].y, Police[i].z, Police[i].heading, true, true)
        SetPedFleeAttributes(Police[i].id, 0, 0)
		SetAmbientVoiceName(Police[i].id, Police[i].Ambiance)
		SetPedDropsWeaponsWhenDead(Police[i].id, false)
		SetPedDiesWhenInjured(Police[i].id, false)
		GiveWeaponToPed(Police[i].id, Police[i].Weapon, 2800, false, true)
		
      end
      generalLoaded = true
		
    end
	
  end
end)
    

-------------------------------------------------------------------------------------------------
---------------------------------- DON'T EDIT THESES LINES --------------------------------------
-------------------------------------------------------------------------------------------------

-- Action when player Near NPC (or not)
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
		RequestAnimDict("amb@world_human_guard_patrol@male@idle_a")
		while (not HasAnimDictLoaded("amb@world_human_guard_patrol@male@idle_a")) do 
			Citizen.Wait(0) 
		end

        RequestAnimDict("random@shop_clothes@mid")
		while (not HasAnimDictLoaded("random@shop_clothes@mid")) do 
			Citizen.Wait(0) 
		end
		
		for i=1, #ShopClerk do
			distance = GetDistanceBetweenCoords(ShopClerk[i].x, ShopClerk[i].y, ShopClerk[i].z, GetEntityCoords(GetPlayerPed(-1)))
			if distance < 4 and PlayingAnim ~= true then
				TaskPlayAnim(ShopClerk[i].id,"random@shop_clothes@mid","_greeting_a", 1.0, -1.0, 4000, 0, 1, true, true, true)
				PlayAmbientSpeech1(ShopClerk[i].id, ShopClerk[i].VoiceName, "SPEECH_PARAMS_FORCE", 1)
				PlayingAnim = true
				Citizen.Wait(4000)
				if PlayingAnim == true then
					TaskPlayAnim(ShopClerk[i].id,"random@shop_clothes@mid","_idle_b", 1.0, -1.0, -1, 0, 1, true, true, true)
					Citizen.Wait(40000)
				end
			else
				--don't touch this
				--TaskPlayAnim(ShopClerk[i].id,"random@shop_clothes@mid","_idle", 1.0, -1.0, -1, 0, 1, true, true, true)
			end
			if distance > 5.5 and distance < 6 then
				PlayingAnim = false
			end
   
   -- FOR loop Police here
         for i=1, #Police do
			distance = GetDistanceBetweenCoords(Police[i].x, Police[i].y, Police[i].z, GetEntityCoords(GetPlayerPed(-1)))
			if distance < 4 and PlayingAnimDance ~= true then
				TaskPlayAnim(Police[i].id,"amb@world_human_guard_patrol@male@idle_a","idle_a", 1.0, -1.0, 4000, 0, 1, true, true, true)
				PlayAmbientSpeech1(Police[i].id, Police[i].VoiceName, "SPEECH_PARAMS_FORCE", 1)
				PlayingAnimDance = true
				Citizen.Wait(4000)
				if PlayingAnimDance == true then
					TaskPlayAnim(Police[i].id,"amb@world_human_guard_patrol@male@idle_a","_idle_b", 1.0, -1.0, -1, 0, 1, true, true, true)
					Citizen.Wait(40000)
				end
			else
				--don't touch this
				--TaskPlayAnim(Police[i].id,"amb@world_human_guard_patrol@male@idle_a","idle_a", 1.0, -1.0, -1, 0, 1, true, true, true)
			end
			if distance > 5.5 and distance < 6 then
				PlayingAnimDance = false
			end


		end
  end
end)
1 Like

here:

local Police= {
  -- ID: id of NPC | name: Name of Blip | BlipID: Icone of Blip | VoiceName: NPC Talk When near it | Ambiance: Ambiance of Shop | Weapon: Hash of Weapon | modelHash: Model | X: Position x | Y: Position Y | Z: Position Z | heading: Where Npc look
	{id = 1, name = "Sandy Shores Sheriff Station", BlipID = 137, VoiceName = "GENERIC_HOWS_IT_GOING", Ambiance = "AMMUCITY", Weapon = 0x5EF9FEC4, modelHash = "csb_prolsec", x = 1852.88, y = 3688.95, z = 34.27, heading = 209.0},
	{id = 2, name = "Paleto Bay Police Station", BlipID = 137, VoiceName = "GENERIC_HOWS_IT_GOING", Ambiance = "AMMUCITY", Weapon = 0x5EF9FEC4, modelHash = "csb_prolsec", x = -448.33, y = 6012.64, z = 31.72, heading = 312.0},
	{id = 3, name = "Paleto Bay Bank Security", BlipID = 2, VoiceName = "GENERIC_HI", Ambiance = "AMMUCITY", Weapon = 0xA2719263, modelHash = "s_m_m_armoured_01", x = -118.42, y = 6469.75, z = 31.63, heading = 228.75},
}

You have forgotten commas after }

i knew it was something simple thanks

2 Likes

If another error occurs, do not hesitate to report it :wink:
I am a beginner in lua but I would do my best to help you !

Thanks, i put the commas in, but still no joy.

Did you notice this yet?

yes i did and i changed it, but still no joy

1 Like

ShopClerk[i].id = CreatePed(2, Police[i].modelHash, Police[i].x, Police[i].y, Police[i].z, Police[i].heading, true, true)

do you have tryed this:

Police[i].id = CreatePed(2, Police[i].modelHash, Police[i].x, Police[i].y, Police[i].z, Police[i].heading, true, true)

ShopClerk[i].id is for the array ShopClerk
if your new array is named Police, call it Police[i].id

Otherwise it will fetch the information in ShopClerkand not in Police

if this doesn’t work, try this:
NPCLife_multiNPC.rar (2.0 KB)