Forum

Making a monster spawn another monster when it dies?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Making a monster spawn another monster when it dies?

Postby SamUK » Tue Dec 01, 2009 7:11 pm

Yep.

I've started on a new monster, almost done with it. When I thought I was done, bang problem.

I want to make a monster that idle. It just sits on the wall, however you kill it, it spawns a bunch of creatures. I thought it'd be pretty simple.

Code: Select all
 void() pod_die =
{
// regular death
   sound (self, CHAN_VOICE, "infection/death1.wav", 1, ATTN_NORM);   
   Monster_infection (Self.origin);
   CreateFblood (self.origin);
   pod_die1 (self.origin);


However, when the pod dies, the infection monster spawns, but it's like it's not connected to the AI as it just stands there doing nothing. I can still kill it of course, it just doesn't do anything.

Any help?

(Warning, newbie here ;) )
Working on Solitude
SamUK
 
Posts: 101
Joined: Wed Dec 17, 2008 6:47 pm
Location: United Kingdom

Postby Team Xlink » Tue Dec 01, 2009 8:40 pm

Well do any of the things you called in your code have the AI routine in it? If not you need to add it.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby Dr. Shadowborg » Tue Dec 01, 2009 9:17 pm

Is it animating? If not you probably need to do something to initialize it in it's spawn function, probably something like this for example:

Code: Select all
newmonster.think = evile_stand;
newmonster.nextthink = time + 0.1;
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm

Postby Team Xlink » Tue Dec 01, 2009 10:18 pm

Dr. Shadowborg wrote:Is it animating? If not you probably need to do something to initialize it in it's spawn function, probably something like this for example:

Code: Select all
newmonster.think = evile_stand;
newmonster.nextthink = time + 0.1;


Is it doing damage to the player?

If it is then I think Dr. Shadowborg is right.

Where exactly is your AI routine located?
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby Wazat » Tue Dec 01, 2009 10:40 pm

Also note that if you're not calling walkmosnter_start (or the corresponding fly/swim functions) you can have other problems, like your monster kill count not matching the maximum.

Make sure you're calling the _start function and that your animations are set up to loop properly (i.e. walk, stand, etc). The animations should also call the appropriate AI functions like ai_stand();

Mind if we take a gander at the Monster_infection function?

-Wazat
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby SamUK » Tue Dec 01, 2009 10:49 pm

Bare with me.

Sure, Wazat.

Code: Select all
void() monster_infection =
{
   if (deathmatch)
   {
      remove(self);
      return;
   }
   precache_model ("progs/h_infected.mdl");
   precache_model ("progs/infectedflood.mdl");
   precache_model ("GFX/bflood.spr");
   
   precache_sound ("infection/dattack1.wav");
   precache_sound ("infection/ddeath.wav");
   precache_sound ("infection/idle.wav");

   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;

   setmodel (self, "progs/infectedflood.mdl");

   setsize (self, '-8 -8 -8', '8 8 8');
   self.health = 1;

   self.th_stand = infection_stand1;
   self.th_walk = infection_walk1;
   self.th_run = infection_run1;
   self.th_die = infection_die; // Gibing only
   self.th_melee = infection_atta1;
   self.th_missile = infection_leap1;

   walkmonster_start();
};


No, it's doing nothing but spawn and die. Also, what do you mean by Ai routine, not up to scrtach with my coding jargon.
Working on Solitude
SamUK
 
Posts: 101
Joined: Wed Dec 17, 2008 6:47 pm
Location: United Kingdom

Postby frag.machine » Tue Dec 01, 2009 11:12 pm

I had a similar problem with my skeleton king monster; it spawns zombies to fight its enemies. I solved the zombies ignoring the skel's enemies with this:

Code: Select all
   // let the spawned monster fight against the parent's enemies
        // (assume self = the parent monster)
   sight_entity = self;
   sight_entity_time = time;


EDIT: spellcheck, removed a bit of useless code and added a better comment
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby SamUK » Tue Dec 01, 2009 11:47 pm

Hmm, it's getting there. It moves now. Still doesn't attack though.
Working on Solitude
SamUK
 
Posts: 101
Joined: Wed Dec 17, 2008 6:47 pm
Location: United Kingdom

Postby Team Xlink » Wed Dec 02, 2009 1:11 am

SamUK may I have your permission to fix it and upload an improved version for us?
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby Dr. Shadowborg » Wed Dec 02, 2009 1:19 am

Hmm, what you've got there in monster_infection should only work for monster_infection placed in the map by the mapper. (Just guessing, but are you using Darkplaces or something? Don't worry, it's just that Darkplaces has a habit of allowing things that make stuff that should break normal engines not break, which while good, is also very bad for teaching proper modding techniques. Another problem I see there is that monster_infection isn't set up to take any vectors.)

Anyway, you need to make a separate spawn function for your pod spawned infection monsters that also takes into account the relativity factor. i.e. self in the case of pod_die() is the pod, not the monster_infection, hence when monster_infection is called it doesn't set up the monster_infection's functions, it just modifies your pod entity.

In short, you need to create a copy of monster_infection similiar to the following: (note, I've taken out the precaches and deathmatch removal, they should be defined within monster_pod or whatever)

Code: Select all

void(vector org) monster_pod_infection =
{
   local entity stemp;
   
   newmis = spawn();
   stemp = self;
   self = newmis;
   
   setorigin(self, org);
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;

   setmodel (self, "progs/infectedflood.mdl");

   setsize (self, '-8 -8 -8', '8 8 8');
   self.health = 1;

   self.th_stand = infection_stand1;
   self.th_walk = infection_walk1;
   self.th_run = infection_run1;
   self.th_die = infection_die; // Gibing only
   self.th_melee = infection_atta1;
   self.th_missile = infection_leap1;

   walkmonster_start();

   self = stemp;
};


Hope this helps!
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm

Postby Wazat » Wed Dec 02, 2009 4:56 am

As Doc Shadowborg pointed out, your precache functions etc should be moved into the spawn function of the monster that creates these creatures on death. Precache should only ever happen during the map loading. Darkplaces handles it nicely, but other engines probably won't.

The fact that your monsters aren't performing their own target acquisition worries me though. Perhaps something is missing in the animations that handles the target searching (i.e. ai_stand etc). Can you post the code for the animations?

Actually, it may be that nothing is wrong with the animation code. It could very well be that the fix Dr. Shadowborg posted will fix it. As he said, your spawn function was modifying self instead of a newly spawned entity, so it was setting all this info on the pod. Perhaps something was going awry there. Although modifying the original entity and turning it into the infection shouldn't hurt anything presumably... You just can't spawn multiple infection monsters that way.

If Shadow's fixes don't get your spawnlings searching for the player, let's have a look at the walk, stand, run etc animations.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby SamUK » Sat Dec 05, 2009 3:38 pm

Ahh, cheers guys! It's working.

Image

Note: The art is all wip. Something I made real quick to test it out. A decent sprite and texture should make all the difference.

Edit: Also, the muzzleflash has been replaced. I've just got an old build running on darkplaces.
Working on Solitude
SamUK
 
Posts: 101
Joined: Wed Dec 17, 2008 6:47 pm
Location: United Kingdom

Postby Wazat » Sun Dec 06, 2009 5:55 am

Hurray! Congrats, man.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby Teiman » Fri Jan 08, 2010 5:33 pm

man, I hate these evil fungus :-)
Teiman
 
Posts: 309
Joined: Sun Jun 03, 2007 9:39 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest