UE1 - UT Keeping Weapons Despite Death

  • 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.

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
I am trying to make a mutator that takes affect after a death. Once a person dies, all the inventory (weapons, powerups, ammo and everything else) that they had the instant before death comes back to them upon respawning. I really haven't a clue how to even start this, but I guess it would start out with a scorekill.

Code:
function ScoreKill(Pawn Killer, Pawn Other)
{

//need to keep other.inventory

}

Yes I know that is barely anything to go on, but I haven't the slightest idea what kind of functions this would require.
 

War_Master

Member
May 27, 2005
702
0
16
You will have to use either the PreventDeath() or the ScoreKill() functions to save each player's InventoryList - I recommend using PreventDeath since ScoreKill is not returned to its parent mutator in many mutators specially custom announcers. Then, whatever InventoryList for the specific player you will need to give it back with the ModifyPlayer() function.

This has already been done before but I cant remember the mod that did it at all. But if it helps, you can check out the Relic of Redemption or the FreezeGun which save the player's InventoryList items in different ways in order to give it back to the player.
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
Maybe the Pinata mod can offer some clues. It drops a player's inventory when they get fragged.
 

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
This didn't work for some reason, but this is my theory:


Code:
function bool PreventDeath (Pawn Killed, pawn Killer, class<DamageType> damageType, vector HitLocation)  
{

local PlayerStart PS;


killed.health = 100;
killed.SetLocation(PS.Location);

return true;

}

something like this should be able to help, but I think I am doing it a little bit wrong.
 

War_Master

Member
May 27, 2005
702
0
16
The way this have to be done is pretty complicated to me... I'm not that advanced with UScript. But, I know exactly how the theory works and I can't write the code to save the data and then give it back at respawn.

To help you out I directed you to what functions in a mutator can be used to handle such thing. This also will be a very tricky way to save inventory for the reason that Items have a Charge as well as other variables which differs on some of them. Also, the weapons have to be stored as well as their ammo which might be easier to save than a pick-up Item. In other words, you will have to specify Item by Item and their variables to restore the same value when the player was killed. Otherwise, it will be best to just give the same Item Class and not worry about their variables so they are given with their default values.

The PrevenDeath() function is called in a Pawn's Died() function so that a mutator can easily handle code through a mutator to do some cool stuff like spawning a Zombie or an explosion effect when a player dies. It should be the last function called in a player where you can save the InventoryList data before its lost. Then, you can give back the Inventory items to the player when it respawns using the ModifyPlayer() function.


under Pawn:

Code:
function Died(pawn Killer, name damageType, vector HitLocation)
{
	local pawn OtherPawn;
	local actor A;

	// mutator hook to prevent deaths
	// WARNING - don't prevent bot suicides - they suicide when really needed
[COLOR="Red"]	if ( Level.Game.BaseMutator.PreventDeath(self, Killer, damageType, HitLocation) )
	{
		Health = max(Health, 1); //mutator should set this higher
		return;
	}[/COLOR]
	if ( bDeleteMe )
		return; //already destroyed
	Health = Min(0, Health);
	for ( OtherPawn=Level.PawnList; OtherPawn!=None; OtherPawn=OtherPawn.nextPawn )
		OtherPawn.Killed(Killer, self, damageType);
	if ( CarriedDecoration != None )
		DropDecoration();
	level.game.Killed(Killer, self, damageType);
	//log(class$" dying");
	if( Event != '' )
		foreach AllActors( class 'Actor', A, Event )
			A.Trigger( Self, Killer );
	Level.Game.DiscardInventory(self);
	Velocity.Z *= 1.3;
	if ( Gibbed(damageType) )
	{
		SpawnGibbedCarcass();
		if ( bIsPlayer )
			HidePlayer();
		else
			Destroy();
	}
	PlayDying(DamageType, HitLocation);
	if ( Level.Game.bGameEnded )
		return;
	if ( RemoteRole == ROLE_AutonomousProxy )
		ClientDying(DamageType, HitLocation);
	GotoState('Dying');
}

under Mutator:

Code:
function bool PreventDeath(Pawn Killed, Pawn Killer, name damageType, vector HitLocation)
{
	if ( NextMutator != None )
		return NextMutator.PreventDeath(Killed,Killer, damageType,HitLocation);
	return false;
}
 

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
Okay, how would I go about saving the inventory list?

As for variables, for the project I am using this for, ammo and charge should be restored to full. I think that will make it a bit easier.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
Saving the Inventory list could be as simple as disconnecting the entire linked list from the Pawn and storing a reference to the first element somewhere else until the player respawned. That event can be detected with ModifyPlayer(). All you need to do then is give the respawned player the inventory list back. Note however, that players already spawn with some inventory items, so you'll have to find a way to deal with any duplicates.
 

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
Saving the Inventory list could be as simple as disconnecting the entire linked list from the Pawn and storing a reference to the first element somewhere else until the player respawned..


