Raised This Month: $ Target: $400
 0% 

Pick Random Player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flynn
Senior Member
Join Date: Sep 2009
Old 09-28-2009 , 23:12   Re: Pick Random Player
Reply With Quote #1

Depends on context when you do it. I had several similar things (but for random weapons spawning within a given list) and punishing a random player when a team refused to stop camping.

I would declare two arrays (set to the size of MAXPLAYERS) and then do stacking operations. Kinda like how bl4nk suggested...
Code:
#include <sourcemod>
//Returns highest int found
public StackQueryHigh(const Stack[],const End)
{
 decl I,X;
 for(I = 0, X = End;Stack[I] != End;I++)
 {
  if(Stack[I] > X)
  {
   X = Stack[I];
  }
 }
 return X;
}
public StackClear(Stack[],const End)
{
 decl I;
 for(I = 0;Stack[I] != End;)
 {
  Stack[I] = -1;
  I++;
 }
 return;
}
public StackCount(const Stack[],const End)
{
 decl I;
 for(I = 0;Stack[I] != End;)
 {
  I++;
 }
 return I; 
}
public StackEnd(const Stack[],const End)
{
 decl I;
 for(I = 0;Stack[I] != End;)
 {
  I++;
 }
 return I;
}
public StackFind(const Stack[],const Item,const End)
{
 decl I;
 for(I = 0;Stack[I] != End && Stack[I] != Item;)
 {
  I++;
 }
 
 if(Stack[I] == Item)
 {
  return I;
 }
 return -1;
}
public StackAdd(Stack[],const Item,const End)
{
 if(StackFind(Stack,Item,End) == -1)
 {
  Stack[StackEnd(Stack,End)] = Item;
  return true;
 }
 return false;
}
public StackRemove(Stack[],const Item,const End)
{
 new Find = StackFind(Stack,Item,End);
 if(Find == -1)
 {
  return false;
 }
 
 new EndItem = (StackEnd(Stack,End)-1);
 Stack[Find] = Stack[EndItem];
 Stack[EndItem] = End;
 return true;
}
Add them to the specific team stack when you want them to be selected, and remove them from it when they leave or change team. Get the stack count to return how many items and use that to set the max int of the random generator.

Once you generate a number, you deference the array to get the stored client.
Code:
new Target = Blue[RandomNumber];
If it returns 0, then you know it's a dud. I don't imagine you would want to use this, but I'm presenting it in-case it's of any use, and this has worked for me before.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 10-08-2009 , 11:46   Re: Pick Random Player
Reply With Quote #2

id really like to try and implement something like that flynn. although i dont fully understand it . im not happy with just picking a random player. i want to narrow it down a bit. could i use your suggestion to narrow the choices and keep track of who has been choosen?

Last edited by meng; 10-08-2009 at 23:07.
meng is offline
Send a message via Yahoo to meng
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode