Noob question. (delayed explosion effect)

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

nickelplate

New Member
Jun 20, 2003
24
0
0
Montréal, Canada
Visit site
Noob question.

I'm getting started with UnrealScript, and I've been experimenting with some simple mutators. I want to write one that spawns an explosion when a kill is scored where the dead corpse lays. How do I go about timing the spawning? For example how do I spawn the explosion three seconds after the kill has occured?
 

nickelplate

New Member
Jun 20, 2003
24
0
0
Montréal, Canada
Visit site
Well,

I took the apprach Solid Snake suggested above, but there probably is something I'm doing wrong. I subclassed the class GameRules, and created a new class in which I overrided the function ScoreKill(). I'm doing this to store the location of the dead player. Then I set the timer to 3 seconds, and I in Timer() call a function called SummonDeathExplosion(), which spawns an explosion where the dead corpse lays. The spawning code is almost the same as in the Grenade class. I then created a mutator in which I set the level game rules to the new game rules. When I test my code, the explosion is spawned as specified by the log, but I don't see it, and the near player takes no damage. Can anyone help? I'm new here and I really don't want to go against your post habits. I read some of the posts here and I didn't see any that could resolve my problem. I apologize in advance if my question is too "simple".

Cheers, nickelplate.
 
Last edited:

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
You won't get some of our habits as long as you tried, that is alwasy what I am getting on about. WHy come here and post a random question and then expect an answer and then get huffy when you dont get one. Anyway,

Hmmm, well when you do a ScoreKill function, instead of making the GameRules class to do the explosion, try to get the GamesRules to actually spawn a grenade there. That way the Timer wont get confused since they will be independent of each other.

ie, spawn(class'XWeapons.Grenade',,,DeadCorpseLocation, DeadCorpseRotation);

Something along those lines.
 

Dark[NSF]

Northwest Secessionalist Forces
Random Encounters

[SAS]Solid Snake said:
You won't get some of our habits as long as you tried, that is alwasy what I am getting on about. WHy come here and post a random question and then expect an answer and then get huffy when you dont get one. Anyway,

Hmmm, well when you do a ScoreKill function, instead of making the GameRules class to do the explosion, try to get the GamesRules to actually spawn a grenade there. That way the Timer wont get confused since they will be independent of each other.

ie, spawn(class'XWeapons.Grenade',,,DeadCorpseLocation, DeadCorpseRotation);

Something along those lines.


What would be even better would be a random spawn, something along the lines of ahealth pickup or armour pickup... Then for some fun add in a grenade :D

Just a crazy idea :p
 

nickelplate

New Member
Jun 20, 2003
24
0
0
Montréal, Canada
Visit site
It is still not working.

I've tried something simpler, not involving a timer. I just spawn a grenade when a kill is scored. Here is my code.

Code:
//=====================================================
// DeathGameRules - Change the game rules for the death mutator.
//=====================================================
class DeathGameRules extends GameRules;

function ScoreKill(Controller Killer, Controller Killed)
{
	// Spawn a grenade where the dead corpse lays
	if ((Killed != None) && (Killer != Killed) && (Killer != None))
	{
		Spawn(class'XWeapons.Grenade', , , Killed.Location, Killed.Rotation);
	}

	// Pass the function down the game rules chain
	Super.ScoreKill(Killer, Killed);
}

My mutator goes like this:

Code:
//=====================================================
// MutDeath - Makes a bomb go off where a dead corpse lays.
//=====================================================
class MutDeath extends Mutator;

function PostBeginPlay()
{
	local DeathGameRules G;

	Super.PostBeginPlay();

	G = Spawn(class'DeathGameRules');
	
	if (Level.Game.GameRulesModifiers == None)
	{
		Level.Game.GameRulesModifiers = G;
	}
	else
	{
		Level.Game.GameRulesModifiers.AddGameRules(G);
	}

	Destroy();
}


defaultproperties
{
	FriendlyName = "Death Mutator"
	Description = "A bomb goes off where a dead corpse lays."
}

