• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Weapon Ownership

xtsnet

Active member
Jun 23, 2012
42
0
Hi, Newbie here. I;m trying to get information on how I'd go about creating a MUT that assigns an ownership value/property to weapons when they are purchased at the trader. The purpose is to make it so that if a player buys more than 1 weapon (Firebug for instance buys multiple Flame Throwers) and then throws those weaps off to the side while he buys another, a different player cant come along pick it up and sell it .

So the base design would be:

(PSEUDO CODE)

if(!strcmp(weapon->ownername, player->name))
{
allow the weap to be picked up
}else{
msg("SORRY THIS IS NOT YOUR WEAPON");
}

Something along those lines with in, Id assume, the pickup class somewhere

Never worked with UnrealScript b4 - but any suggestions would be appreciated - just looking for a starting point.

Been through the Mut tutorials and it all makes sense - and have compiled stuff - but lost as far as the code structure and code references


:D TIA
 
1. Open KF editor. Go to Actor Classes and select 'File -> Export All Scripts' to update source codes ofexisting packages.
2. Get the UnCodeX program. It shows the entire class tree of UnrealScript and can help you a lot.

Now about your problem:
Weapon that player holds in his inventory and the one which is dropped on the ground are completely different classes.
a) Take a look on "DropFrom()" function inside KFWeapon class. It is executed when player drops a gun. "Instigator" variable points on the current weapon holder. Store it somewhere.
b) Then check the "CheckCanCarry" function inside the KFWeaponPickup class. It receives KFHumanPawn argument, which can be compared with previously stored Instigator.

Task is very easy. The problem is how to implement it inside a mutator. If you override KFWeapon and KFWeaponPickup classes, you will be supposed to rewrite all weapon and their pickup classes to be derived from your new classes. Then you'll be supposed to override any classes that points to them, e.g. perks.
 
Upvote 0
The only workaround to make a mutator without modifing the weapons classes is:


a. use OverridePickupQuery, the make a list with the ownership of the picked up weapon.
b. in trader time, the player must
b1. buy a weapon
b2. trown, pickup and re trwon

In that simpel way we can make a mutator to handle the ownership of a weapon, is a very ugly way but as i say (maybe im grong!) is the only way to doit without change the weapon clases.

If this has upfingers from more users i will code for the community as soon i have a litle time.
 
Upvote 0
The only workaround to make a mutator without modifing the weapons classes is:


a. use OverridePickupQuery, the make a list with the ownership of the picked up weapon.
b. in trader time, the player must
b1. buy a weapon
b2. trown, pickup and re trwon

In that simpel way we can make a mutator to handle the ownership of a weapon, is a very ugly way but as i say (maybe im grong!) is the only way to doit without change the weapon clases.

If this has upfingers from more users i will code for the community as soon i have a litle time.
It's a very good idea ,but redroping few time? In killing floor are somelarge maps like mountain pass and when you have to go from A to B 40 seconds or more and you will not have much time to re-drop. Maybe better to ovveride not every weapons ? Better the stongest ones?
 
Upvote 0
Generally its the primary weapons that are taken and sold

No one really gives a crap a machete or 9mm - But should fit into weapons class so that all weapons have an associated owner to it, Of course when someone dies , the owner becomes WORLD which would release it so that anyone can pick it up, and of course any spawned weaps would also have that ownership assigned to it
 
Upvote 0
So, with this approach a player can't give a weapon to other...

Ok, in resumen:

** cases with ownership **
case1: a weapon is purchased from trader, the weapon must have a custom pickup class that set the owership to the player who bought.

Setings will be for primary weapons: xbow, scarm, law, flames,....?

case2: a weapon is trowed by a player

case3: a player spawns with certain weapon

** cases without ownership **

caseA: a map spawns a weapon
caseB: a player dies/leaves the game



TO clarify: For caseB can be confused, maybe the player if die can retain the ownership, but if he leave the server the ownership dissapear.


What do you think?
 
Upvote 0
I would simply do this using mutator and gamerules combinations, something along these lines:
Mutator:
Code:
class MyMutator extends Mutator;

var array<WeaponPickup> Pending;
var MyRules Rules;

