Hi, I'm starting to get a headache on trying to rewrite this plugin to detect multiple cupboards in a sphere within range of initial cupboard. Any smart people out there to help me solve this? ^^
CupboardRadius [Obsolete]
Discussion in 'Plugin Support' started by dcode, Aug 28, 2015.
-
Code:
private void OnEntityBuilt(Planner plan, GameObject ent) { var cupboard = ent.GetComponent<BuildingPrivlidge>(); if (cupboard) { var hits = Physics.OverlapSphere(cupboard.transform.position, 35); foreach (var ents in hits) { BuildingPrivlidge privs = ents.GetComponentInParent<BuildingPrivlidge>(); } } }
-
This is a definitely a push in a right direction, thank you so much ! And I found a method "PreventBuilding (UnityEngine.BoxCollider)" . Could this be implemented and how to use it ? if max ents in hits is like >5 ? And would this actually work ? Thanks again.
[DOUBLEPOST=1488934852][/DOUBLEPOST]Also this code triggers even if cupboards are outside the set collision radius, tested with a TC 100m away, with radius set to 15. -
Alright, on closer inspection it would seem that the collider reacts to all of the surrounding objects <----X_X----< I am completely braindead at this point xD
-
Ok, in the end I had to resort to something retarded as this, but now it now detects only the tcs in set radius. In the end this basically works with minimal knowledge of C#, pretty much a copy-paste case. Credits to Fujikura for "DoRemove" and sami37 for providing me an absolutely amazing template to work with
Code:static void DoRemove(BaseEntity Entity, bool gibs = true) { if (Entity != null) { Interface.Oxide.CallHook("OnRemovedEntity", Entity); if (!Entity.IsDestroyed) Entity.Kill(gibs ? BaseNetworkable.DestroyMode.Gib : BaseNetworkable.DestroyMode.None); } } private void OnEntityBuilt(Planner plan, GameObject ent) { bool allowbuild = true; var cupboard = ent.GetComponent<BuildingPrivlidge>(); if (cupboard) { var hits = Physics.OverlapSphere(cupboard.transform.position, radius); int i = 0; foreach (var ents in hits) { var privs = ents.GetComponentInParent<BuildingPrivlidge>(); if (ents.ToString() == "assets/prefabs/deployable/tool cupboard/cupboard.tool.deployed.prefab (UnityEngine.BoxCollider)") { i++; PrintWarning("Number of TC in range : " + i +""); } if (i >= 6) { PrintWarning("Max cupboards reached, destroying"); allowbuild = false; DoRemove(cupboard, removeGibsAdmin); break; } } } }
Last edited by a moderator: Mar 8, 2017 -
how can i set this so you can only place 1 tc every 3 or 4 foundations apart
-
"ignoreInfluenceRestriction": true -
-
{
"cupboardRadius": 3,
"ignoreInfluenceRestriction": false
}
You'll find a happy medium, if you play w/ that radius number. -
-
I'm out of ideas ^^
-
Use my script above...
var hits = Physics.OverlapSphere(cupboard.transform.position, radius); . Change "radius" to distance you want.
And the last thing this script is missing is to send network update of an object state. -
something is broke, can no longer place cupboards near each other anymore since updates. anyone have a fix?
-
Wulf Community Admin
-
-
Wulf Community Admin
-
-
Here to confirm it!
Code:"ignoreInfluenceRestriction": true
[DOUBLEPOST=1494684267][/DOUBLEPOST]MultiCupboard | Oxide also isn't working.
But he said he is on it -
@Wulf Do you know something about SocketMods/SocketBase?
As far as I understand this plugin updates the BuildPrivilegeTrigger to a sphere in the updateTriggerMethod and sets a specific radius to it. This changes the area for the building privilege.
Then it tries to change where you can build a cupboard:
It changes the SocketMods of the "cupboard.tool.deployed.prefab" and removes a specific mod which outpts the phrase "You're trying to place too close to another cupboard". So as far as I understood it just removes a placing rule but somehow this behaviour has changed. I just tried to remove all rules but it's still getting ignored.Last edited by a moderator: May 13, 2017 -
Wulf Community Admin