Sorry to cut and paste like that but it was the quickest and least confusing way.

Strangely enough, the mutator doesn't change anything to the game. The grenade is spawned, but I don't see it, it doesn't explode and the near player doesn't take any damage. What am I doing wrong?

Cheers, nickelplate.
 

nickelplate

New Member
Jun 20, 2003
24
0
0
Montréal, Canada
Visit site
Whatever I spawn in the ScoreKill() function doesn't appear in the game. I know it has been spawned because the log says so, but I never see it.

Anyone else ever encountered this kind of problem?

Cheers.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
A player's Controller is not neccessarily at the same location as the player's visible representation in the game, i.e. the Pawn. You spawn the grenade at the controllers's location which could be far away from the pawn, so you don't see it.
 

Slaught

New Member
Aug 19, 2003
1
0
0
41
UK
www.vault13.co.uk
So would the correct code would be:

Code:
//=====================================================
// DeathGameRules - Change the game rules for the death mutator.
//=====================================================
class DeathGameRules extends GameRules;

function ScoreKill(Controller Killer, Controller Killed)
{
	// Spawn a grenade where the dead corpse lays
	if ((Killed != None) && (Killer != Killed) && (Killer != None))
	{
		Spawn(class'XWeapons.Grenade', , , Killed.Pawn.Location, Killed.Pawn.Rotation);
	}

	// Pass the function down the game rules chain
	Super.ScoreKill(Killer, Killed);
}

Correct? And if so, why the heck does it still not work for me, i have the exact same setup, and was just trying to figure out how to spawn an explosion when i came accross this, which i figured was lucky, but it still wont work for me, so am i doing something wrong elsewhere still you reckon?
 

nickelplate

New Member
Jun 20, 2003
24
0
0
Montréal, Canada
Visit site
I've finally found a way to do it.

I think my original code didn't work because the spawned grenade would bounce off the ground after being spawned, making it harder to notice it. Maybe someone can comment on this. Anyway, I subclassed the original Grenade, to create a deadly one. The rest is pretty much the same as before. Here's my code.

Code:
//=============================================================================
// DeathBomb - A deadly version of the original UT2003 grenade.
//=============================================================================

class DeathBomb extends Grenade;


simulated function BlowUp(vector HitLocation)
{
	HurtRadius(Damage, DamageRadius, MyDamageType, MomentumTransfer, Location );
	if (Role == ROLE_Authority)
	{
		MakeNoise(2.0);
	}
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
	PlaySound(sound'WeaponSounds.BExplosion3',,2.5*TransientSoundVolume);
    if ( EffectIsRelevant(Location,false) )
    {
    	Spawn(class'RocketExplosion',,,HitLocation + HitNormal*16,rotator(HitNormal));
        Spawn(class'ExplosionCrap',,, HitLocation, rotator(HitNormal));
	}

	BlowUp(HitLocation);
}

defaultproperties
{
     Damage=50.000000
     DamageRadius=800.000000
     MomentumTransfer=75000.000000
     MyDamageType=Class'XWeapons.DamTypeAssaultGrenade'
     bBounce=False
}


Code:
//=============================================================================
// DeathGameRules - Modifies the game rules for using the death mutator
//=============================================================================
class DeathGameRules extends GameRules;

function ScoreKill(Controller Killer, Controller Killed)
{
	local DeathBomb spawnedBomb;

	// Spawn a death bomb where the dead corpse lays
	if ((Killed != None) && (Killer != Killed) && (Killer != None))
	{
		spawnedBomb = Spawn(class'MyPackage.DeathBomb', , ,
							Killed.Pawn.Location, Killed.Pawn.Rotation);
		
		if (spawnedBomb != None)
		{
			spawnedBomb.Explode(Killed.Pawn.Location, vector(Killed.Pawn.Rotation));
		}

	}

	// Pass the function down the game rules chain
	Super.ScoreKill(Killer, Killed);
}

It works fine. Maybe it is not the best way to go at it, so any comment on this code would be appreciated.

Cheers.