Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using WusModApi;
- public class MapScript : MonoBehaviour
- {
- private bool _startedMusic = false;
- private void Start()
- {
- ModdingApi.Log("Hello, I am a logging tool. You can use me like this! I'm not written to your log file.");
- ModdingApi.GameEvents.OnSecondTickCallback += TickSecond;
- var sprt = ModdingApi.ImageLibrary.GetModSprite("MissionImage");
- if (sprt != null)
- {
- Debug.Log("FOUND AN IMAGE");
- }
- else
- {
- Debug.Log("Did not find an image :(");
- }
- //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
- //(graphs get scanned, music is set, enemies are chosen etc...). If you want to do stuff with the api here, it's best you
- //set an invoke for a second or two, and do stuff then.
- SetStartingResources();
- }
- public void OnDestroy()
- {
- ModdingApi.GameEvents.OnSecondTickCallback -= TickSecond;
- }
- public void Update()
- {
- //do something in update, this is called every frame so really use this sparingly...
- }
- public void TickSecond(int second)
- {
- /* because the game wasn't initially designed for modding, there are certain things that happen in certain order.
- 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,
- the music will reset again in the 4th second of the next minute. */
- if(second == 3 && !_startedMusic){
- var goodWarrior = ModdingApi.ImageLibrary.GetModSprite("GoodWarrior");
- var evilWarrior = ModdingApi.ImageLibrary.GetModSprite("EvilWarrior");
- ModdingApi.Dialogue.ShowDialogue(goodWarrior, "Mesamandias", "We will banish you once and for all from these lands...", 5, true, "", 5.0f);
- ModdingApi.Dialogue.ShowDialogue(evilWarrior, "Aranarth", "Not before you all perish!", 0, false, "", 5.0f);
- _startedMusic = true;
- PlayMusicListExample();
- PlayClipExample();
- SetWeather("weather_name_thunderStorm", 600);
- ModdingApi.Logging.AddLog("Hold the fort!", "red");
- //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.");
- }
- //if (second > 4)
- //{
- // var weatherId = ModdingApi.Weather.GetCurrentWeather();
- // ModdingApi.ILog.AddLog("Weather is: " + weatherId, "white");
- //}
- }
- //Get the sound clip "Horn.wav", and play it. Sounds must be wav files in ModFolder/Sounds.
- public void PlayClipExample()
- {
- var clip = ModdingApi.SoundLibrary.GetModSound("Horn");
- ModdingApi.SoundLibrary.PlaySound(clip);
- }
- //Music is just a sound clip, so get it and play it in a loop. Same folder as sounds.
- public void PlayMusicExample()
- {
- //var clip = ModdingApi.SoundLibrary.GetModSound("the-legion");
- //ModdingApi.SoundLibrary.PlayMusicLoop(clip);
- }
- //Play a list of music
- public void PlayMusicListExample()
- {
- //get the clips we want
- var clip = ModdingApi.SoundLibrary.GetModSound("Legionnaire");
- //var clipTwo = ModdingApi.SoundLibrary.GetModSound("chase");
- //make a list, and add the clips
- List<AudioClip> music = new List<AudioClip>();
- music.Add(clip);
- //music.Add(clipTwo);
- //call the api to play it
- ModdingApi.SoundLibrary.PlayMusicList(music);
- }
- public void SetWeather(string weatherId, int duration)
- {
- //if we force weather, it will stay for the duration of the whole level, until we change ForceWeather to false again.
- //ModdingApi.Weather.ForceWeather = true;
- //set the weather like this, remember that even if you force it the number will always show
- ModdingApi.Weather.SetWeather(weatherId, duration);
- }
- public void SetStartingResources()
- {
- ModdingApi.Resources.SetResource("Wood_res_name", 7000);
- ModdingApi.Resources.SetResource("Stone_res_name", 5000);
- ModdingApi.Resources.SetResource("Iron_res_name", 3000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment