Having trouble spawning entities!
Moderator: InsideQC Admins
3 posts
• Page 1 of 1
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.
And how do I keep the model from bleeding when hit?
Gimme some help please.
- Code: Select all
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;
}
- worldspawn
- Posts: 27
- Joined: Tue Dec 02, 2008 11:44 pm
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:
change the SpawnBlood function or make your own that instead of:
does:
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).
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: Select all
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: Select all
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: Select all
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.
- Chris
- Posts: 79
- Joined: Sat Aug 05, 2006 5:31 am
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