function PostBeginPlay()
{
	if( Rules==None )
		Rules = Spawn(Class'MyRules');
}
function bool CheckReplacement(Actor Other, out byte bSuperRelevant)
{
	if( WeaponPickup(Other)!=None && !Level.Game.bWaitingToStartMatch )
	{
		Pending[Pending.Length] = WeaponPickup(Other);
		SetTimer(0.01,false);
	}
	return true;
}
function Timer()
{
	local int i;

	for( i=(Pending.Length-1); i>=0; --i )
	{
		if( Pending[i]!=None && Pending[i].Instigator!=None && PlayerController(Pending[i].Instigator.Controller)!=None )
			Rules.AddPickup(Pending[i],Pending[i].Instigator.Controller);
	}
	Pending.Length = 0;
}
GameRules:
Code:
class MyRules extends GameRules;

struct FOwnership
{
	var Controller Owner;
	var WeaponPickup P;
};
var array<FOwnership> OwnedPickups;
var transient string LastOwnerName;

function PostBeginPlay()
{
	NextGameRules = Level.Game.GameRulesModifiers;
	if( Level.Game.GameRulesModifiers==None )
		Level.Game.GameRulesModifiers = Self;
}
final function bool CanTakeItem( Controller P, Pickup W, bool bDeleteItem )
{
	local int i;

	for( i=(OwnedPickups.Length-1); i>=0; --i )
	{
		if( OwnedPickups[i].Owner==None || OwnedPickups[i].P==None )
			OwnedPickups.Remove(i,1); // Purge old information
		else if( OwnedPickups[i].P==W )
		{
			if( OwnedPickups[i].Owner==P )
			{
				if( bDeleteItem )
					OwnedPickups.Remove(i,1);
				return true;
			}
			LastOwnerName = OwnedPickups[i].Owner.PlayerReplicationInfo.PlayerName;
			return false;
		}
	}
	return true;
}
final function bool HasItemClass( Actor Other, class<Inventory> IC )
{
	local Inventory I;

	for( I=Other.Inventory; I!=None; I=I.Inventory )
		if( I.Class==IC )
			return true;
	return false;
}
function bool OverridePickupQuery(Pawn Other, Pickup item, out byte bAllowPickup)
{
	if( WeaponPickup(item)!=None && Other.Controller!=None )
	{
		bAllowPickup = 0;
		if( !HasItemClass(Other,item.InventoryType) )
		{
			if( !CanTakeItem(Other.Controller,P,true) )
				Other.ClientMessage("This weapon is owned by"@LastOwnerName);
			else return false;
		}
		else if( CanTakeItem(Other.Controller,P,false) )
			return false;
		return true;
	}
	if( NextGameRules!=None && NextGameRules.OverridePickupQuery(Other, item, bAllowPickup) )
		return true;
	return false;
}
final function AddPickup( WeaponPickup WP, Controller Other )
{
	local int i;

	for( i=(OwnedPickups.Length-1); i>=0; --i )
	{
		if( OwnedPickups[i].Owner==None || OwnedPickups[i].P==None )
			OwnedPickups.Remove(i,1); // Purge old information
	}

	OwnedPickups.Insert(0,1);
	OwnedPickups[0].P = WP;
	OwnedPickups[0].Owner = Other;
}
I have not tested if this even works (or even compiles).
 
Upvote 0
Ok, so... the only way to setup the ownership is rewriting the pickups OR making my the ugly workaround?

Some light in that particular point? remember, the goal is to set the ownership without writing every weapon pickup classs
Re-look at Marco's code shown lol. It seems to be everything you need as it decides on how the pickup is to be used and who owns it. Pretty nice work Marco.
 
Upvote 0
I finally found the time to start working on this - I have compiled it and loaded it.

It doesnt work as of yet, but its a good base to start from though - I need to add some debugging messages through the code to determine where it is broken

I did see what seems to be a typo - just checking to see if it really was:


if( !CanTakeItem(Other.Controller,P,true) )

under the function

OverridePickupQuery(Pawn Other, Pickup item, out byte bAllowPickup)

================== I ASSUME this is what you meant

if( !CanTakeItem(Other.Controller,Item,true) )
 
Upvote 0