Spawn monsters on command

Discuss programming in the QuakeC language.
EMR
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Spawn monsters on command

Post by EMR »

Let's say I wanted to make a gun that spawned monsters. Would I just spawn a new entity, just like spawning a shot entity, then call the 'monster_bla' function for it? Where are those functions, and what is the syntax for calling them in that context?
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

Re: Spawn monsters on command

Post by hondobondo »

EMR wrote:Let's say I wanted to make a gun that spawned monsters. Would I just spawn a new entity, just like spawning a shot entity, then call the 'monster_bla' function for it? Where are those functions, and what is the syntax for calling them in that context?

Code: Select all

local entity new,temp;
new = spawn();
setorigin(new,SOMEORIGIN);
temp = self;
self = new;
monster_knight();
spawn_tfog (self.origin);
spawn_tdeath (self.origin,self);
new = self;
self = temp;
or something like that ;)
you can set the velocity beforehand like any projectile, but don't set avelocity. use the grenade launcher code. if you want to do that you can set the model for the grenade, and then just set the think to the monster_knight function

Code: Select all

self.think = monster_knight;
self.nextthink = time + 1;
i've tried stuff like that (not exactly) and it has worked. any way try it and tell me how it works
Sajt
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Post by Sajt »

You should also set the classname, like

self.classname = "monster_knight";
monster_knight();

Because otherwise the classname will be blank, and some gameplay behaviours are dependent on classname (e.g. sightsounds iirc)
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

To use Sajt's approach you'll need to make sure all required models were previously precached by your code, not the regular monster code. Actually, you'll need to change existing code to not try to precache any model or sound during game execution (this leads to a fatal error in most if not all engines). One easy way to do this is replacing precache_model and precache_sound builtin references in defs.h like this:

Code: Select all

// void (string s) precache_model = ...
void (string s) __precache_model = ...
And use some QuakeC wrappers to deal with:

Code: Select all

void (string s) precache_model = {
  if (time < 3) { // silently prevent precaches beyond the very initial seconds
    __precache_model (s);
  }
};
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

Post by hondobondo »

frag.machine wrote:To use Sajt's approach you'll need to make sure all required models were previously precached by your code, not the regular monster code. Actually, you'll need to change existing code to not try to precache any model or sound during game execution (this leads to a fatal error in most if not all engines). One easy way to do this is replacing precache_model and precache_sound builtin references in defs.h like this:

Code: Select all

// void (string s) precache_model = ...
void (string s) __precache_model = ...
And use some QuakeC wrappers to deal with:

Code: Select all

void (string s) precache_model = {
  if (time < 3) { // silently prevent precaches beyond the very initial seconds
    __precache_model (s);
  }
};
oh yeah. or you could precache in world.qc
EMR
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Post by EMR »

Thanks for the clip-the switching the 'self' around makes sense now.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

so i was wanting to do something similar... but what i want to do is call a traceline and at the end of that traceline spawn a monster...

thing is i still dont understand traceline at all... i was looking in defs but i think the only thing i know i have to use is trace_endpos


any idea where i can start? (i think the code above shows for something like the grenade launcher?)

maybe add some comments if its not too far out of the way of what each of the lines do? cause traceline confuses me pretty bad.
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

hope this helps..

Post by gnounc »

Start by looking in weapons.qc at void() W_FireAxe.

you'll see that the start vector used in the traceline
is based on your position:

Code: Select all

source = self.origin + '0 0 16';
and the vector used for the end position is as well
(its 64 units past the start vector along v_forward which is straight
ahead of the player)

after you've called a traceline things like trace_endpos (the
location where your line is interrupted ) and
trace_ent (the entity hit if any) are available for you to use
local to the function you called it in.

and as always keep this or the pdf version handy

http://www.gamers.org/dEngine/quake/Qc/qc-built.htm
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

hmm the thing is though is that the axe's hit point is so close to the player. idk maybe ill mess with it and see what i can do. im going to need to look at the axe and the grenade to see how spawning a new entitie through a weapon works. and the axe for my trace function.
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Post by gnounc »

If the line isnt long enough....uh make it longer.
its code, you can change it.
and its a perfect easy place to learn how to traceline.

change the 64 units beyond v_forward
(which is the end point of the line)
to something like 200, bam, done and done.
lth
Posts: 144
Joined: Thu Nov 11, 2004 1:15 pm

Post by lth »

Just using traceline can cause all sorts of trouble; you could spawn monsters into a wall, for instance. You need to take account of the monster bounding box size when you spawn them, and make sure it doesn't interact with the map or any other objects in the game. So trace a line, take the endpos, and then from there trace the size of the bounding box. I think there's a function lurking in the frikbot code to do this but I don't remember what it is offhand.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

sounds like something ill have to look into when refining what im working on. im going to attempt to make a sandbox mod for quake...
Mexicouger
Posts: 514
Joined: Sat May 01, 2010 10:12 pm
Contact:

Post by Mexicouger »

Hmm. Me and Jukki are going to try to create a sandbox like gamemode, and when a user creates an Object, save it to text file with the origin of that file, Like Frikbot did. Then have a command that let's you load the Objects.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

why would you need to save things? sorta like ingame mapping?
Mexicouger
Posts: 514
Joined: Sat May 01, 2010 10:12 pm
Contact:

Post by Mexicouger »

ceriux wrote:why would you need to save things? sorta like ingame mapping?
It is based of Halo Forge. I can't directly save a .bsp file(At least Not without doing lots of code). So That is the best way that I can think. Put an object at an origin, and load it up.
Post Reply