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

4 replies
Goto Page
To the start Previous 1 Next To the start
Up
Alistaire
User
Offline Off
> 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;

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


Code:
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?
IMG:http://i.imgur.com/5zhwOTP.png
03.11.12 06:23:47 pm
Up
BetaM
User
Offline Off
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
03.11.12 09:08:13 pm
Up
Alistaire
User
Offline Off
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

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.
IMG:http://i.imgur.com/5zhwOTP.png
04.11.12 03:47:49 pm
Up
Starkkz
Moderator
Offline Off
You should try the modulus lua function.
Code:
1
local npcid = rootrot % 5

It's the same thing you did there.
lol
04.11.12 03:56:16 pm
Up
Alistaire
User
Offline Off
user Starkkz has written:
You should try the modulus lua function.
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.
IMG:http://i.imgur.com/5zhwOTP.png
To the start Previous 1 Next To the start