Is there any way to change the mutator settings when changing the map/game?

Search, find and discuss about Mutators!
User avatar
f7r
Average
Posts: 41
Joined: Mon Oct 19, 2020 6:53 pm

Is there any way to change the mutator settings when changing the map/game?

Post by f7r » Fri May 21, 2021 7:33 pm

Example for StuffSwapper I want different setting for different game. Not only StuffSwapper, I am interested in any mutator. In principle, is it possible? I know only one way - clone mutators (subclass/copyclass without change). But I do not want to produce too redundant entity, since the individual specimen is needed for each individual setting. Surely this question has already arisen before, but i don't know how to search the answer.
Last edited by f7r on Fri May 21, 2021 9:10 pm, edited 1 time in total.

User avatar
OjitroC
Godlike
Posts: 2480
Joined: Sat Sep 12, 2015 8:46 pm

Re: Is there any way to change the mutator settings when changing the map/game?

Post by OjitroC » Fri May 21, 2021 8:06 pm

f7r wrote:
Fri May 21, 2021 7:33 pm
Example for StuffSwaper I want different setting for different game. Not only StuffSwaper, I am interested in any mutator. In principle, is it possible? I know only one way - clone mutators (subclass/copyclass without change). But I do not want to produce too redundant entity, since the individual specimen is needed for each individual setting. Surely this question has already arisen before, but i don't know how to search the answer.
Using StuffSwapper as an example, which/what settings do you want to change for different game(types?)? It's not totally clear what you want to achieve.

ProAsm
Skilled
Posts: 191
Joined: Sun Sep 29, 2013 7:12 am

Re: Is there any way to change the mutator settings when changing the map/game?

Post by ProAsm » Fri May 21, 2021 8:24 pm

Yes it is possible but very involved.
Firstly you create a small mutator that has all the settings and classes of whatever other mutator's settings you want to change.
Lets say your mod is called MySetter1.u and you want to change settings in StuffSwapper.u
Now when you set the EditPackages= in your UT.ini file for your mod, you add all the other mutator.u mod names as well.
So you have:
[Editor.EditorEngine]
EditPackages=StuffSwapper
EditPackages=MySetter1

Now when you compile your MySetter1.u it will add all the classnames for StuffSwapper into your mod so in your mod you can now call for instance:
StuffSwapperConfigsPage.default.CurrentConfig=3
You may need to use a DynamicLoadObject to do this as I cannot remember any more :)
Something like:

Code: Select all

    local StuffSwapper SW;
    
    SW = class<Mutator>(DynamicLoadObject("StuffSwapper", class'Class'));
    SW.StuffSwapperConfigsPage.default.CurrentConfig=3
Like I say, very involved, maybe one of the boffins here can shine some better light on the subject :)

User avatar
f7r
Average
Posts: 41
Joined: Mon Oct 19, 2020 6:53 pm

Re: Is there any way to change the mutator settings when changing the map/game?

Post by f7r » Fri May 21, 2021 10:07 pm

OjitroC wrote:
Fri May 21, 2021 8:06 pm
Using StuffSwapper as an example, which/what settings do you want to change for different game(types?)? It's not totally clear what you want to achieve.
Perhaps StuffSwapper is not best example... I want to have able to change settings (set of config variable i think) of any mutators when change game on server.
ProAsm wrote:
Fri May 21, 2021 8:24 pm
Yes it is possible but very involved.
Thank you. I seem to grasp the idea. As I understand it, your code must be executed before spawn mutator. Right? So that the mutator worked with new settings.

User avatar
TankBeef
Skilled
Posts: 163
Joined: Tue Apr 13, 2021 12:56 am

Re: Is there any way to change the mutator settings when changing the map/game?

Post by TankBeef » Fri May 21, 2021 11:51 pm

You mean something like medToggle?

User avatar
f7r
Average
Posts: 41
Joined: Mon Oct 19, 2020 6:53 pm

Re: Is there any way to change the mutator settings when changing the map/game?

Post by f7r » Sat May 22, 2021 1:05 am

Only ProAsm understood me correctly. How to explain clear? For simple example, there is such a mutator as GravityControl - I want that in one game/map there was one level of gravity (config variable nGravityLevel), and in another game/map - another level. In order to change the parameters of the mutator when changing the game on server.

User avatar
Barbie
Godlike
Posts: 2125
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Is there any way to change the mutator settings when changing the map/game?

Post by Barbie » Sat May 22, 2021 1:11 am

