Total Miner Forums

Total Miner => Mods => Topic started by: JAZZ 0R KILLER on April 02, 2018, 08:30:46 PM

Title: C# (Edit)
Post by: JAZZ 0R KILLER on April 02, 2018, 08:30:46 PM
Big shout out to Justyn! He has helped me with almost all of this project that I am working on.

I am working on a project that adds a sound effect to the game when a button is pressed. I got all the way up to the point to where you add the references, and you're supposed to add all the .dll files from the Total Miner directory. For some reason it doesn't let me add all of the .dlls, I get an error. Can someone help me out? What am I doing wrong?

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Sound_Effects_Mod
{
    public class Class1
    {
        SoundEffect[] SoundEffects;
        ITMGame gameVar;
        public void Draw(ITMPlayer player, ITMPlayer virtualPlayer)
        {

        }

        public void Initialize(ITMPluginManager agr, string path)
        {

        }

        public void InitializeGame(ITMGame game)
        {
            this.gameVar = game;
            this.SoundEffects = new SoundEffect[1];
            this.SoundEffects[0] = this.gameVar.AudioManager.LoadSoundEffectFromStream(@"C:\Users\First.Last\Desktop\Sound_Effects\Sound_Effect.wav");

        }

        public void PlayerJoined(ITMPlayer player)
        {

        }

        public void PlayerLeft(ITMPlayer player)
        {

        }

        public void Update(ITMPlayer player)
        {
            if (InputManager.IsKeyReleasedNew(player.PlayerIndex, Keys.N))
            {
                int index = this.gameVar.Random.Next(1, 1);
                this.SoundEffects[index].Play();
            }
        }

        public void Update()
        {

        }
    }
}
Title: Re: C# (Need help)
Post by: Craig on April 03, 2018, 08:39:57 AM
What error? Do you mean the yellow icon next to the reference?

It's probably better to just copy the dll's from total miner directly to your bin folder and reference the dll's from there, or create a sub folder in your project, named Libs or something, and copy the dll's into there and reference them from there.
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 03, 2018, 01:28:25 PM
Im getting errors like this: Severity   Code   Description   Project   File   Line   Suppression State
Error   CS0234   The type or namespace name 'Touch' does not exist in the namespace 'Microsoft.Xna.Framework.Input' (are you missing an assembly reference?)   Noise effect Mod   C:\Users\My.Name\Documents\My Games\TotalMinerBeta\Mods\Noise effect Mod\Noise effect Mod\Noise effect Mod\Class1.cs   10   Active
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 03, 2018, 01:31:13 PM
I've tried adding all the .dlls from Total Miner directory to the references, almost all work, but CSteamworks, DSETUP, dsetup32, and steam_api wont load into the references. Also, where can I get the Total Miner plugins? That might contribute greatly to my problem
Title: Re: C# (Need help)
Post by: Craig on April 03, 2018, 06:20:04 PM
You don't need to add steamworks, dsetup etc, you only need to add whichever StudioForge, Microsoft.Xna and System assemblies your code will actually reference. See some of the examples here: https://github.com/cmartin99/TotalMinerMods
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 03, 2018, 06:29:06 PM
How do I see the references on these projects?
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 03, 2018, 07:13:32 PM
It says it can't find ITMPlayer, ITMGame, "The name InputManager does not exist" and 14 other errors
Title: Re: C# (Need help)
Post by: Craig on April 03, 2018, 07:26:18 PM
How do I see the references on these projects?
Download the solution and look at the projects in Visual Studio.
Title: Re: C# (Need help)
Post by: Craig on April 03, 2018, 07:26:56 PM
It says it can't find ITMPlayer, ITMGame, "The name InputManager does not exist" and 14 other errors
You need 'using' statements at top of source file. See the projects I posted above.
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 03, 2018, 07:48:19 PM
Okay, I've looked at some things. My mod folder for the mod I am trying to create only has Class1.cs of the cs files. And I also don't have the .dll file
Title: Re: C# (Need help)
Post by: Craig on April 03, 2018, 07:54:47 PM
I'm going to create a Getting Started video for C# soon, probably later today. You might be best waiting for that.
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 03, 2018, 07:55:23 PM
Will do, I'll be looking for it
Title: Re: C# (Need help)
Post by: Rorthic on April 03, 2018, 08:56:21 PM
I typed this up a while ago as a reminder to myself on how to do a mod. I briefly read through it and I believe it is still correct.

