Forum

Spawn monsters on command

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Spawn monsters on command

Postby EMR » Tue Dec 14, 2010 2:39 am

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?
EMR
 
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Re: Spawn monsters on command

Postby hondobondo » Tue Dec 14, 2010 4:38 am

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
hondobondo
 
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am

Postby Sajt » Tue Dec 14, 2010 7:03 am

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.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby frag.machine » Tue Dec 14, 2010 11:14 am

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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby hondobondo » Tue Dec 14, 2010 4:47 pm

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
hondobondo
 
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am

Postby EMR » Tue Dec 21, 2010 3:28 pm

Thanks for the clip-the switching the 'self' around makes sense now.
EMR
 
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Postby ceriux » Wed Dec 29, 2010 9:34 am

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.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

hope this helps..

Postby gnounc » Wed Dec 29, 2010 10:14 am

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
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby ceriux » Wed Dec 29, 2010 7:23 pm

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.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby gnounc » Wed Dec 29, 2010 10:04 pm

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.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby lth » Wed Dec 29, 2010 10:23 pm

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.
User avatar
lth
 
Posts: 144
Joined: Thu Nov 11, 2004 1:15 pm

Postby ceriux » Thu Dec 30, 2010 12:42 am

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...
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby Mexicouger » Thu Dec 30, 2010 1:57 am

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.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby ceriux » Thu Dec 30, 2010 3:45 am

why would you need to save things? sorta like ingame mapping?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby Mexicouger » Thu Dec 30, 2010 4:34 am

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.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest