-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose arrestedPlayers table globally #3234
Conversation
This should at least be a function that returns this value. Removing the local looks like a bug. |
Also, third option: use the hooks to keep your own table. Using this one is quite full of footguns: it works on steam ids, not on player objects, the players are the keys, not the values, modifying it will most likely cause things to break, it has its own behavior regarding players that disconnect. Its only reason to exist is to be an optimisation. I think it's too dangerous to expose it. Maybe just a function that returns a count, or a function that builds a num:ply table. |
Just expose an iterator function like DarkRP.iterateArrestedPlayers() |
I think this is the best solution, what do you think it should be called? |
I'm afraid that doesn't address the concerns in my latest post. It would be better to implement my idea or @Kefta's |
That could work too, could we return a copy of the table instead? Or would that not be optimal? |
I'm afraid the average DarkRP coder won't know how to use a function which returns an iterator, a table would be "simpler" to use and it's more typical in the gamemode codebase. |
A simple example on the wiki page showing |
Yeah, I was thinking the same thing. I feel like just returning the table would be the most simple. However, I'll be happy to implement whatever @FPtje believes is best. |
Let's do the iterator with documentation, though this iterator should ideally give player objects, not the steam IDs and booleans that the original table has. So ideally, the usage would be The iterator should specifically skip over SteamIDs of players that are not currently in the server. Those Steam IDs can be in there, because rejoining should get them re-arrested. With a player limit of 128, one can wonder if iterating over all players is not more efficient than iterating over the table and checking the SteamIDs, but I'll leave that as an optional exercise. |
I generally agree with the functions you exposed, but with some refactoring of the arrestedPlayers structure, linear iteration can be achieved. Lemme write up a POC |
Sorry for my inactivity, I have been busy with classes and work. I think this should be sufficient for my use case and any others I can think of. I honestly still feel like adding these functions instead of just making the table global or giving a reference to it through a function is a little over-complicated, but I think this should still work fine. Either way, it's an improvement over having to use the debug library to get a reference to the table using upvalues which most people don't know how to do. Looks good to me so far, looking forward to what @Kefta has to show. |
Thanks! if the functions have the right interface, then I think this PR is good to go, and improvements can be made later without affecting the interface.
I understand. My concern is mostly that I don't like addon authors being able to modify DarkRP internals. Having an addon write that datastructure can lead to very weird bugs that show up as errors in DarkRP code. With these functions, that mistake should not be easy. |
I would like to expose this table globally to allow for more efficient usage. Right now, if you want a table of all arrested players you must do one of the following:
Additionally, we can also make a function which returns the arrestedPlayers table and keep it local or rename it to something more unique like arrestedPlayersDarkRP or something. I'd be happy to make changes, just let me know.