Know with what NPC you're dealing..?
4 replies



03.11.12 06:00:15 pm
> 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;
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?
> 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;
Code:
1
2
3
2
3
function spawnSoldier(x, y, rot)
parse('spawnnpc 5 '..x..' '..y..' '..rot)
end
parse('spawnnpc 5 '..x..' '..y..' '..rot)
end
Code:
1
2
3
4
5
6
7
8
9
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
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?
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.
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
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
----
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.
- rotation can be enhanced when spawning an NPC with Lua
- rootrot is an object(id, 'value') value
- there are 5 NPC ID's
Code:
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.
You should try the modulus lua function.
It's the same thing you did there.
Code:
1
local npcid = rootrot % 5
It's the same thing you did there.

You should try the modulus lua function.
It's the same thing you did there.
Code:
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.