1) Install XNA Game Studio in Visual Studio 2017 follow this tutorial: http://totalminerforums.net/index.php?topic=19324.0
2) Open Visual studio and create a new project for XNA Game Studio Windows Game Library(4.0) with your mod name for the name  ex: TM_ExampleMod.
3) In the Solution Explorer right click on References select add reference
4) Click Browse and navigate to your Total Miner steam Directory                             
  (C:\Program Files (x86)\Steam\steamapps\common\Total Miner)
5) Select all the .dll files and click add, or add 1 at a time, currently there are 7 in total: StudioForge.Engine.Core.dll, StudioForge.Engine.GUI.dll, StudioForge.Engine.Services.dll, StudioForge.Engine.Integration.dll, StudioForge.Engine.Game.dll, StudioForge.BlockWorld.dll, StudioForge.TotalMiner.API.dll
6) After adding them select the ones you need with check marks and click ok
7) Rename the default class1.cs file to the mod name TM_ExampleMod1.cs by right clicking on it and choosing rename.
8 ) Open the cs file for editing
9) At the top add
using StudioForge.TotalMiner.API;
using StudioForge.TotalMiner;
10) change the class name to match your mod name and make it extend ITMPlugin public class Class1 to
public class TM_ExampleMod1 : ITMPlugin
11)  Add the required interfaces to the class:                                                           
public void WorldSaved(int version){}
       public void PlayerJoined(ITMPlayer player){}
       public void PlayerLeft(ITMPlayer player){}
       public void Initialize(ITMPluginManager manager, string path){}
       public void InitializeGame(ITMGame game){}
       public bool HandleInput(ITMPlayer player){return false;}
       public void Update(ITMPlayer player){}
       public void Update(){}
       public void Draw(ITMPlayer player, ITMPlayer virtualPlayer){}
12)  In solution explorer right click on your mod name not the solution name and choose add new item
13)  find Code File C# highlight it and click add
14) Rename it to TMPluginProvider.cs  note: this is the required name
15)  open the file for editing with required code and implement required interfaces:             
using StudioForge.TotalMiner.API;

       namespace TM_ExampleMod
   {
       class TMPluginProvider : ITMPluginProvider
       {
            public ITMPlugin GetPlugin()
      {
         return new TM_ExampleMod1();
      }
           public ITMPluginBlocks GetPluginBlocks(){return null;}
           public ITMPluginArcade GetPluginArcade(){return null;}
          public ITMPluginGUI GetPluginGUI(){return null;}
       }
   }
note: namespace TM_ExampleMod is mod namespace name, return new TM_ExampleMod1() is constructor for mod name
16) Code your mod, build your solution, copy your modname.dll to the mod folder for TM in a folder of the mod name
   C:\Users\YourName\Documents\My Games\TotalMiner\Mods\ TM_ExampleMod1
17) Run Total Miner and test your mod.

Optional Settings

1) Right click on mod project file and choose properties
2) under XNA Game Studio select Use HiDef to access the complete API
3) go to Build Events and for Post-Build event command line: add     
   xcopy /Y /E /I "$(TargetPath)" "$(ProjectDir)\Install\"   
   xcopy /Y /E /I "$(ProjectDir)\Content" "$(ProjectDir)\Install"     
   xcopy /Y /E /I "$(ProjectDir)\Install" "$(HOMEDRIVE)$    (HOMEPATH)\Documents\MyGames\TotalMiner\Mods\$(ProjectName)"
   note: this copies the mod files to the mod directory automatically. make sure the path is correct.
Title: Re: C# (Need help)
Post by: Craig on April 03, 2018, 11:29:18 PM
Heres the first video https://youtu.be/uTqqXBrHT5Q

