So far I've been able to use the hooks in oxide as well as setting/getting variables of objects/entities, but is there a way to catch when an instance variable/list in an entity changes?
i.e. when an AI helicopter instance's _targetList adds or removes an entry
Entity var/event hooks?
Discussion in 'Rust Development' started by Quenn1599, Jan 30, 2016.
-
Calytic Community Admin Community Mod
List does not support notifications for changes.
You will have to create a timer and compare the current list with a saved version of the list from the last check. In other words, your plugin will have to do the legwork to accomplish this. -
Alrighty, thanks for the info!
-
You could try ObservableCollection<T> instead of List<T>
ObservableCollection has a CollectionChanged event which is fired when the collection is being modified.
Untested in oxide though.Code:using System.Collections.ObjectModel;public class MyMemory() { private ObservableCollection<string> _ocList = new ObservableCollection<string>(); public MyMemory() { _ocList.CollectionChanged += (sender, e) => { //list changed - an item was added. if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { //Do what ever you want to do when an item is added here... //the new items are available in e.NewItems } }; } } -
Yeah, sadly unless there's a way to override the var types on objects then I guess I have to use the timer + saved list method.
