Forum

> > CS2D > Scripts > Know with what NPC you're dealing..?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Know with what NPC you're dealing..?

4 replies
To the start Previous 1 Next To the start

old Know with what NPC you're dealing..?

Alistaire
User Off Offline

Quote
> Working on a dungeoncrawler mod
> No I'm not promising it's gonna be released

----

So, how do you know with what NPC you're dealing AFTER you've spawned it yourself with Lua;

1
2
3
function spawnSoldier(x, y, rot)
	parse('spawnnpc 5 '..x..' '..y..' '..rot)
end

1
2
3
4
5
6
7
8
9
function _objDmgFunc(dynid, dmg, id)
	if object(dynid, 'type') >= 30 and object(dynid, 'type') <= 35 then
		_targetHudFunc(dynid, dmg, id, object(dynid, 'type'))
	end
end

function _targetHudFunc(dynid, dmg, id, npctype)
	parse('hudtxt2 '..id..' 49 "©255255255'..npcNames[npctype-29]..': '..object(dynid, 'health')..' health left" 320 5 1')
end

It's pretty much about line 8; npcNames[npctype-29]. I searched the forums and found people saying a zombie is npc type 30, and headcrab npc type 31. But it is not.

Now, how do I find out what npc type/id I've just damaged?

old Re: Know with what NPC you're dealing..?

BetaM
User Off Offline

Quote
Try object(x,"player"). (it returns the NPC type)

For some reason the NPC's with the same type as the player ID (so only 1-5) break when the player leaves the server (regardless of the mp_killbuildings value), so it's a bit tricky to put into multiplayer.
edited 1×, last 03.11.12 09:14:25 pm

old Re: Know with what NPC you're dealing..?

Alistaire
User Off Offline

Quote
How I solved this:

- rotation can be enhanced when spawning an NPC with Lua
- rootrot is an object(id, 'value') value
- there are 5 NPC ID's

1
local NPC ID = ((rootrot / 5) - math.floor(rootrot / 5)) * 5

----

To spawn an NPC you have to put in the NPC ID, and the rotation you actually want. The script enhances the rotation a bit so that if it goes through said function, the NPC ID will be retrieved.

It's a terrible way of doing this, but it works.

old Re: Know with what NPC you're dealing..?

Alistaire
User Off Offline

Quote
user Starkkz has written
You should try the modulus lua function.
1
local npcid = rootrot % 5
It's the same thing you did there.


I found out it's easier to use object(id, 'player'). Rootrot isn't set if you spawn an NPC with Lua.

The downside of the player value is that, according to some people, NPC's die when you leave the server or something. Maybe it's a myth, just like object(id, 'type') = 30 to 35.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview