I've looked through a bunch of solutions for my code, but none of them apply to what I've been trying to add. Since I'm modding a game, I've been coding through dnSpy, and I'm constantly coming up with a read-only error with my issue.
Like I said, I've looked through so many other threads about the "Property or indexer cannot be assigned to -- it is read only" error, but none of them actually help towards my code, from what I can tell.
// Token: 0x06000B48 RID: 2888 RVA: 0x00045EA0 File Offset: 0x000440A0
public static bool ConsoleCommandModifier(string command_arguments)
{
if (!string.IsNullOrEmpty(command_arguments))
{
string[] array = command_arguments.Split(new char[]
{
' '
});
if (array.Length > 0 && State.LocalPlayer != null && State.LocalPlayer != null)
{
string text = array[0].ToLower();
if (text != null)
{
if (text == "rocketjump")
{
State.LocalPlayer.Modifier = (PlayerControllerModifier)ScriptableObject.CreateInstance(typeof(RocketJumpModifier));
State.LocalPlayer.Modifier.AddModifier(State.LocalPlayer);
return true;
}
}
}
}
return false;
}
The expected results is, I type in the chat of the game "/modifier [modifier] and it applies that modifier to my character. This code was in the game back in early 2018, and I wanted to re-add the code.
The actual results is nothing but an error, describing "Property or indexer 'PlayerController.Modifier' cannot be assigned to -- it is read only. Usually there's more than just 1 modifier, but for this example, I'm using "rocketjump". When there's more modifiers, each of the
State.LocalPlayer.Modifier = (PlayerControllerModifier)ScriptableObject.CreateInstance(typeof(RocketJumpModifier));
lines do the same error, so I suspect that the error has something to do with this line.
Finally, how do I fix the "Property or indexer 'PlayerController.Modifier' cannot be assigned to -- it is read only" error?