Game Development Community

Prevent NPC from hurting

by Temasek Polytechnic Tp8 · in Torque Game Engine · 06/18/2006 (9:09 pm) · 22 replies

Anyone had any idea to prevent NPC from been killed by player or BOT
Page «Previous 1 2
#1
06/18/2006 (9:25 pm)
Give your NPC class it's own ::damage function that does nothing?
#2
06/19/2006 (12:01 am)
I second Paul:
Send those offending bytes of damage to the all consuming bit bucket! Let your almighty NPC walk with confidence knowing he can not die. Let the hordes come and cast themselves against this NPC, like the waves of the ocean against the rocks. Never shall this NPC know pain again!!!

You could do this too (in damage function):
...
if(%obj.name $= "BadAssNPC")
   return;
...

Or something like that. Name is not a real variable and I did not even bother to look in the damage function, but I think you get the idea.

You need to read the first part of this message like there is some dooms day guy speakin in a gruff and foreboding voice to hear what I heard in my head when I wrote it. Did you hear that? Never mind it's gone now.
#3
06/19/2006 (1:02 am)
Cannot work
#4
06/19/2006 (1:55 am)
Yes it can
#5
06/19/2006 (2:00 am)
In the NPC datablock

isInvincible = true;

Isn't that a much easier way of doing it?
#6
06/19/2006 (2:17 am)
I knew there was a variable for that, but I forgot what it was.
#7
06/19/2006 (2:23 am)
If you set isInvincible to true, the character can still die right it just doesn't take any damage in the ondamage?

But the isInvincible would prevent the NPC to take damage from a car, right?
#8
06/19/2006 (2:40 am)
If isInvincible is set to true the character will never die nor take any damage of any type.

Issuing a suicide cmd, projectiles, collision with a car, falling from a great height - doesn't matter what you do the character will NEVER die.
#9
06/19/2006 (2:42 am)
But it would still be possible to fake the death of the NPC by playing the death animation and then remove the character?
#10
06/19/2006 (2:50 am)
Sure, you could do that. Or you could just set isInvincible to false when you require the NPC to die and let nature take its natural course.
#11
06/19/2006 (3:30 am)
If it's a datablock value you don't wanna be doing that. In that case youl'd want to give it a ::damage function that you can switch on and off, it'd have the same effect.
#12
06/19/2006 (4:11 am)
Then wouldn't the best solution be to create an ::damage function which determined if the source could damage the npc and if it couldn't simply return, similar to pauls?
#13
06/19/2006 (7:12 am)
Quote:
If it's a datablock value you don't wanna be doing that. In that case youl'd want to give it a ::damage function that you can switch on and off, it'd have the same effect.
You can alter datablocks on the fly, I do it all the time. As long as you keep it to a minimum you won't run into any problems. Though Martin's method would probably be better however would require more work.
#14
06/19/2006 (7:28 am)
Actually, the more I think about it... if you needed your NPC to die at some point than the datablock method isn't the way to go. Although you can change datablocks on the fly, they're not supposed / designed to be. Plus if you had more than one NPC sharing the same datablock they would all be affected by any changes you make to the datablock.

Yeah, use a damage function which only applies damage if a global variable is set to true. This way you can control when and if a NPC will receive damage.

If the NPC is to never die, it would be easier to use an invincible value in the datablock.
#15
06/19/2006 (8:31 am)
Quote:
Yeah, use a damage function which only applies damage if a global variable is set to true. This way you can control when and if a NPC will receive damage.

Not that I discurage the use of a global, which I usually do, but wouldn't it be more correct to have a local object var, this way different NPC sharing the same datablock would be able to get killed, decided by the class var?
#16
06/19/2006 (8:47 am)
Depends on your style of scripting ;)
#17
06/19/2006 (8:55 am)
Roger that ;)
#18
06/19/2006 (9:11 am)
Martin has a good point - seems to me that using a global such as "$isNPCKillable" is pretty much equivelant to setting the value of isInvincible in the datablock. personally i'd make it a member variable of the NPCs script object.

eg %theAIPlayer.isKillable
#19
06/19/2006 (9:13 am)
Yes Martin makes a brilliant point, as do you Orion.

I screwed up =(

Still, we got there in the end ;)
#20
06/19/2006 (1:05 pm)
Quote:
Quote:

If it's a datablock value you don't wanna be doing that. In that case youl'd want to give it a ::damage function that you can switch on and off, it'd have the same effect.


You can alter datablocks on the fly, I do it all the time. As long as you keep it to a minimum you won't run into any problems. Though Martin's method would probably be better however would require more work.

Not to pick on Tim or anything, but just because you can do it doesn't mean you should do it!

There are dozens of reasons why you shouldn't change the values within a datablock during runtime, but not many (if any) designs that require it.
Page «Previous 1 2