PDA

View Full Version : Get s random player from each team in TF2


patronsaint
01-12-2012, 12:32
Im trying making a TF2 arena mod for a map map on my private sever where two players will fight in a 1 v 1 battle zone separated from the rest of the map.

Basically what i want to do is, upon a round start, make it randomly pick a player from both BLU and RED, announce them, then teleport them to the designated area, and change their model to a custom one. Also when one gets killed, it will announce the victor and give them a health buff for the next round.

How would I go about doing this? I know I can get it working for one player, but i cant figure out how to do it for two.

Thanks. :)

TnTSCS
01-12-2012, 13:44
Smlib has a getrandom function for getting a random player from a specified team

pheadxdll
01-12-2012, 14:24
For the random player, it's quite simple, create a large array for each team, put candidate players into the array, and pick a random index depending on how large it is. If you need examples, I bet there's a ton if you search.

Not sure how much help you need with the others.. You can set a custom player model with the "SetCustomModel" input. TeleportEntity, SetEntityHealth..

patronsaint
01-12-2012, 14:56
Smlib has a getrandom function for getting a random player from a specified team

Ill check out smlib, and see how it would be done.

For the random player, it's quite simple, create a large array for each team, put candidate players into the array, and pick a random index depending on how large it is. If you need examples, I bet there's a ton if you search.

Not sure how much help you need with the others.. You can set a custom player model with the "SetCustomModel" input. TeleportEntity, SetEntityHealth..

As for arrays, Ill do some research into using arrays. As for the others, I dont need much help on those, yet.
Also, if its not to much to ask, can you make an example for me. Although im familiar with sourcemod, ive never done anything advanced in it besides a few small, easy scripts.

TnTSCS
01-12-2012, 15:15
from SMLib (http://www.sourcemodplugins.org/pages/smlib):


/**
* Gets a random client matching the specified flags filter.
*
* @param flags Client Filter Flags (Use the CLIENTFILTER_ constants).
* @return Client Index or -1 if no client was found
*/
stock Client_GetRandom(flags=CLIENTFILTER_ALL)


CLIENTFILTERs are defined in smlib\clients.inc

[code]
#define CLIENTFILTER_ALL 0 // No filtering
#define CLIENTFILTER_BOTS ( 1 << 1 ) // Fake clients
#define CLIENTFILTER_NOBOTS ( 1 << 2 ) // No fake clients
#define CLIENTFILTER_AUTHORIZED ( 1 << 3 ) // SteamID validated
#define CLIENTFILTER_NOTAUTHORIZED ( 1 << 4 ) // SteamID not validated (yet)
#define CLIENTFILTER_ADMINS ( 1 << 5 ) // Generic Admins (or higher)
#define CLIENTFILTER_NOADMINS ( 1 << 6 ) // No generic admins
// All flags below require ingame checking (optimization)
#define CLIENTFILTER_INGAME ( 1 << 7 ) // Ingame
#define CLIENTFILTER_INGAMEAUTH ( 1 << 8 ) // Ingame & Authorized
#define CLIENTFILTER_NOTINGAME ( 1 << 9 ) // Not ingame (currently connecting)
#define CLIENTFILTER_ALIVE ( 1 << 10 ) // Alive
#define CLIENTFILTER_DEAD ( 1 << 11 ) // Dead
#define CLIENTFILTER_SPECTATORS ( 1 << 12 ) // Spectators
#define CLIENTFILTER_NOSPECTATORS ( 1 << 13 ) // No Spectators
#define CLIENTFILTER_OBSERVERS ( 1 << 14 ) // Observers
#define CLIENTFILTER_NOOBSERVERS ( 1 << 15 ) // No Observers
#define CLIENTFILTER_TEAMONE ( 1 << 16 ) // First Team (Terrorists, ...)
#define CLIENTFILTER_TEAMTWO ( 1 << 17 ) // Second Team (Counter-Terrorists, ...)
[\code]