Forum

> > CS2D > Scripts > Npc ID
Forums overviewCS2D overview Scripts overviewLog in to reply

English Npc ID

4 replies
To the start Previous 1 Next To the start

old Npc ID

KaBooMa
User Off Offline

Quote
Hey guys! Im making a mod and putting the new npcs to use.

Can you guys help me with a little problem. Im spawning alot of zombie npcs and i need to know. How can i find there id when they are spawned? I have it so when the server start, they spawn. I have a global array ( NpcLevel ) that is set when they spawn. It is randomly set from 1,3. How do i find the npcs id so i can do

NpcLevel[npcid] = random.math(1,3)

from there i can fix my exp and money gain system xD. Thanks for all help.

old Re: Npc ID

EngiN33R
Moderator Off Offline

Quote
First, NPCs are objects like walls and dispensers. They have the type 30. so
1
if (object(obj,"type")==30) then
... I think you'll understand the rest

old Re: Npc ID

DC
Admin Off Offline

Quote
that's right. what you also need to know: the sub-id (so whether it is a zombie, headcrab or npc) is stored in the player field of the NPC dynamic object.
1
object(obj,"player")

old Re: Npc ID

KaBooMa
User Off Offline

Quote
Thanks Alot. But some reason i cant figure this out still. Its probably is the smallest error and i just don't see it....here is my code, if you guys can see what im doing wrong and/or show me how to change up to make it work a little better, please do so. This is all i could brainstorm...

Spoiler >

old Re: Npc ID

DC
Admin Off Offline

Quote
it's insanely inefficient to do it that way! use object(0,"table") to get a Lua table with all EXISTING objects. the table contains all IDs. you can just iterate over this table instead of iterating over an insane number of non-existing elements

I don't see the problem in your code. use debug output messages (msg/print) to see where it fails. (after the for-statement and after each if-statement).

a common mistake would be that SpawnNpcX/Y contains the position in pixels and not in tiles or something like that.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview