I have created a predefined area in code and I am trying to get the location of mining quarries inside the zone so i can increase their rates, without increasing the rates of every quarry. As of right now it is increasing all quarries.
Code:private void OnQuarryGather(MiningQuarry quarry, Item item) { string minedItem; minedItem = item.info.name; // Creates an array of mining quarries on the server. MiningQuarry[] quarries = UnityEngine.Object.FindObjectsOfType<MiningQuarry>(); foreach (MiningQuarry BLquarry in quarries) { // If the entity is in the zone. if ((BLquarry.transform.position.z > this.zoneBottom && BLquarry.transform.position.z < this.zoneTop) && (BLquarry.transform.position.x < this.zoneEast && BLquarry.transform.position.x > this.zoneWest)) { if ((minedItem.Contains("ore")) || (minedItem.Contains("oil")) || (minedItem.Contains("fragment")) || (minedItem.Contains("stone"))) { item.amount = (int)(item.amount * 3); } else { item.amount = (int)(item.amount); } } else { item.amount = (int)(item.amount); } } }
Using entity location to increase gather rate?
Discussion in 'Rust Development' started by (Stray), Apr 6, 2017.
-
OnQuarryGather is called for every quarry individually, whenever this quarry gathers items. Thus you don't need to get an array of all quarries. This should solve your problem:
Code:private void OnQuarryGather(MiningQuarry quarry, Item item) { string minedItem = item.info.name; if ((quarry.transform.position.z > this.zoneBottom && quarry.transform.position.z < this.zoneTop) && (quarry.transform.position.x < this.zoneEast && quarry.transform.position.x > this.zoneWest)) { if ((minedItem.Contains("ore")) || (minedItem.Contains("oil")) || (minedItem.Contains("fragment")) || (minedItem.Contains("stone"))) item.amount = item.amount * 3; } }
-
Thank you, this takes care of it.