I'll post a 2nd video for Arcade Block Games later.
Title: Re: C# (Need help)
Post by: Craig on April 04, 2018, 03:15:58 AM
Arcade block
https://youtu.be/6hdvo41wPoQ
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 04, 2018, 09:12:10 AM
*Ignore*
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 04, 2018, 02:51:28 PM
These videos have been extremely  helpful. I was following an outdated tutorial this whole time and didn't know it. I do have one more question, how would I add a sound effect?
Title: Re: C# (Need help)
Post by: Craig on April 04, 2018, 06:16:42 PM
I do have one more question, how would I add a sound effect?
This mod (https://github.com/cmartin99/TotalMinerMods/tree/develop/Lockpick) adds a sound effect.
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 04, 2018, 06:30:46 PM
Thanks!
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 04, 2018, 07:14:47 PM
When I go to load my mod, it says "Index was outside of the bounds of the array of InitializeGame"
Title: Re: C# (Need help)
Post by: Craig on April 04, 2018, 08:35:37 PM
Start the game via Steam, In Visual Studio, Debug -> Attach to Process, select the total miner process, turn on 'Break On Exception' or put a break point in the InitializeGame method, activate the mod in game and start a world, and use the debugger to find out what is wrong in the InitializeGame method.
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 04, 2018, 09:55:31 PM
Alright, I found out that my problem here is it's not locating  my sound file. Is there a certain location I should move that to?

'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.TotalMiner.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.Net.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.Integration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.Services.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Xact\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Xact.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.Game.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.GUI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.TotalMiner.API.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Game\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Game.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Graphics\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Graphics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.Renderers.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Xna.Framework.Input.Touch\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Input.Touch.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.BlockWorld.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Total Miner\StudioForge.Engine.GamerServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Xna.Framework.GamerServices\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.GamerServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
The thread 0x1e0c has exited with code 0 (0x0).
The thread 0x1434 has exited with code 0 (0x0).
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Users\My.Name\Documents\My Games\TotalMinerBeta\Mods\SoundEffects\MyTestMod.dll'. Symbols loaded.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'Microsoft.GeneratedCode'.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Management.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'StudioForge.TotalMiner.exe' (CLR v4.0.30319: StudioForge.TotalMiner.exe): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[7080] StudioForge.TotalMiner.exe' has exited with code 1073807364 (0x40010004).

I honestly feel terrible for keeping you busy with this. I'm sure that you're busy with other things
Title: Re: C# (Need help)
Post by: Craig on April 04, 2018, 11:09:12 PM
The sound file is stored in the mod folder, just like that Lockpick mod I linked you to. So when you build, copy both the DLL and the sound file into your mod folder.
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 05, 2018, 10:28:14 AM
Okay, I put the sound file into the mod folder, but I still get the same error.

*UPDATE* My apologies for taking your time. I found my small error and got it fixed, though the sound doesn't play. I'm sure I can find that error. Thanks for sticking around with me, it really means a lot!
Title: Re: C# (Need help)
Post by: JAZZ 0R KILLER on April 05, 2018, 10:51:41 AM
I'm trying to set it to play the sound effect at the press of a key, I press the key, but no sound

*UPDATE* I have it set to notify me when the button is pressed. That all works, but it still doesn't play the sound. How do I execute the script (what is the script) to play the sound at the press of a key? As I said, when I press the assigned key, I get the notification, but no sound is played.
Title: Re: C# (Edit)
Post by: Rorthic on April 08, 2018, 01:08:46 AM
Not sure if this has been answered yet but his works, I tested it. Without seeing your code we cant help much. But if you get the notification when you press the button but no sound it makes me think there is a problem with the sound file. 

Code: [Select]
if (InputManager.IsKeyPressed(tmPlayer.PlayerIndex, Keys.P))
{
     SoundEffect sound = game.AudioManager.LoadSoundEffectFromStream(FileSystem.RootPath + Mod.Path + "357_reload1.wav");
     sound.Play();
}

p.s. if you havent joined TM discord I would suggest it, these question usually get answered pretty quickly in the modding section. http://totalminerforums.net/index.php?topic=18450.0
Title: Re: C# (Edit)
Post by: Craig on April 08, 2018, 02:47:54 AM
Code: [Select]
if (InputManager.IsKeyPressed(tmPlayer.PlayerIndex, Keys.P))
{
     SoundEffect sound = game.AudioManager.LoadSoundEffectFromStream(FileSystem.RootPath + Mod.Path + "357_reload1.wav");
     sound.Play();
}
While this code works, it has some flaws.

It will be loading and playing the sound effect 60 times a second. That will likely be problematic. Better to use InputManager.IsKeyPressedNew or InputManager.IsKeyReleasedNew. This ensures the sound effect is only played once per key press.

Also it is inefficient to load a sound effect from disk every time you want to play it. It will likely cause frame rate stutters. It is better to cache all sound effects by loading them once when the mod is initiailized (see the LockPick example on github).

Also if you plan on using the sound effect rapidly, like say for machine gun fire, then it is better to use the SoundEffectInstance type over the SoundEffect type. It allows more control the playing of several instances of the sound effect better, even if the sound overlaps each other, and gives other control you don't have with SoundEffect.
Title: Re: C# (Edit)
Post by: JAZZ 0R KILLER on April 08, 2018, 09:13:20 AM
"The name 'tmPlayer' does not exist in the current context"