MarvinBeym / MscModApi

An api for the game My Summer Car that allows mod creators to make their objects installable.
MIT License
10 stars 138 forks source link

Help with documentation. #41

Open Martin97y opened 7 months ago

Martin97y commented 7 months ago

Hello i want to use your modApi for my mod, but i got some problems. The documentation is hard to understand, i dont know how to use it. Can you please send me a example of installable part with screws? Thanks!

MarvinBeym commented 7 months ago

I haven't gotten to redoing the documentation yet

The best example I can give is probably my TurboMod: https://github.com/MarvinBeym/My-Summer-Car-Turbocharger/tree/feature/rework (feature/rework branch)

  1. Load your assetsbundle assetsBundle = Helper.LoadAssetBundle(this, "turbochargermod.unity3d");
  2. Create a PartBaseInfo object (this is pretty much a container for all the stuff that every part would need. partBaseInfo = new PartBaseInfo(this, assetsBundle, partsList);
  3. Create a class inheriting from DerivablePart Example: https://github.com/MarvinBeym/My-Summer-Car-Turbocharger/blob/feature/rework/SatsumaTurboCharger/part/TurboSmallExhaustInletTube.cs (The ExhaustHeader parent parameter is the parent (where this part installs on, this can also be a GamePart) which is a wrapper for parts added by the game (for example the cylinder head)
    • The DerivablePart class has several base methods you can choose from, if your prefab inside the assetbundle has the same name as you'd give the part as a partId you don't need to also tell the DerivablePart the prefabName as that is then automatically loaded using the partId.
  4. You should also pass the partBaseInfo as a parameter (In my case I made it static, if you want to make proper code, don't do it like that)
  5. You can add screws to the part using .AddScrew or AddScrews (Ideally do that inside the part class itself for cleaner code)
  6. Finally inside your Mods OnNewGame method. Add MscModApi.MscModApi.NewGameCleanUp(this);. This will reset parts when you start a new game

That's all you need for a part spawning & interactable

There are several more features of the api so let me know if you need further help

Martin97y commented 7 months ago

Thanks! And also the default spawn location is gonna be like normal position on load?

MarvinBeym commented 7 months ago

correct

Martin97y commented 7 months ago

And how to put specific parent? I want to install my model into the trunk on car body, can i specify position and rotation?

MarvinBeym commented 7 months ago

you will have to figure out a part you want it to attach, take

use Developer Toolset 2 to search for a part that would fit what you need.

For example the Dashboard would be dashboard = new GamePart("Database/DatabaseMechanics/Dashboard"); (You can use the example ´Database/DatabaseMechanics/Dashboard` to see how it would have to look. It needs a very specific setup of components (You can see that on the right side of the Developer Toolset 2 UI). It's always a part with uppercase first letter, !!! NEVER !!! with lowercase. (that path with Database/DatabaseMechanics is optional, but if there are multiple parts called "Dashboard" you might get the wrong one (which is random) and your mod will crash, so best to use the entire path to be sure).

Alternatively you can use SatsumaGamePart.GetInstance() which acts as a fake GamePart object (because the car itself does not implement things an actual GamePart of the game does (eg. you can't disassemble the Satsuma itself... because it is the starting point for everything else already, there is nothing the car itself is attached to...).

Usage of it should be avoided if possible as it's not the proper way to do it. There should be few instances where this is required and there is no proper way.

Position and Rotation get defined by

protected override Vector3 partInstallPosition => new Vector3(-0.0668f, 0.28826f, -0.08025f);
protected override Vector3 partInstallRotation => new Vector3(0, 0, 0);

inside the class you created

Martin97y commented 7 months ago

Now it shows this. obrazek

obrazek obrazek

MarvinBeym commented 7 months ago

I don't see you passing a parent to the base(...) call.

MarvinBeym commented 7 months ago

i'd recommend enabling developer/debug mode for ModLoader to see where the error is actually occuring

Martin97y commented 7 months ago

Ok sending whole log obrazek

MarvinBeym commented 7 months ago

"Version 4.0.0" is definetly wrong, you have your Visual Studio project incorrectly configured somewhere.

Something from the dev mode is also missing. Are you executing the debug.bat file after moving your .dll file to the mods folder?

MarvinBeym commented 7 months ago

And is your Visual Studio set to build in "Debug" as well?

Martin97y commented 7 months ago

I tried building it on lower version but then i got error on NET 2.0, and Debug build is selected.

MarvinBeym commented 7 months ago

you will have to build it on Net 2.0

there is no way around it

Martin97y commented 7 months ago

So your api needs to be built on 2.0 too?

MarvinBeym commented 7 months ago

everything in this game has to be, regardless of what it is,

the game is using decades old Unity

you don't have to do anything with my MscModApi code, you just have to put the .dll file from the Releases tab into your games mod folder

Martin97y commented 7 months ago

Switched to 2.0 but now im missing these two references obrazek

MarvinBeym commented 7 months ago

you probably didn't follow the ModLoader instructions. You are likely missing this:

https://github.com/piotrulos/MSCModLoader/wiki/Install-Visual-Studio-for-MSCLoader

MarvinBeym commented 7 months ago

Mainly the .Net 3.5

Martin97y commented 7 months ago

I have everything enabled, trying to update studio now

Martin97y commented 7 months ago

Still with everything installed im missing these 2 references.

Martin97y commented 7 months ago

obrazek

MarvinBeym commented 7 months ago

Try using 3.5 instead of 2.0 like Ms loader says

Martin97y commented 7 months ago

Now references are ok. But another problem obrazek

Martin97y commented 7 months ago

obrazek Config obrazek obrazek obrazek

MarvinBeym commented 7 months ago

Missing a reference to the MscLoader.dll I guess

Martin97y commented 7 months ago

obrazek

MarvinBeym commented 7 months ago

Why have you opened the MscModAli in visual studio code.

As I said, you only put the dll file of my MscModApi inside your mods folder, then in your visual studio project, you add a reference to that dll

Martin97y commented 7 months ago

obrazek Did that, but i cant still build my mod on 3.5 or 2.0 only on 4.0 which gives me error in game

Martin97y commented 7 months ago

obrazek Isnt this the problem? Msc loader was built on 4.0

MarvinBeym commented 7 months ago

I just looked at how my project is setup. "Target Framework" has to be Unity 3.5 .net full Base Cass Libraries

Martin97y commented 7 months ago

obrazek Still throws error.

MarvinBeym commented 7 months ago

Can you post a screenshot of the line where this error occurs in your code? (File & Line columns in your current screenshot)

Martin97y commented 7 months ago

obrazek

MarvinBeym commented 7 months ago

Hmm looks like there is no error...

Have you tried just building it? Sometimes visual studio sees errors that don't exist (anymore)

MarvinBeym commented 7 months ago

Alternatively you could try creating a completely new project and set it up correctly from the start

Martin97y commented 7 months ago

obrazek New project less errors.

Martin97y commented 7 months ago

MscModApi is imported

Martin97y commented 7 months ago

I can build on 4.0

Martin97y commented 7 months ago

obrazek

MarvinBeym commented 7 months ago

Then I don't know without sitting in front of it.

Compiling with .net 4 is definitely wrong and may cause your mod to not work as intended.

That's all I can say about this

Martin97y commented 7 months ago

I will try again later, but thanks for all your help! :)