SHARE
TWEET

RoR2 Custom Monster Spawner (bugged)

a guest Apr 23rd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Networking;
  4. using System.Collections.Generic;
  5.  
  6. namespace RoR2
  7. {
  8.     public partial class CombatDirector : MonoBehaviour
  9.     {
  10.         public float timer = 0f;
  11.         int monsterRating = 0;
  12.  
  13.         public Transform[] basicSpawner;
  14.         public Transform[] flyerSpawner;
  15.         public Transform[] crabSpawner;
  16.         public Transform[] vagrantSpawner;
  17.         public Transform[] bigSpawner;
  18.  
  19.         public string[] monsters;
  20.  
  21.         private void FixedUpdate()
  22.         {
  23.             // By emptying the CombatDirector we can handle monster spawns on our own.
  24.  
  25.             this.timer += Time.deltaTime;
  26.             if(this.timer > 5f) // every 5 or so seconds we try to spawn something
  27.             {
  28.                 this.timer = 0f;
  29.  
  30.                 if(monsters == null)
  31.                 {
  32.                     this.basicSpawner = GameObject.Find("basic spawner").GetComponentsInChildren<Transform>();
  33.                     this.flyerSpawner = GameObject.Find("flyer spawner").GetComponentsInChildren<Transform>();
  34.                     this.crabSpawner = GameObject.Find("crab spawner").GetComponentsInChildren<Transform>();
  35.                     this.vagrantSpawner = GameObject.Find("vagrant spawner").GetComponentsInChildren<Transform>();
  36.                     this.bigSpawner = GameObject.Find("big spawner").GetComponentsInChildren<Transform>();
  37.  
  38.                     monsters = new string[]
  39.                     {
  40.                         "Beetle",
  41.                         "Jellyfish",
  42.                         "Wisp",
  43.                         "Lemurian",
  44.                         "Golem",
  45.                         "Bell",
  46.                         "HermitCrab",
  47.                         "GreaterWisp",
  48.                         "Vagrant",
  49.                         "BeetleQueen",
  50.                         "Titan"
  51.                     };
  52.  
  53.                     monsterRating = 4; // start off only able to spawn the first 4 monsters
  54.                 }
  55.                
  56.                 // Choose a random monster
  57.                 string monsterName = monsters[UnityEngine.Random.Range(0, monsterRating-1)];
  58.                 // Choose spawn location
  59.                 Vector3 spawnPosition = Vector3.zero;
  60.                 if(monsterName == "Jellyfish" || monsterName == "Wisp" || monsterName == "GreaterWisp" || monsterName == "Bell")
  61.                 {
  62.                     spawnPosition = flyerSpawner[UnityEngine.Random.Range(0,flyerSpawner.Length)].position;
  63.                 }
  64.                 else if(monsterName == "HermitCrab")
  65.                 {
  66.                     spawnPosition = crabSpawner[UnityEngine.Random.Range(0,crabSpawner.Length)].position;
  67.                 }
  68.                 else if(monsterName == "Vagrant")
  69.                 {
  70.                     spawnPosition = vagrantSpawner[UnityEngine.Random.Range(0,vagrantSpawner.Length)].position;
  71.                 }
  72.                 else if(monsterName == "Vagrant")
  73.                 {
  74.                     spawnPosition = vagrantSpawner[UnityEngine.Random.Range(0,vagrantSpawner.Length)].position;
  75.                 }
  76.                 else if(monsterName == "BeetleQueen" || monsterName == "Titan")
  77.                 {
  78.                     spawnPosition = bigSpawner[UnityEngine.Random.Range(0,bigSpawner.Length)].position;
  79.                 }
  80.                 else
  81.                 {
  82.                     spawnPosition = basicSpawner[UnityEngine.Random.Range(0,basicSpawner.Length)].position;
  83.                 }
  84.  
  85.                 GameObject prefab = MasterCatalog.FindMasterPrefab(monsterName + "Master");
  86.                 GameObject body = BodyCatalog.FindBodyPrefab(monsterName + "Body");
  87.  
  88.                 GameObject monster = Instantiate<GameObject>(prefab, spawnPosition, Quaternion.identity);
  89.                 CharacterMaster master = monster.GetComponent<CharacterMaster>();
  90.                 NetworkServer.Spawn(monster);
  91.                 master.SpawnBody(body, spawnPosition, Quaternion.identity);
  92.             }
  93.         }
  94.     }
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top