View previous topic :: View next topic |
Author |
Message |
worldspawn
Joined: 02 Dec 2008 Posts: 26
|
Posted: Mon May 25, 2009 8:51 pm Post subject: Having trouble spawning entities! |
|
|
The spawned entity called in building_die disappears after just a second. But I want it to remain there permanently.
And how do I keep the model from bleeding when hit?
Gimme some help please.
Code: | void() building_die =
{
local entity hitbuilding;
sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
BecomeExplosion ();
hitbuilding = spawn ();
hitbuilding.solid = SOLID_BSP;
setmodel (self, "progs/building_hit.mdl");
}
void() misc_building =
{
self.solid = SOLID_BSP;
precache_model ("progs/building_normal.mdl");
setmodel (self, "progs/building_normal.mdl");
precache_model ("progs/building_hit.mdl");
precache_sound ("weapons/r_exp3.wav");
self.health = 20;
self.th_die = building_die;
self.takedamage = DAMAGE_AIM;
} |
|
|
Back to top |
|
 |
Chris
Joined: 05 Aug 2006 Posts: 78
|
Posted: Mon May 25, 2009 10:10 pm Post subject: |
|
|
local entity newthing, oldself;
oldself = self; // maintain reference to previous self (the misc_building thing)
newthing = spawn();
setorigin (newthing, self.origin); // put this newly spawned entity at the misc_building's origin
self = newthing; // set self to the new entity spawned so when you call the explosion stuff it happens to him
BecomeExplosion(); // this I think acts on the 'self' in that it set's it's model to a sprite and runs some frame animation thing then removes itself
self = oldself; // reset self to the previous reference of the misc_building
self.health = 20; // in example this would set your original misc_building's health back to 20 since the self reference is now returned to what it was at the beginning of the function, theres other ways of doing this like using th_pain instead of th_die or making a proper explosion effect that spawns an entity not modifying the entity that fills in the self reference, but oh well, I'll work within the confines of what looks like progs 1.06 projectile explosion code (sigh)
setmodel (self, "progs/building_hit.mdl"); // arbitrary placement of the setmodel I just snagged from your code
sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM); // more arbitrary audio placement, really should make your own modular explosion function that spawns an entity and does all this for you not messing with self pointer, is just ugly in qc (my opinion).
FYI, I did not test this code so take it as pseudo code, I hope it helps
As for the bleeding unfortunately it is not handled by the entity hit to great extent beyond determining whether the entity can take damage. This is handled in the weapon impact code, most likely in your weapons.qc there is an area for example the shotgun that comes down to the TraceAttack function:
Code: |
void(float damage, vector dir) TraceAttack =
{
local vector vel, org;
vel = normalize(dir + v_up*crandom() + v_right*crandom());
vel = vel + 2*trace_plane_normal;
vel = vel * 200;
org = trace_endpos - dir*4;
if (trace_ent.takedamage)
{
SpawnBlood (org, vel*0.2, damage);
AddMultiDamage (trace_ent, damage);
}
else
{
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_GUNSHOT);
WriteCoord (MSG_BROADCAST, org_x);
WriteCoord (MSG_BROADCAST, org_y);
WriteCoord (MSG_BROADCAST, org_z);
}
};
|
change the SpawnBlood function or make your own that instead of:
Code: |
TraceAttack CALL:
SpawnBlood (org, vel*0.2, damage);
function:
void(vector org, vector vel, float damage) SpawnBlood =
{
particle (org, vel*0.1, 73, damage*2);
};
|
does:
Code: |
TraceAttack CALL:
SpawnBloodIfIWanna (trace_ent, vel*0.2, damage);
Function:
void(entity thingy, vector vel, float damage) SpawnBloodIfIWanna =
{
if (thingy.classname != "misc_building")
{
particle (thingy.origin, vel*0.1, 73, damage*2);
}
else
{
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_GUNSHOT);
WriteCoord (MSG_BROADCAST, thingy.origin_x);
WriteCoord (MSG_BROADCAST, thingy.origin_y);
WriteCoord (MSG_BROADCAST, thingy.origin_z);
}
};
|
To do a proper determination of whether a building should "bleed" or not comes down to an architectural decision if you have multiple different kinds of units with different effects when they get impacts (buildings versus people versus vehicles versus bowls of jello) you'll want to be checking against some member variable or flag set on each said entity that would be hit on initialization. Not reliant on the weapon which really shouldn't be determining whether or not the entity hit should bleed in this case (yet again my opinion).
Last edited by Chris on Mon May 25, 2009 10:37 pm; edited 4 times in total |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Mon May 25, 2009 10:23 pm Post subject: |
|
|
Chris has it right as far as I can see. _________________ Apathy Now! |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2004 phpBB Group
|