ProAsm wrote:
Fri May 21, 2021 8:24 pm
Firstly you create a small mutator that has all the settings and classes of whatever other mutator's settings you want to change.
In most cases including all these other packages is not needed, you only need to know the variable names. Then you can change them with SetPropertyText(). Sadly it does not work with arrays, for example Dispatcher.OutEvents[].

Your mutator has first to find the other mutator and then change its variable(s), before that mutator uses them. Example:

Code: Select all

ForEach AllActors(class'Mutator', M)
	if (M.Name == 'WhateverMutator0')  {
		M.SetPropertyText("PropertyName", "New Value");
		break;
	}
f7r wrote:
Sat May 22, 2021 1:05 am
In order to change the parameters of the mutator when changing the game on server.
I do this with a lot of maps on my server:

Code: Select all

enum EPatchStage {
	PS_PreBeginPlayStart,
	PS_PreBeginPlay,
	PS_PostBeginPlay,
	PS_State,
};

function bool PatchMap(string MapNameWithoutExtension, ELogType LogLevel, out int PatchCount, EPatchStage PatchStage) {
const CFunctionNamePatchMap = "PatchMap";
local int PredictedResult;

	switch(MapNameWithoutExtension) // ordered by map name
	{

		case "MH-305":
			if (PatchStage != PS_PreBeginPlay)
				goto PatchMap_NoPatchDefined;
			PredictedResult = 2 + 1;
			PatchCount = PatchMap_MH_305();
			Goto PatchMap_PatchWasDefined;

		case "MH-3072-FloorWays_rv1":
			if (PatchStage != PS_PreBeginPlay)
				goto PatchMap_NoPatchDefined;
			PredictedResult = 2;
			PatchCount = PatchMap_MH_3072_FloorWays_rv1();
			Goto PatchMap_PatchWasDefined;
...
That function runs for every PatchStage. In most cases PreBeginPlay is used, but this depends on the kind of patches.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

User avatar
f7r
Average
Posts: 41
Joined: Mon Oct 19, 2020 6:53 pm

Re: Is there any way to change the mutator settings when changing the map/game?

Post by f7r » Sat May 22, 2021 11:10 am

Barbie wrote:
Sat May 22, 2021 1:11 am
That function runs for every PatchStage. In most cases PreBeginPlay is used, but this depends on the kind of patches.
What causes this function? Is it UEngine builtin?
Barbie wrote:
Sat May 22, 2021 1:11 am
before that mutator uses them.
How to achieve this? What should be the sequence? So that other mutator actor already exist, but did not processed to use variables.

ProAsm
Skilled
Posts: 191
Joined: Sun Sep 29, 2013 7:12 am

Re: Is there any way to change the mutator settings when changing the map/game?

Post by ProAsm » Sat May 22, 2021 12:00 pm

Very interesting indeed Barbie :)

User avatar
Barbie
Godlike
Posts: 2125
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Is there any way to change the mutator settings when changing the map/game?

Post by Barbie » Sat May 22, 2021 1:30 pm

f7r wrote:
Sat May 22, 2021 11:10 am
Barbie wrote:
Sat May 22, 2021 1:11 am
That function runs for every PatchStage. In most cases PreBeginPlay is used, but this depends on the kind of patches.
What causes this function? Is it UEngine builtin?
Every Actor has some events in the process of its creation. See Chain_Of_Events_When_Spawning_Actors in wiki.
So your mutator should call that PatchMap() function in every stage of that process:

Code: Select all

Class MapPatcher expands Mutator;

enum EPatchStage {
	// event *Spawned* is left out
	PS_PreBeginPlayStart,
	PS_PreBeginPlay,
	PS_PostBeginPlay,
	PS_State,
};


event PreBeginPlay() {
local int PatchCount;
	PatchMap(MapFilename, LogLevel, PatchCount, PS_PreBeginPlayStart);
	...
	PatchMap(MapFilename, LogLevel, PatchCount, PS_PreBeginPlay);
}

event PostBeginPlay() {
	PatchMap(MapFilename, LogLevel, PatchCount, PS_PostBeginPlay);
	...
}

auto state Ready {

begin:
	if (bActive)
	{
		PatchMap(MapFilename, LogLevel, PatchesCount, PS_State);
		...
	}

}
f7r wrote:
Sat May 22, 2021 11:10 am
What should be the sequence? So that other mutator actor already exist, but did not processed to use variables.
Look at the code of the other mutator(s) and decide when to change its variables. Also the position in the chain of mutators is relevant.

(My MapPatcher has 18234 lines and 1805 compilations at the moment.)
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett