function bool AlwaysKeep(Actor Other)

Discussions about Coding and Scripting
Post Reply
User avatar
Gadavre
Skilled
Posts: 169
Joined: Sun Jan 18, 2015 7:55 am

function bool AlwaysKeep(Actor Other)

Post by Gadavre »

Hi. When should I use this function only? Can you give examples? This function seems to me useless.

Code: Select all

function bool AlwaysKeep(Actor Other)
{
	if ( NextMutator != None )
		return ( NextMutator.AlwaysKeep(Other) );
	return false;
}
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: function bool AlwaysKeep(Actor Other)

Post by JackGriffin »

You'll need a higher level coder to answer here but I can tell you from experience that AlwaysKeep is very powerful and is the key to fixing certain situations. However that power also makes it easy to mess things up and so you need to be very careful with using it. You can affect other mods in a very negative way quite easily even though you are accomplishing what you need to do within the framework of your own work.

I'm interested what Higor, Nog, or Nels has to say about it. I could stand to learn more myself.
So long, and thanks for all the fish
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: function bool AlwaysKeep(Actor Other)

Post by Barbie »

Just have a look at the comment at the source code in Mutator.uc:

Code: Select all

/* Force game to always keep this actor, even if other mutators want to get rid of it */
function bool AlwaysKeep(Actor Other)
...
Keeping this actor works because IsRelevant() and CheckReplacement() of other mutators are not called then. See also Wiki: Chain Of Events When Spawning Actors.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Gadavre
Skilled
Posts: 169
Joined: Sun Jan 18, 2015 7:55 am

Re: function bool AlwaysKeep(Actor Other)

Post by Gadavre »

Thanks friends!
nogardilaref
Masterful
Posts: 577
Joined: Tue Jun 20, 2017 1:00 pm
Personal rank: ⚋⚊⚌☰⚞⌖⚟☰⚌⚊⚋

Re: function bool AlwaysKeep(Actor Other)

Post by nogardilaref »

This function purpose is to simply avoid other mutators from replacing something you actually want to keep.

Let's say, for example, that you have a weapon mod which replaces every weapon in the game, but there's one particular weapon you don't want to be replaced at all, so you can build a mutator which tells the game that you want to keep that weapon, therefore the weapon mod won't be able to replace it.
Having that said, some weapon mods allow you to disable certain replacements from happening from their .ini files, thus you don't really need to implement this in those cases.

However, it's generally best to abstain from using this, given that if a mod wants to replace something, you should let it replace it unless you fully understand the full repercussions of it, or not use such mod at all.
Let's say a mutator actually needs to replace item X otherwise it won't work properly, and then you come along and use AlwaysKeep to prevent it, then you have pretty much broken the other mod.

On the other hand, let's say that a mod does replace item X by another, but this new item is broken in some sense, but not the rest, you can use AlwaysKeep to keep that item unreplaced avoiding the problem altogether, and still enjoy the rest of the mod.

In other words, it's the kind of function where you have to understand the implications towards other mods, and should only be used if you have a really good reason to.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: function bool AlwaysKeep(Actor Other)

Post by sektor2111 »

Just take a look at "KeepIt" mutator - that's a "live" demo about AlwaysKeep. Application ? A camper-sniper server which also uses Translocator, preventing this to be replaced with a Rifle but other weapons are turned into Rifle.
Post Reply