Spawn entities in real-time

Discuss programming in the QuakeC language.
Post Reply
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Spawn entities in real-time

Post by JasonX »

Without a modified engine, is it possible to spawn entities in real-time? I'm working on a small TD mod for Q1, but i'm curious if i'm able to spawn entities (like zombies, or dogs) to attack my enemies, as well boxes and other models (to block the way).
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Spawn entities in real-time

Post by ceriux »

i did it. i think you just spawn a spawn entity at the position you want but only spawn the monster according to some variable.
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Spawn entities in real-time

Post by leileilol »

You can spawn entities in real-time, it's just the precaching you can't do in real-time - because it's not really precaching if you do it post-load. So you'd have to make the precaching bit in a conditional and precache the relevant monster stuff in another init funciton.
i should not be here
ajay
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Re: Spawn entities in real-time

Post by ajay »

JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Spawn entities in real-time

Post by JasonX »

Alright, thank you guys! Another quick question: with QC, can i grab the player view point, so i can spawn an entity where the player is looking at? Like a bullet?
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Spawn entities in real-time

Post by mankrip »

JasonX wrote:Alright, thank you guys! Another quick question: with QC, can i grab the player view point, so i can spawn an entity where the player is looking at? Like a bullet?
Yes. Do a traceline, and set the new entity origin as trace_endpos:

Code: Select all

local entity myentity;
local vector org;
org = self.origin + '0 0 22';
// self must be the player
makevectors	(self.v_angle);	// calculate forward angle for velocity
traceline (org, org + v_forward*2000, TRUE, self);
myentity = spawn ();
// set model, solid and everything else before
setorigin (myentity, trace_endpos);
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Spawn entities in real-time

Post by JasonX »

mankrip wrote:
JasonX wrote:Alright, thank you guys! Another quick question: with QC, can i grab the player view point, so i can spawn an entity where the player is looking at? Like a bullet?
Yes. Do a traceline, and set the new entity origin as trace_endpos:

Code: Select all

local entity myentity;
local vector org;
org = self.origin + '0 0 22';
// self must be the player
makevectors	(self.v_angle);	// calculate forward angle for velocity
traceline (org, org + v_forward*2000, TRUE, self);
myentity = spawn ();
// set model, solid and everything else before
setorigin (myentity, trace_endpos);
Wow! It works perfectly. Thank you! :mrgreen:
Post Reply