C#:
---layout : forumstitle : 'Cupboard Overlap - Ignore Cupboard Influence'breadcrumbs : - "Plugin Development" : "/forums/plugin-development.105/" - "Rust Development" : "/forums/rust-development.4/"---<div class="titleBar"> <h1> <a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/' | prepend: site.baseurl }}">Cupboard Overlap - Ignore Cupboard Influence</a> </h1> <p id="pageDescription" class="muted">Discussion in '<a href="{{ '/forums/rust-development.4/' | prepend: site.baseurl }}">Rust Development</a>' started by <a class="username" dir="auto">virobeast</a>, <a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/' | prepend: site.baseurl }}"><span class="DateTime" title="Jan 9, 2016 at 7:20 AM">Jan 9, 2016</span></a>.</p></div><ol class="messageList" id="messageList"> <li id="post-161203" class="message" data-author="virobeast"> <div class="messageUserInfo"> <div class="messageUserBlock"> <div class="avatarHolder"> <span class="helper"></span> <a class="avatar Avm" data-avatarhtml="true"><img src="{{ '/assets/styles/oxide/logo.og.png' | prepend: site.baseurl }}" width="96" height="96" alt="virobeast" /></a> </div> <h3 class="userText"> <a class="username" dir="auto">virobeast</a> </h3> <span class="arrow"></span> </div> </div> <div class="messageInfo primaryContent"> <div class="messageContent"> <article> <blockquote class="messageText SelectQuoteContainer ugc baseHtml">Just a bit of butchered code from the cupboard radius if anyone wants to test it out and post suggestions if it is broken, I am currently away on holidays and unable to test.<br /> <br /> Essentially the only function this plugin should do is ignore cupboard influence.<br /> <div class="bbCodeBlock bbCodeCode"> <div class="type">Code : </div> {
% raw %
}
<pre>using Oxide.Core;
using Oxide.Core.Plugins;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins {
[Info("
CupboardOverlap"
, "
Virobeast"
, "
1.0.0"
, ResourceId = 2131)] public class CupboardOverlap : RustPlugin {
// Do not edit this file anymore: There is a config file now. protected override void LoadDefaultConfig() {
Config["
ignoreInfluenceRestriction"
] = false;
}
private int Overlap;
private bool ignoreInfluence;
private CupboardOverlapPersistence pst = null;
private bool initialized = false;
[HookMethod("
OnServerInitialized"
)] private void onServerInitialized() {
if (initialized) return;
LoadConfig();
ignoreInfluence = Config.Get<
bool>
("
ignoreInfluenceRestriction"
);
Puts("
Using a Overlap of {
0
}
, {
1
}
influence restrictions"
, Overlap, ignoreInfluence ? "
ignoring"
: "
not ignoring"
);
bool reloaded = false;
foreach (var prevPst in ServerMgr.Instance.gameObject.GetComponents<
MonoBehaviour>
()) {
if (prevPst.GetType().Name == "
CupboardOverlapPersistence"
) {
reloaded = true;
pst.influenceIgnored = (bool)prevPst.GetType().GetField("
influenceIgnored"
).GetValue(prevPst);
pst.influenceBackup = (SocketMod[])prevPst.GetType().GetField("
influenceBackup"
).GetValue(prevPst);
UnityEngine.Object.Destroy(prevPst);
break;
}
}
var bpts = UnityEngine.Object.FindObjectsOfType<
BuildPrivilegeTrigger>
();
var updated = 0;
foreach (var bpt in bpts) if (updateTrigger(bpt)) ++updated;
Puts("
Updated Influence"
, updated, bpts.Length);
if (bpts.Length >
0) updateInfluence(bpts[0].privlidgeEntity.prefabID);
initialized = true;
}
[HookMethod("
OnEntitySpawned"
)] private void onEntitySpawned(BaseNetworkable ent) {
if (!initialized || !(ent is BuildingPrivlidge)) return;
updateInfluence(ent.prefabID);
var trig = ent.GetComponentInChildren<
BuildPrivilegeTrigger>
();
if (trig == null) Interface.Oxide.NextTick(() =>
{
trig = ent.GetComponentInChildren<
BuildPrivilegeTrigger>
();
if (trig == null) {
PrintWarning("
Failed to update BuildingPrivlige : Missing BuildPrivilegeTrigger"
);
return;
}
updateTrigger(trig);
}
);
else updateTrigger(trig);
}
private void updateInfluence(uint privlidgePrefabID) {
if (ignoreInfluence == pst.influenceIgnored) return;
var attr = PrefabAttribute.server.Find(privlidgePrefabID);
var socketBases = attr.Find<
Socket_Base>
();
if (socketBases.Length <
1) {
PrintWarning("
Failed to update cupboard influence : Missing Socket_Base attribute"
);
return;
}
var socketBase = socketBases[0];
if (ignoreInfluence) {
if (pst.influenceBackup == null) pst.influenceBackup = socketBase.socketMods;
socketBase.socketMods = socketBase.socketMods.Where(mod =>
mod.FailedPhrase.english != "
You're trying to place too close to another cupboard").ToArray();
pst.influenceIgnored = true;
Puts("Cupboard influence restrictions are now ignored");
} else {
socketBase.socketMods = pst.influenceBackup;
pst.influenceIgnored = false;
Puts("Cupboard influence restrictions are no longer ignored");
}
} private class CupboardOverlapPersistence : MonoBehaviour
{
public bool influenceIgnored = false;
public SocketMod[] influenceBackup = null;
}
}
}
</pre>{% endraw %}
</div>
<div class="messageTextEndMarker"> </div>
</blockquote>
</article>
</div>
<div class="messageMeta ToggleTriggerAnchor">
<div class="privateControls">
<span class="item muted">
<span class="authorEnd"><a class="username author" dir="auto">virobeast</a>,</span>
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/' | prepend: site.baseurl }}" title="Permalink" class="datePermalink"><span class="DateTime"
title="Jan 9, 2016 at 7:20 AM">Jan 9, 2016</span></a>
</span>
</div>
<div class="publicControls">
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/' | prepend: site.baseurl }}" title="Permalink" class="item muted postNumber hashPermalink OverlayTrigger"
data-href="posts/161203/permalink">#1</a>
</div>
</div>
</div>
</li>
<li id="post-161219" class="message" data-author="k1lly0u">
<div class="messageUserInfo">
<div class="messageUserBlock">
<div class="avatarHolder">
<span class="helper"></span>
<a class="avatar Avm" data-avatarhtml="true"><img src="{{ '/assets/styles/oxide/logo.og.png' | prepend: site.baseurl }}" width="96" height="96" alt="k1lly0u" /></a>
</div>
<h3 class="userText">
<a class="username" dir="auto">k1lly0u</a>
</h3>
<span class="arrow"></span>
</div>
</div>
<div class="messageInfo primaryContent">
<div class="messageContent">
<article>
<blockquote class="messageText SelectQuoteContainer ugc baseHtml">You have calls to a method updateTrigger but the method doesn't exist <div class="messageTextEndMarker">
</div>
</blockquote>
</article>
</div>
<div class="messageMeta ToggleTriggerAnchor">
<div class="privateControls">
<span class="item muted">
<span class="authorEnd"><a class="username author" dir="auto">k1lly0u</a>,</span>
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/#post-161219' | prepend: site.baseurl }}" title="Permalink" class="datePermalink"><span class="DateTime"
title="Jan 9, 2016 at 8:35 AM">Jan 9, 2016</span></a>
</span>
</div>
<div class="publicControls">
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/#post-161219' | prepend: site.baseurl }}" title="Permalink"
class="item muted postNumber hashPermalink OverlayTrigger" data-href="posts/161219/permalink">#2</a>
</div>
</div>
</div>
</li>
<li id="post-161568" class="message" data-author="recon">
<div class="messageUserInfo">
<div class="messageUserBlock">
<div class="avatarHolder">
<span class="helper"></span>
<a class="avatar Avm" data-avatarhtml="true"><img src="{{ '/assets/styles/oxide/logo.og.png' | prepend: site.baseurl }}" width="96" height="96" alt="recon" /></a>
</div>
<h3 class="userText">
<a class="username" dir="auto">recon</a>
</h3>
<span class="arrow"></span>
</div>
</div>
<div class="messageInfo primaryContent">
<div class="messageContent">
<article>
<blockquote class="messageText SelectQuoteContainer ugc baseHtml">You could have just asked him to implement a config entry to disable all features except the overlapping <img
src="{{ '/assets/styles/default/xenforo/clear.png' | prepend: site.baseurl }}" class="mceSmilieSprite mceSmilie2" alt=";)" title="Wink ;)" /> You pretty much just copied it and removed methods, which will
basically not work.<br />
<br /> Missing/Removed method:<br />
<div class="bbCodeBlock bbCodeCode">
<div class="type">Code:</div>
{% raw %}<pre>private bool updateTrigger(BuildPrivilegeTrigger bpt) {
var col = bpt.GetComponent<UnityEngine.Collider>();
var wasTrigger = true;
if (col != null) { // should always be the case
if (col is SphereCollider && Mathf.Approximately((col as SphereCollider).radius, radius))
return false; // Already a sphere with that radius
wasTrigger = col.isTrigger;
UnityEngine.Object.Destroy(col);
}
col = bpt.gameObject.AddComponent<SphereCollider>();
col.transform.localPosition = Vector3.zero;
col.transform.localScale = Vector3.one;
(col as SphereCollider).radius = radius;
col.isTrigger = wasTrigger;
return true;
}</pre>{% endraw %}
</div>This is the part which changes the shape to a sphere. Instead of removing that,<br /> dcode could just add a bool somewhere which allows us to disable it via
config.<br /> No need to create a separate plugin for that.<br />
<br /> The bool has to be added where I marked it in the following method:<br />
<div class="bbCodeBlock bbCodeCode">
<div class="type">Code:</div>
{% raw %}<pre>[HookMethod("OnEntitySpawned")]
private void onEntitySpawned(BaseNetworkable ent) {
if (!initialized || !(ent is BuildingPrivlidge))
return; updateInfluence(ent.prefabID);// Check if shape changing is enabled in config
// {
var trig = ent.GetComponentInChildren<BuildPrivilegeTrigger>();
if (trig == null)
Interface.Oxide.NextTick(() => {
trig = ent.GetComponentInChildren<BuildPrivilegeTrigger>();
if (trig == null) {
PrintWarning("Failed to update BuildingPrivlige: Missing BuildPrivilegeTrigger");
return;
}
updateTrigger(trig);
});
else
updateTrigger(trig);
// }
}</pre>{% endraw %}
</div>Also in onServerInitialized():<br />
<div class="bbCodeBlock bbCodeCode">
<div class="type">Code:</div>
{% raw %}<pre> var bpts = UnityEngine.Object.FindObjectsOfType<BuildPrivilegeTrigger>();
// Check if shape changing is enabled in config
// {
var updated = 0;
foreach (var bpt in bpts)
if (updateTrigger(bpt))
++updated; Puts("Updated {0} of {1} cupboards to use a sphere trigger", updated, bpts.Length);
// }
</pre>{% endraw %}
</div>
<div class="messageTextEndMarker"> </div>
</blockquote>
</article>
</div>
<div class="editDate">Last edited by a moderator: <span class="DateTime" title="Jan 10, 2016 at 12:58 AM">Jan 10, 2016</span>
</div>
<div class="messageMeta ToggleTriggerAnchor">
<div class="privateControls">
<span class="item muted">
<span class="authorEnd"><a class="username author" dir="auto">recon</a>,</span>
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/#post-161568' | prepend: site.baseurl }}" title="Permalink" class="datePermalink"><span class="DateTime"
title="Jan 10, 2016 at 12:41 AM">Jan 10, 2016</span></a>
</span>
</div>
<div class="publicControls">
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/#post-161568' | prepend: site.baseurl }}" title="Permalink"
class="item muted postNumber hashPermalink OverlayTrigger" data-href="posts/161568/permalink">#3</a>
</div>
</div>
</div>
</li>
<li id="post-161621" class="message" data-author="Michael R">
<div class="messageUserInfo">
<div class="messageUserBlock">
<div class="avatarHolder">
<span class="helper"></span>
<a class="avatar Avm" data-avatarhtml="true"><img src="{{ '/assets/styles/oxide/logo.og.png' | prepend: site.baseurl }}" width="96" height="96" alt="Michael R" /></a>
</div>
<h3 class="userText">
<a class="username" dir="auto">Michael R</a>
</h3>
<span class="arrow"></span>
</div>
</div>
<div class="messageInfo primaryContent">
<div class="messageContent">
<article>
<blockquote class="messageText SelectQuoteContainer ugc baseHtml">We'll to contribute with this topic, at my server I had to remove the plugin since it started to give allowed
build or build block to random players on entire map. Suddenly appear someone with enable build everywhere. Or blocked everywhere. It happens until he dies, one time dead it
backs to normal. <div class="messageTextEndMarker"> </div>
</blockquote>
</article>
</div>
<div class="messageMeta ToggleTriggerAnchor">
<div class="privateControls">
<span class="item muted">
<span class="authorEnd"><a class="username author" dir="auto">Michael R</a>,</span>
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/#post-161621' | prepend: site.baseurl }}" title="Permalink" class="datePermalink"><span class="DateTime"
title="Jan 10, 2016 at 4:24 AM">Jan 10, 2016</span></a>
</span>
</div>
<div class="publicControls">
<a href="{{ '/threads/cupboard-overlap-ignore-cupboard-influence.14396/#post-161621' | prepend: site.baseurl }}" title="Permalink"
class="item muted postNumber hashPermalink OverlayTrigger" data-href="posts/161621/permalink">#4</a>
</div>
</div>
</div>
</li>
</ol>