Hi there.
I am trying to figure out how to check if players have been added to white list for codelocks.
Reason is that for the mod I am currently working on I want to check if they have access before running the mod to stop consumption of resources.
I have been going through the DLLs to see what is available but so far all I found was this and sadly the list was private, Please can someone assist me, cheers.
Code:Assembly-CSharp.dll internal List<ulong> whitelistPlayers = new List<ulong>(); public override bool OnTryToOpen(BasePlayer player) { object[] objArray = new object[] { player, this }; object obj = Interface.CallHook("CanUseDoor", objArray); if (obj as bool) { return (bool)obj; } if (!base.IsLocked()) { return true; } if (this.whitelistPlayers.Contains(player.userID)) { this.DoEffect(this.effectUnlocked.resourcePath); return true; } this.DoEffect(this.effectDenied.resourcePath); return false; }
Check if player has access to codelock
Discussion in 'Rust Development' started by Alphawar, Dec 4, 2015.
-
Calytic Community Admin Community Mod
Try using reflection, maybe something like this..
Code:System.Reflection.FieldInfo propertyInfo = typeof(CodeLock).GetField("whitelistPlayers", BindingFlags.NonPublic | BindingFlags.Instance); List<ulong> whitelist = (List<ulong>)propertyInfo.GetValue(myCodeLock); whitelist.Add(player.userID); propertyInfo.SetValue(myCodeLock, whitelist); -
Thank you for your help.
I am having trouble integrating this.
I have included this in the segment "object CanUseDoor(BasePlayer player, CodeLock door)"
What I want to know how would I do a variable like:
[DOUBLEPOST=1449348480,1449289835][/DOUBLEPOST]@Calytic could I please get some more assistance?Code:if (Targetdoor whitelist contain (player.userid)) return null -
Calytic Community Admin Community Mod
Untested, but here..
Code:System.Reflection.FieldInfo whitelistPlayers = typeof(CodeLock).GetField("whitelistPlayers", BindingFlags.NonPublic | BindingFlags.Instance);object CanUseDoor(BasePlayer player, BaseLock codeLock) { if (codeLock is CodeLock) { List<ulong> whitelist = (List<ulong>)whitelistPlayers.GetValue(codeLock); if (whitelist.Contains(player.userID)) { return null; } } return false; } -
Thank you for that, To me this indeed makes more sense, I will try it out tonight and let you know. If it works ill shout you a beer
(somehow)
[DOUBLEPOST=1449566678,1449439304][/DOUBLEPOST]Thank you Thank you Thank you Thank you.
Just did some quick tests and it seemed to work perfectly
Your name will forever be marked in my mod.
