Forum

> > CS2D > Scripts > Spawning an NPC with more health
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spawning an NPC with more health

4 replies
To the start Previous 1 Next To the start

old Spawning an NPC with more health

Alistaire
User Off Offline

Quote
> working on Dungeoncrawler mod
> not finished

----

How would one spawn or make an NPC with more health than usual? I'm looking for a way that's possible to implement rather without triggers or anything on the map.

So far I've tried spawnobject and spawnnpc, but it doesn't change health, I've tried to fill in loads of info in an NPC entity's name (_script_bossnpc hp money xp intchance intmin intmax), declaring a special type in a table for every map (['dcm_missions_2'] = { ['specialnpcs'] = { 'Bossmonster' = { mapname, hp, money, xp, intchance etc} , 'Uber Headcrab' } })

a.k.a you do not know anything about an NPC when it's spawned from an entity. This means, that you won't find an NPC back by internal ID, but only by initial health values.

This means I have to edit every single NPC entity on the map to have 1 health more than the previous one, etc, to name every NPC.

-

So if ANYONE has a way to make NPC's spawn with more health, or a way to return the entity it's spawned from, please comment.

old Re: Spawning an NPC with more health

Starkkz
Moderator Off Offline

Quote
@user Alistaire: It will be possible on the next version, there will be damage and heal commands for dynamic objects (npcs are dynamic objects as far as I know). The other way would be setting a value in Lua that is going to be the npc health, and detect npc damage with the cs2d lua hook objectdamage.

old Re: Spawning an NPC with more health

Alistaire
User Off Offline

Quote
Wait, do you mean this?

- There's a value like npc.health[dynid]
- If an npc gets hit, it always returns 1 (don't damage)
- Instead, the npc.health goes down
- If the npc.health <= 0 then kill the npc

This sounds genius. I did the exact same with player damage, to be honest. Wow.

----

Yet, it doesn't solve the problem that I can not name NPC's by dynid.

old Re: Spawning an NPC with more health

Starkkz
Moderator Off Offline

Quote
Right, you can use cs2d lua hook always and object(0,"table"). Check that the object type is an NPC (they do have an type id) if the dynamic object id is not in your npc table it's because it's been spawned recently on console or by cs2d map.

1
2
3
4
5
6
7
8
9
10
11
addhook("always","newnpc")
function newnpc()
for _, id in pairs(object(0,"table")) do
if (object(id,"type") == npc type id here) then
if (not npc.health[id]) then
-- npc has been spawned
npc.health[id] = npc health here
end
end
end
end

Try modifying it. Sorry about tabs, I'm on mobile.

old Re: Spawning an NPC with more health

Alistaire
User Off Offline

Quote
Well I find the general idea quite good, but it might work if I save all initial NPC dynid's in a big table, and whenever the player hits a new one, that one is most certainly spawned, and it'll read the special NPC's array for its name and health information.

Huge workarounds and all but this looks promising! I can now even add different weapondamage per player!
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview