How to start programming mods for my summer car?

Hey, everyone, I am new too unity and C# but I have programmed in Java and even modified java based games.

How do you all start creating plugins? Like complex ones for example the coffie machine mod, or the colt 1911 mod.
 
Now I am having an issue that the only GameObject it can find is the satsuma. if I try to find PLAYER or even the CD_Player in the car it throws an error saying
Object reference not set to an instance.

If I attempt to do it the way you recommended
It only returns the method as the SATSUMA.

What am I doing wrong?


This is my code:

Satsuma = GameObject.Find("SATSUMA(557kg, 248)").gameObject;
CDPlayer = GameObject.Find("PLAYER");
PlayMaker = Satsuma.GetComponents<PlayMakerFSM>();

ModConsole.Print("CDPlayerNameComponent: " + PlayMaker[1].name);
ModConsole.Print("CDPlayerName: " + PlayMaker[1].name);


 
you would be more efficient verifying the in-game components than looking for it by code, right now I do not know where the cd_Player is located but I imagine that it will be in child to the satsuma gameobject, you would need to know exactly where the cdplayer playmakerfsm is located
 
use the develop toolkit for search and visual components variables, it is a very good tool that will help you to get the names of variables, events and others ... it even lets you enable and disable
 
If you search for the "PLAYER" object in the beginning it will end up NULL since it doesn't spawn untill everything else is loaded basicly. Notice it's all black once you finished loading? Thats because "PLAYER" has not been spawned yet.

..So to find PLAYER and give it a valid reference, if null is not what you desire LOL, you MUST wait untill player is spawned before giving it the reference.

Possible solution: (Not tested this code posted bellow.. written from memory)
Code:
using System.Threading; // Need the reference

GameObject _player; // Player reference

//First loaded when mod initiated
public override void OnLoad()
{
   _player = GameObject.Find("PLAYER"); // Will probably NOT find reference...
    new Thread(work).Start(); // Start new thread work
}

//Work method
void work()
{
    Thread.Sleep(10 * 1000); // Make it sleep for a while...

   _player = GameObject.Find("PLAYER"); // Try again...
}

Try this and see if it works!

My issue is that I don't know how to check if the player is in "driving mode".. I'm a little lost when it comes to how to check it... My thoughts are that it can be done by using "PLAYERINCAR" PlayMaker event but with no avail so far... Suggestions, ideas are much appreciated!
 
use the template better for load mod when player active.
private static AssetBundle m_bundle;
private static ModBehaviour m_instance;
public static ModBehaviour Instance
{
get { return m_instance; }
}
// Use this for initialization
void Start()
{
m_instance = this;
StartCoroutine(SetupMod());
}
private IEnumerator SetupMod()
{
while (GameObject.Find("PLAYER") == null)
{
yield return null;
}
var path = YourMod.assetPath;
path = Path.Combine(path, "YourAssets.unity3d");
if (!File.Exists(path))
{
ModConsole.Error("Couldn't find asset bundle from path " + path);
yield break;
}
m_bundle = AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(path));
ModConsole.Print("YourMod Completed!");
LoadAssets();
}
private void LoadAssets()
{
Instantiate(m_bundle.LoadAsset<GameObject>("YourPrefab")).AddComponent<YourScript>();
}
private void OnDestroy()
{
m_bundle.Unload(true);
}
 
My issue is that I don't know how to check if the player is in "driving mode".. I'm a little lost when it comes to how to check it... My thoughts are that it can be done by using "PLAYERINCAR" PlayMaker event but with no avail so far... Suggestions, ideas are much appreciated!
I imagine that the solution would be in the general fsmbool.
if(FsmVariables.GlobalVariables.FindFsmBool("PlayerCarControl").Value)
{
ModConsole.Print("using car");
}
I have not tested it, I guess that's how it worked so I looked at it quickly
 
I managed to use a string instead. Thanks!

Code:
if (FsmVariables.GlobalVariables.FindFsmString("PlayerCurrentVehicle").Value != "")
{
    ModConsole.Print("You are driving a vehicle.");
}

And thanks for sharing that template :thumbsup:
 
Thanks, guy it worked I opened up a new thread that is set to run all the time and it was able to find the component PLAYER. Now how do I edit variables in a component? I wanna try changing the walk speed of PLAYER just to play around with the code.
 
Hi, I'm new, I have main mod class and a console command class,
The command should print string in console but it does not work, I guess I have to implement command class somehow into main mod class, how do I do it?
 
There are plenty of ways to wait for load completion. Take a look at zamp's mods. He links his github in every mod and you can take a look at his more complex mods. Also, when you link dlls from the game make sure dependencies arenta copied into your mod. All of that info is written on GitHub wiki for ModLoader. There is also msc discord for modding that Kubix has created. If you need an invite send me pm
 
Another question, how can i place my new object into the game(position it, and etc.)
What code do i need to write?

Sorry, I thought I was elsewhere earlier.. To topic:

Visit this link that provides needed information regarding the creation of assets/gameobjects:
https://github.com/piotrulos/MSCModLoader/wiki/How-to-create-and-use-Asset-Bundles

Code:
//Define objects
AssetBundle assets;
GameObject turbo;

//Onload.. We load, initialize and give references.
assets = LoadAssets.LoadBundle(this, "turbo.unity3d"); // Load this asset
turbo = assets.LoadAsset("turbo_prefab.prefab") as GameObject; //get specific prefab
assets.Unload(false); //Unload once all prefabs has been gathered to clean memory

//Placement
turbo = GameObject.Instantiate(turbo); //Instantiate object in the world
// OPTIONAL: turbo.transform.SetParent(GameObject.Find("satsu").transform, false); // We can set it as child object

//We set pos, rot & scale | Be aware, there are localPosition and Position. Choose relative to the use.
turbo.transform.localPosition = new Vector3(0.3f, 0.16f, 1.02f);
turbo.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
turbo.transform.localScale = new Vector3(0.0005f, 0.0005f, 0.0005f);

TIP: If the object is NOT to move in-game you should always tick the checkbox making it a static object. If your object is a child of an object it can still be ticked as static. It will require less resources of the PC running the mod and is recommended.
 
Last edited:

Latest News

How long have you been simracing

  • < 1 year

    Votes: 365 15.9%
  • < 2 years

    Votes: 254 11.0%
  • < 3 years

    Votes: 245 10.7%
  • < 4 years

    Votes: 181 7.9%
  • < 5 years

    Votes: 303 13.2%
  • < 10 years

    Votes: 260 11.3%
  • < 15 years

    Votes: 166 7.2%
  • < 20 years

    Votes: 129 5.6%
  • < 25 years

    Votes: 100 4.3%
  • Ok, I am a dinosaur

    Votes: 297 12.9%
Back
Top