I'm going to try to write a function that lets us spawn items at certain intervalls inside a set radius. I'm a complete novice and probably won't do this on the first try, so anyone not learning from it or my mistakes - feel free to chip in!
I'm just going to use this thread as a sort of diary as I progress from literary 0% , and then hopefully an improved "quick-guide" or boiler item script if I manage to get something working.
[DOUBLEPOST=1475350605][/DOUBLEPOST]
Step 1.
I find a text editor that I like to work with, it should open fast, simple and I want it to be a bit pretty. I need a nice readability and contrast. I landed on something called Atom for osx. Which has some backing from github and is free.
Next up I open the metorites plugin from Smeag, which seems to be pretty well written and has a lot of the same functions as I need - Basically only more, so I could in theory - and I have tried.. To just take out the things I don't need. Like the meteor, but I figured I'll have to start from scratch to succeed by understanding a bit of what I'm doing.
I copy the first part of it, into a new document which I'm saving under a new name. Now I'll open a few tabs, try to get a grip about Classes in c# - and come back to it after I make any progress.
Code:using System.Collections.Generic; using System.Linq; using Oxide.Core; using Oxide.Core.Configuration; using UnityEngine; using System.Collections; using System;// Some sort of initial hookup of other scripts and systems above, left it intact from the donor scrpt.. // General info about plugin below namespace Oxide.Plugins { [Info("Drillsite", "ztif", "0.1")] [Description("Rock eruptions occur at timed intervall - (earthquakes?!).")]// Not sure how classes work. But I'll call this itemspawn_class public class itemspawn_class : HurtworldPlugin { } }
My journey through learning plugin development
Discussion in 'Hurtworld Development' started by ZTIF, Oct 1, 2016.
-
Have been away for about a week, but figured I'd get back to this now.
Taking one step back, and forgetting about Hurtworld for a minute, I've managed to get a very unpolished script going that spawns a random item from a pre determined list of prefabs at a random location inside a given set of coordinates every five seconds/frames on a empty unity test project.
Code://using System.Collections.Generic; //using System.Linq; //using Oxide.Core; //using Oxide.Core.Configuration; using UnityEngine; using System.Collections; using System; using System.Collections.Generic;// Some sort of initial hookup of other scripts and systems above, left it intact from the donor scrpt.. // General info about plugin below //namespace Oxide.Plugins //{ // [Info("Drillsite", "ztif", "0.1")] // [Description("Rock eruptions occur at timed intervall - (earthquakes?!).")]// Not sure how classes work. But I'll call this itemspawn_class // public class itemspawn_class : HurtworldPlugin public class drillsite: MonoBehaviour { List<GameObject> prefabList = new List<GameObject>(); public GameObject Prefab1; public GameObject Prefab2; public GameObject Prefab3; static int count = 0; static float lastTime = 0; public int showCount = 1; public float MinX = -10; public float MaxX = 10; public float MinY = 0; public float MaxY = 1; public float MinZ = 0; public float MaxZ = 1;/* this.gameObject = Singleton<HNetworkManager>.Instance.NetInstantiate( uLink.NetworkPlayer.server, "WorldItemMeteor", Vector3.zero, Quaternion.Euler(0, 180, 0), GameManager.GetSceneTime()); */ void Start() { lastTime = Time.time; prefabList.Add(Prefab1); prefabList.Add(Prefab2); prefabList.Add(Prefab3); ; } void Update() { if(count < 50) { if (Time.time - lastTime > 5.0f) { float x = UnityEngine.Random.Range(MinX,MaxX); float y = UnityEngine.Random.Range(MinY,MaxY); float z = UnityEngine.Random.Range(MinZ,MaxZ); int prefabIndex = UnityEngine.Random.Range(0,3); // Instantiate(spawnObj, new Vector3(x,y,z), Quaternion.identity) as GameObject; if(Prefab1 != null) Instantiate(prefabList[prefabIndex], new Vector3(x,y,z), Quaternion.Euler(x, y, z)); // if(prefabB != null) Instantiate(prefabB, new Vector3(x, y, z), Quaternion.Euler(x, y, z)); lastTime = Time.time; count++; showCount = count; } } } // } }
Then the next step will be to un-comment the header and translate it into something that would actually work trhough oxide and in the game -
Code:namespace Oxide.Plugins { [Info("EpicPlugin", "Unknown", 0.1)] [Description("Makes epic stuff happen")]class EpicPlugin : HurtworldPlugin { // The rest of the code and magic } }
Last edited by a moderator: Nov 24, 2016 -
I would love to see more of this, I really want like to learn C# and I am a quick learner but someone has to show me why a setting should be that setting.
So if possible please post more of this diary ;-) -
I've been getting a lot closer to having a better grasp on Oxide / C# lately, and will continue this and post a working script soon. It's a shame no-one who is more of a coder than I, have taken time to post a bunch of these very useful snippets..
Thank you very much for your input Kappasaurus! -
Wulf Community Admin