About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
NPC's
Author Message
Brainache Offline
Member

Post: #1
NPC's
Hey there,

I am starting work on implementing NPCs (monsters, creatures, etc) and need a bit of direction please....

I've used the 'dynamically adding objects' example, and modifed the barrel code to drop a chr type object - and this working correctly. However, when I move the main character - all the dynamically dropped chr's move as well.

I havent been able to find out how to dynamically create an object of a particular class...

For example:

I want to extend the chr struct as Player ( as is currently done in the character example) and another extended as NPC (that does not have movement code)

How would I then spawn the NPC stuct into the world? Would I be better off adding them via Game::world.create... or by using my own container to hold them? ( I would think it would be more effecient to use game::world...)

Your thoughts?

Thanks
12-06-2008 04:27 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: NPC's
Hi,
For this you would need either:
1) edit obj_type.h enum in your data folder, and create additional types OBJ_CHR_PLAYER or OBJ_CHR_NPC (these are just examples)
create some base .obj file with those types, then in loading the world in the code point OBJ_CHR_PLAYER to one class (and container) and OBJ_CHR_NPC to other class (and container)

2) or stick to only one OBJ_CHR type (which already exists), and add to the file data\obj\chr\base.obj a custom parameter "Bool is_player" or "Bool is_npc", then save it and set your .obj files to have this parameter set on "on" or "off"
then in your custom class (derived from Game::Chr) code your 'update' function to work differently wheter "is_player" is on or off

Those 2 methods are ok, it's your choice which one to use.
12-06-2008 08:17 PM
Find all posts by this user Quote this message in a reply
Brainache Offline
Member

Post: #3
Re: NPC's
Great - thanks for the pointers.. I think I'll take the first approach....
12-06-2008 09:15 PM
Find all posts by this user Quote this message in a reply
Post Reply