UnixCode Posted August 1, 2011 Posted August 1, 2011 Hello all i need help at something, cause i have not tried it again. Anyway... Let's take an example: I want from a fastlist (type L2PCINSTANCE) to select 1 player , and he becomes hero.The player will be selected randomly, how can i do it? i have tried: int r; FastList <L2PcInstance> players = new FastList<L2PcInstance>(); { for(L2PcInstance p: players){ r = Rnd.get(p.getObjectId()); } for(L2PcInstance p2 :players){ if(r == p2.getObjectId()) p2.setHero(true); } but i dont think it will work, can anyone help me with this? :D Quote
0 mogo Posted August 1, 2011 Posted August 1, 2011 Generate a random number between 0 and the size of the player list minus one. Then do a players.get(the_random_number) Quote
0 UnixCode Posted August 1, 2011 Author Posted August 1, 2011 Generate a random number between 0 and the size of the player list minus one. Then do a players.get(the_random_number) : int r; FastList <L2PcInstance> players = new FastList<L2PcInstance>(); { Random dice = new Random(); int counter = 0; while(counter < 1){ r = dice.nextInt(players.size()); counter++; } L2PcInstance p = players.get(r); } ? Quote
0 adenaman Posted August 1, 2011 Posted August 1, 2011 availableMembers.get(Rnd.get(availableMembers.size())); c/p from L2Party.java Quote
0 UnixCode Posted August 2, 2011 Author Posted August 2, 2011 availableMembers.get(Rnd.get(availableMembers.size())); c/p from L2Party.java yea thanks.....i just didn't think the way. also this works(for sure above one is better): int r; FastList <L2PcInstance> players = new FastList<L2PcInstance>(); { Random dice = new Random(); int counter = 0; while(counter < 1){ r = dice.nextInt(players.size()); counter++; } L2PcInstance p = players.get®; } Quote
Question
UnixCode
Hello all i need help at something, cause i have not tried it again. Anyway...
Let's take an example:
I want from a fastlist (type L2PCINSTANCE) to select 1 player , and he becomes hero.The player will be selected randomly, how can i do it?
i have tried:
but i dont think it will work, can anyone help me with this? :D
5 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.