Page 1 of 1

function bool AlwaysKeep(Actor Other)

Posted: Sat Dec 16, 2017 3:51 pm
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;
}

Re: function bool AlwaysKeep(Actor Other)

Posted: Sat Dec 16, 2017 4:11 pm
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.

Re: function bool AlwaysKeep(Actor Other)

Posted: Sat Dec 16, 2017 4:27 pm
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.

Re: function bool AlwaysKeep(Actor Other)

Posted: Sat Dec 16, 2017 4:35 pm
by Gadavre
Thanks friends!

Re: function bool AlwaysKeep(Actor Other)

Posted: Sat Dec 16, 2017 5:37 pm
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.

Re: function bool AlwaysKeep(Actor Other)

Posted: Sat Dec 16, 2017 5:57 pm
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.