I am trying to do something similar to this thread. OnEntityEnter OnEntityLeave | Oxide
The example in the thread is Lua and i can't figure out how to get it to work in C#. I have been unable to find any C# examples on how to convert the trigger into the list of players that have authorization. Does anyone know an example?
The C# example for OnEntityEnter from the Oxide API page.
void OnEntityEnter(TriggerBase trigger, BaseEntity entity) {
Puts("OnEntityEnter works!");
}
Aquiring a list of authorized players from OnEntityEnter
Discussion in 'Rust Development' started by OmegaForce, Dec 29, 2015.
-
Calytic Community Admin Community Mod
Alright, you used to have to use reflection for this but the authorizedPlayers list was made public a few patches ago. Here is some code adapted from EntityOwner which should provide you the direction you need to get started in C#.
So something like this might do what you need..Code:private List<string> GetToolCupboardUserIDs(BuildingPrivlidge cupboard) { List<string> userIDs = new List<string>(); foreach (ProtoBuf.PlayerNameID pnid in cupboard.authorizedPlayers) { userIDs.Add(pnid.userid.ToString()); } return userIDs; }
Code:void OnEntityEnter(TriggerBase trigger, BaseEntity entity) { if(entity is BuildingPrivlidge) { List<string> userids = GetToolCupboardUserIDs((BuildingPrivlidge)entity) // do something clever here } }Last edited: Dec 31, 2015 -
There was one too many parentheses on this line instead of a semicolon.
List<string> userids = GetToolCupboardUserIDs((BuildingPrivlidge)entity);
The OnEntityEnter code doesn't seem to produce any results. I have a Puts("Running"); in it and it doesn't get to it. It also appears to be using the entity instead of the trigger which I am trying to do. I tried substituting trigger for entity incase it was a typo and it just threw an error. I am trying to have the user enter the cupboards influence and then retrieving the access list for that cupboard. -
Calytic Community Admin Community Mod
Sorry, I'm not in a position to test this right now. Thanks for catching the extra parenthesis.
