I want to select a random player in the world though I'm not sure how to selet the player I realise I must loopthen add the random proc yet I have no idea how to do this.
Thanks in advance
- Miran94
ID:164640
![]() May 11 2007, 3:22 am
|
|
Why create a list and use pick()? Just do the randomization yourself.
proc/get_random_player() |
Kaioken wrote:
Why create a list and use pick()? Just do the randomization yourself. Because with your method there is a 50/50 chance that the first client will always be picked. I'm not all that great with numbers, but say you have a list of 20 clients. Each client further down in the list will have a progressively higher chance of never being picked. Jp's method works around this by getting all the clients first, then picking one. |
You can change the odds, but either way, it does the job; its random. The client order is practically random as well; so it matters even less.
|
mob So this is how it should work? also I didn't like your 50 50 idea Kioken sorry. - Miran94 |
No, your idea won't work.
Also, according to Kaioken and Dark Wizard, when you for(var/client/c) the order of clients is completely random. I haven't actually tested this and don't believe it to be logical, I'd like to prove it but too lazy to get on all five of my keys at a time. Unless someone wants to disprove it, I'd just go with their method. Here's the problem with yours though. 1) The proc is returning after the first for. Anything you add underneath that return line is completely ignored. The intended usage of that proc was to use it to get the random client inside another proc. 2) You're building a list of clients and then checking it for mobs. A mob is not the same as a client. The reason why everyone told you to do clients is because you just want players, and if you just did all mobs then you'd have npcs and stuff too. |
Tested
Test Code: mob/verb/testclients() Test Process: Logged in with all 5 of my keys, ran testclients() 10 times. Output was identical every time. Client list order: 1 Zagreus (0) 2 Van Fanel (0) 3 Derax (0) 4 Deedlit (0) 5 Deraxian (0) Results of randomclient(): Client list order: 1 Zagreus (43) 2 Van Fanel (27) 3 Derax (14) 4 Deedlit (8) 5 Deraxian (8) Results after a few more tries to just to make sure Zagreus isn't REALLY lucky. :) Client list order: 1 Zagreus (148) 2 Van Fanel (70) 3 Derax (39) 4 Deedlit (20) 5 Deraxian (23) It appears to be doing exactly what I said it would. If you truly want a random player picker, Jp's method is much more accurate. By the way, order appears to be in which order they connected to the server. |
Zagreus wrote:
By the way, order appears to be in which order they connected to the server. But of course. The looping order depends on the internal ID I believe, so whatever is created first is looped first. And so, in a populated game, you're bound to see this much less with objects taking up and freeing IDs between clients and players logging in and out. Definitely, I've seen your point from the beginning, but it isn't significant. Again, you could modify the randomization to whatever chance you want, you could make the chance higher every next iteration and whatnot, I just posted an example. You can never get a truly random result, especially not with BYOND's random number generator which tends to repeat anyway; also some of BYOND's built-in random functions favor some values as well. It's not that important, its still random. And again, whoever has less chance to be chosen is also virtually random. |
Note that that'll return a client.