We have very, very different definitions of "simple".

I am really not a great coder, and the closest I have come to understanding this was when I used my code:

Code:
function bool PreventDeath (Pawn Killed, pawn Killer, class<DamageType> damageType, vector HitLocation)  
{

local PlayerStart PS;


killed.health = 100;
killed.SetLocation(PS.Location);

return true;

}

Wouldn't it be easy just to move the player out of harm's way just before death? They would keep all their current inventory and that would be perfect for the project I am working on.

I know there are problems with it, but it is the closest to a functional code I have so far. Can anyone here tell me what I have done wrong? Will I need to include a function to find a playerstart?

I did some research. I found a forum that said that you must return true for the Prevent Death function to prevent death. Is my Return True; in the right place?

Also, it is fine if this prevents scoring, I already have that figured out.
 
Last edited:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
If I understand things correctly what Wormbo means is that you it would be possible to separate the inventory from a player without having it erased. You'd do this by storing the reference to the first item in variable of the same type (in Java and some other OO languages an object stays in memory as long as something is referring to it) and then set the owner to none or something. You could then relink the list with a player after he's respawned.

P.S: Does anyone have an idea on what DiscardInventory does in DeathMatchPlus (see War_Master's last post) ?
 

War_Master

Member
May 27, 2005
702
0
16
Ok, its been a long time since I read the Inventory's script. If I'm not mistaking, Inventories get destroyed when a certain function in the Pawn or gametype is called. So, what he has to do (I repeat for the third time), is save the InventoryList of the player that is about to die which can be checked and saved using the PreventDeath() function and then have the mutator restore it using the ModifyPlayer() function and blank it out again once the items are given.

Check the OldSkool mod. I remember it giving inventory back to players when they respawn or travel to the next map.

Sorry if you dont know much UScript. But, I'm not going to do it for you at all. You will have to figure this out and write the code by yourself if you actually want to learn how. Otherwise, you're just pretending to seek help about coding when you're actually trying to get someone else to do it for you. By the questions you're making and how lost you really are, this is what I see of your purposes. I already got you in the right track and told you what to look at to get you started if you had a clue on what you were doing.
 
Last edited:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
Oldskool would be a good start. If you need the source, Rajada, I can send it over.
 
Last edited:

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
No, actually I have the OldSkool mod, and that is a good idea.

Ya know War_Master, I really don't appriciate being demeaned on a forum over something so trivial. I simply asked if anyone knew what I could do to improve MY code because it seemed to me to be a simpler process for the project I am attempting.

I may not be a master with Unrealscript, but i'm not an idiot, and I would appriciate it if I was treated with a little more respect. If you do not like that I did not attempt to use your method, then you do not have to post anything here. That would not be nearly as confrontational.
 
Last edited:
Apr 11, 2006
738
0
16
UT2004 RPG has an ability ("Denial" aka NoWeaponDrop) which will store all of your weapons on death and return them to you. Not sure if you have UT2004 and will be willing to check that out. If not I can post the relevant classes for you. Not sure what the differences will be between UT vs. UT2004 in this respect but you should at least be able to tell the approach used.
 

gopostal

Active Member
Jan 19, 2006
848
47
28
Denail caused all sorts of problems on my 2K4 servers though. Lots of server crashes and resets. You could flood the server by suiciding and the weapons would pile up before being destroyed and it eventually would crash the server. I know a couple of the larger RPG servers reworked denial so it didn't do this, but I don't know what was altered.

OK, now to UT99 and my question: I hate to dig up an older thread like this, but I also have a somewhat similar question. I'm trying to get pinata to work with monsterhunt, but it will not affect the players at all. Is it because of this section?:
Code:
function ScoreKill(Pawn Killer, Pawn Other)
{
	local actor dropped;
	local float speed;
	local float temp;
	local int charge;
	local int finalcount;
	local int timecharge;
	local bool firstpass;
	local vector X,Y,Z;

I'm assuming that because the player is being killed by a monster and not another player, this prevents the pinata from functioning. May I get a nudge in a direction to go to solve this? I tried using the same calls that the monsterhunt mod uses to tick off lives on death but no go.

Thank you for any input you might have.
 

gopostal

Active Member
Jan 19, 2006
848
47
28
OK here's an update. Upon further testing the mod will in fact work, but only if you suicide, but not if killed by any monsters. I think the problem lies in the parent function being:

function ScoreKill(Pawn Killer, Pawn Other)

is wrong. When a monster kills you, scorekill is not called (I think). I tried function Death and function Killed but neither worked at all. Got any ideas as to a function to tie into?

Oh, I also tried adding a if statement like this:
if(Killer != None && Killer.bIsPlayer == false)

but it still didn't work, which isn't surprising if the parent function is not called anyway.