Guest User

Untitled

a guest
Jan 15th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.47 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using WusModApi;
  4.  
  5. public class MapScript : MonoBehaviour
  6. {
  7.     private bool _startedMusic = false;
  8.    
  9.     private void Start()
  10.     {
  11.         ModdingApi.Log("Hello, I am a logging tool. You can use me like this! I'm not written to your log file.");
  12.         ModdingApi.GameEvents.OnSecondTickCallback += TickSecond;
  13.        
  14.         var sprt = ModdingApi.ImageLibrary.GetModSprite("MissionImage");
  15.         if (sprt != null)
  16.         {
  17.             Debug.Log("FOUND AN IMAGE");
  18.         }
  19.         else
  20.         {
  21.             Debug.Log("Did not find an image :(");
  22.         }
  23.  
  24.         //Avoid doing much more with the API in Start. The game was not initially designed for modding, so some stuff happens in the first second or so
  25.         //(graphs get scanned, music is set, enemies are chosen etc...). If you want to do stuff with the api here, it's best you
  26.         //set an invoke for a second or two, and do stuff then.
  27.        
  28.         SetStartingResources();
  29.     }
  30.    
  31.     public void OnDestroy()
  32.     {
  33.         ModdingApi.GameEvents.OnSecondTickCallback -= TickSecond;
  34.     }
  35.    
  36.     public void Update()
  37.     {
  38.         //do something in update, this is called every frame so really use this sparingly...
  39.     }
  40.    
  41.     public void TickSecond(int second)
  42.     {
  43.         /* because the game wasn't initially designed for modding, there are certain things that happen in certain order.
  44.         In this case, remember to start a music loop in the fourth second, and do it only once. If you don't implement the bool,
  45.         the music will reset again in the 4th second of the next minute. */
  46.  
  47.  
  48.         if(second == 3 && !_startedMusic){
  49.  
  50.             var goodWarrior = ModdingApi.ImageLibrary.GetModSprite("GoodWarrior");
  51.             var evilWarrior = ModdingApi.ImageLibrary.GetModSprite("EvilWarrior");
  52.             ModdingApi.Dialogue.ShowDialogue(goodWarrior,  "Mesamandias", "We will banish you once and for all from these lands...", 5, true, "", 5.0f);
  53.             ModdingApi.Dialogue.ShowDialogue(evilWarrior,  "Aranarth", "Not before you all perish!", 0, false, "", 5.0f);
  54.  
  55.             _startedMusic = true;
  56.             PlayMusicListExample();
  57.             PlayClipExample();
  58.             SetWeather("weather_name_thunderStorm", 600);
  59.             ModdingApi.Logging.AddLog("Hold the fort!", "red");
  60.             //ModdingApi.Logging.ShowMessage("MAP TWO The last stand", "Hear me, brave warriors, as we stand tall within these ancient fortress walls. In this hour, we face a final test, With honor and valor, we'll give our best.");
  61.         }
  62.        
  63.         //if (second > 4)
  64.         //{
  65.         //    var weatherId = ModdingApi.Weather.GetCurrentWeather();
  66.         //    ModdingApi.ILog.AddLog("Weather is: " + weatherId, "white");
  67.         //}
  68.     }
  69.  
  70.     //Get the sound clip "Horn.wav", and play it. Sounds must be wav files in ModFolder/Sounds.
  71.     public void PlayClipExample()
  72.     {
  73.         var clip = ModdingApi.SoundLibrary.GetModSound("Horn");
  74.         ModdingApi.SoundLibrary.PlaySound(clip);
  75.     }
  76.    
  77.     //Music is just a sound clip, so get it and play it in a loop. Same folder as sounds.
  78.     public void PlayMusicExample()
  79.     {
  80.         //var clip = ModdingApi.SoundLibrary.GetModSound("the-legion");
  81.         //ModdingApi.SoundLibrary.PlayMusicLoop(clip);
  82.     }
  83.    
  84.     //Play a list of music
  85.     public void PlayMusicListExample()
  86.     {
  87.         //get the clips we want
  88.         var clip = ModdingApi.SoundLibrary.GetModSound("Legionnaire");
  89.         //var clipTwo = ModdingApi.SoundLibrary.GetModSound("chase");
  90.        
  91.         //make a list, and add the clips
  92.         List<AudioClip> music = new List<AudioClip>();
  93.         music.Add(clip);
  94.         //music.Add(clipTwo);
  95.        
  96.         //call the api to play it
  97.         ModdingApi.SoundLibrary.PlayMusicList(music);
  98.     }
  99.  
  100.     public void SetWeather(string weatherId, int duration)
  101.     {
  102.         //if we force weather, it will stay for the duration of the whole level, until we change ForceWeather to false again.
  103.         //ModdingApi.Weather.ForceWeather = true;
  104.        
  105.         //set the weather like this, remember that even if you force it the number will always show
  106.         ModdingApi.Weather.SetWeather(weatherId, duration);
  107.     }
  108.  
  109.     public void SetStartingResources()
  110.     {
  111.         ModdingApi.Resources.SetResource("Wood_res_name", 7000);
  112.         ModdingApi.Resources.SetResource("Stone_res_name", 5000);
  113.         ModdingApi.Resources.SetResource("Iron_res_name", 3000);
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment