Base NPC?

Hey! so im making a job NPC and he spawns and works perfict! but!!! i cannot get 2 to spawn so 1 has citizen and the other has police. i tryed making 2 seprate ent in the addon but the code interconnects and so many errors. then i tryed having a seprate addon per npc and that really does not work im not sure what to do ill upload the code to one of the npc if u want.

Show us the code/localize your variables.

https://www.dropbox.com/s/cojz1ewkmoma9f9/npc-trip.rar?dl=0 not virus lol

[editline]12th October 2014[/editline]

ill just paste the code aswell

[editline]12th October 2014[/editline]


 //autorun hook.Add("InitPostEntity", "spawncp", function()
	local job1 = ents.Create("npc_jeffery1")
	job1:SetPos(Vector(2389.828613, -5621.171387, -134.968750))
	job1:SetAngles(Angle(0, 179, 0))
	job1:Spawn()

local job2 = ents.Create("npc_jeffery2")
	job2:SetPos(Vector(2389.828613, -5621.171387, -134.968750))
	job2:SetAngles(Angle(0, 179, 0))
	job2:Spawn()
end)



then i have the ent in a seprate file and even if i make everything local for each ent its still all one

Because the second one is not inside of the hook?

EDIT: Try this



hook.Add("InitPostEntity", "spawncp", function()
	local job1 = ents.Create("npc_jeffery1")
	job1:SetPos(Vector(2389.828613, -5621.171387, -134.968750))
	job1:SetAngles(Angle(0, 179, 0))
	job1:Spawn()


	local job2 = ents.Create("npc_jeffery2")
	job2:SetPos(Vector(2389.828613, -5621.171387, -134.968750))
	job2:SetAngles(Angle(0, 179, 0))
	job2:Spawn()
end) 


i wrote it on this page i forgot to copy it from my code so i wrote it in and messed up

[editline]12th October 2014[/editline]

is this the correct way to make more than one do should i make a new addon for each npc

not both npc spawn with each model different but the derma for each one is the same even if i add local infront of everything???

Dude i have the same problem and its really annoying.

A better way would be to just have npc_jeffrey and to add a custom function like ent:SetTeamID( x );

When the user uses ENT:Use or ENT:AcceptInput, ( serverside ), it reads the team id you set with SetTeamID and networks that to the client. The client can then use that id to populate the derma that opens. It is how I do it with mine; I can register a different set of instructions in my set based on id ranging from different vgui panel, to the same with different options.

Here’s an example I wrote for someone with 2 buttons, join team 2 or close: https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_npc_jointeam_example.rar

Add to init.lua


//
//
//
ENT.TeamID = -1;
function ENT:SetTeamID( _id )
	self.TeamID = _id;
end

Alter init.lua


...

	net.Start( "npc_jointeam_openvgui" );
		net.WriteUInt( self.TeamID,32 ); -- You can use Float which is half double to avoid bit counting; although, 32 bits should be MORE than enough
	net.Send( _caller );

...


alter cl_npc_jointeam.lua, AFTER net.Receive( “npc_jointeam_openvgui”, function( _len ) ADD



	local _teamid = net.ReadUInt( 32 );


Then, just add a table in a shared file ( lua/autorun/sh_blah.lua which contains the table of data. Based on the id, the data should set up what vgui should load, and instructions for the server when the button is pressed…

You’ll need to update the sv_npc_jointeam.lua too; instead of SetTeam( 2 ), it’d need to know the teamid. The server will need to be more strict; it’ll need to ensure the id exists in the shared table, otherwise return; end
If the index exists, then ensure the instructions exist for the team to join…

I’ll make a new example that is more dynamic when I’m back on my desktop.

ok makes sence

what if i want to do it with spawn pos? i want two complete different npc in two complete different spots

Change the vectors of where they spawn.

i did… only one or the other spawns. even if they both have complete different id and ent name

Acording to earlier code, the SetPos vectors are the same.

that was a typo. and instead of putting them both in one file i made two complete seprate addon folders for each npc and they both share stuff even with different ent names?

[editline]19th October 2014[/editline]

mabe because the file names in autorun/server are the same?

i just used a table and a look to go thru and spawn/fill the vgui