[RELEASE] [STANDALONE] NPC Spawner

A configurable resource to spawn NPC peds in a specific locations at boot. You can also specify relationships, armament, godmode, tasks, and more.

This resource lets you spawn a set of NPCs at boot in predefined locations and assign them models, animations, tasks, relationships, combat and reaction attributes, and more. You can set all this and specify any number of NPCs in the included config file.

Download - Github

Enjoy!

14 Likes

if anybody downloaded this in the first few hours after i posted it, please download the updated package from github. i initially uploaded it without the server script. Its working now!

5 Likes

Thanks for what I was looking for :*

1 Like

Hi great resource, could you tell me how to use task= properly? and how much hp gives extrahealth and whats soldier= do

1 Like

thanks!

you can add your task native down in the cl_main.lua around line 141 by uncommenting

			--elseif v.task == "someothervariable" then
			--	insertnewtaskhere

and making it say something like

			if v.task == "taskcombatplayer" then
				TaskCombatPed(npcSpawn, ped, 0, 16)

or whatever your preferred task is. after you do that, you can go into the config and change the task line for the npc that you want to perform the task from

task=nil

to whatever you called your task in the cl_main.lua. in the case of the provided task, since the script is looking for taskcombatped to trigger that task, you would put this in the config at the task line

task="taskcombatped"

extrahealth gives men 200 instead of 100 and women 150 instead of 100.

soldier does a variety of things combat oriented. I wont go into detail explaining them here but ill post the natives that are being used and you can get a general idea of whats happening

		if v.soldier == true then
			SetPedSeeingRange(npcSpawn, 100.0)
			SetPedHearingRange(npcSpawn, 100.0)
			SetPedCombatAttributes(npcSpawn, 46, 1)
			SetPedFleeAttributes(npcSpawn, 0, true)
			SetPedCombatRange(npcSpawn,2)
			SetPedArmour(npcSpawn, 100)
			SetPedAccuracy(npcSpawn, 100)
		end

cheers!

thanks for fast answer i have one last question do i need to restart whole server to reset npc? or i can just restart script?

2 Likes

Restart the server for now. I’m currently adding functionality to respawn them when they’re killed. I should be done with it in a while so keep an eye on the GitHub for an update :wink:

1 Like

First things first, Thank you for this! this so far has been the simplest spawner to use. awesome work.

That being said I am completely inept for some reason. Am I doing something wrong? I can’t get the peds to have the rifle and I can’t get them to try and kill the player.

	---
  { model="s_m_y_blackops_02", 
  x=409.46, y=-964.75, z=29.48, a=47.99,
  anim=nil, 
  animName=nil,
  stoic=true,
  voice=male,
  soldier=true,
  lightarms=false,
  mediumarms=false,
  heavyarms=true,
  relationship=guard,
	god=false,
	task=TaskCombat,
  extrahealth=false},
  ---
 

I have tried your existing player combat as well as one I found online. but all I get is the ped just stands there.

if v.task ~= nil then
			local ped = GetPlayerPed(-1)
			if v.task == "taskcombatplayer" then
				TaskCombatPed(npcSpawn, ped, 0, 16)
			elseif v.task == "TaskCombat" then
				TaskCombat(PlayerPed);
			--elseif v.task == "someothervariable" then
			--	insertnewtaskhere
			end

1 Like

stoic should be false unless you want the npc to always be oblivious to their surrounding.

they will pull out their guns when they begin to attack you so not thats probably why you havent seen them yet.

setting a new relationship will ONLY work if you also setup the relationship. i have moved the lines to do this into the config, right at the top. if you redownload from the github and look, youll see three lines at the top of the config that say “SUB_CREW”. just replace anywhere it says that with “GUARD”. also, in the npc setup table, make sure whatever you specify in the relationship setup is set to match. check the example below.

--Relationship Setup
AddRelationshipGroup("GUARD")
SetRelationshipBetweenGroups(5, "GUARD", "PLAYER")
SetRelationshipBetweenGroups(0, "GUARD", "GUARD")

one of the npcs from the table should look like the following:

{ model="csb_bogdan",
  x=509.66, y=4827.44, z=-62.59, a=260.44,
  anim=nil,
  animName=nil,
  stoic=false,
  voice=male,
  soldier=true,
  lightarms=true,
  mediumarms=false,
  heavyarms=true,
  relationship="GUARD",
  god=false,
  task=nil,
  extrahealth=false},
  ---

hope i helped. Im sorry but im still pretty new to writing scripts so there are no checks or anything to keep the code from breaking if someone enters the wrong thing in the config. I am currently working on this script and adding a way to respawn the npcs when they die. keep an eye on the github for a new version in the next few days.

Hello is this synced between players

yes the created NPCs are networked and the function to spawn them is triggered by the server.

thx ur the best i try to found this for at least 9 mouth

1 Like

there should be a way in the config to set how long after death should the npc be respawned . like maybe 60000 after death where 1000 = 1 second , they should respawn and it could be set individually for each npc so people can change respawn wait time to their needs. this would be useful in so many places.

I was doing this but not for each npc in the one im rewriting. I will look into timed respawns for each npc for V2. Thanks for the suggestion!

1 Like

how to add animation correctly, I prescribe a lot of animations and it doesn’t work

Is it possible to set it so that they can be friendly to a job or gang?

Starting to become quite buggy. Sometimes they dont spawn at all.

1 Like

this would be great hopefully he responds with a solution

Is there any chance you will add a loot system? :slight_smile:

I’m too busy with work to maintain any of my scripts right now but a user by the name of oosayeroo has been reworking this and I have given him permission to post/fork this resource if anybody is interested!

Thanks, oosayeroo!

1 Like