Day of Defeat Plugins Community
This site is an archive — everything is readable and downloadable, nothing can be posted. Admin
11 posts, 4 people · 8,180 views Thread Rating: ★★★★★
closedTeam Manage
Started by MBosta on 04-16-2007, 01:13 PM
M MBosta
started this thread
Posts: 208
Threads: 30
Joined: Sep 2006
04-16-2007, 01:13 PM #1

something that would force everyone on to allies, axis, or spec. Like, amx_teamall allies, then everyone would be switched to allies, amx_teamall axis, etc. And also spec. Also, this people with Immunity would get switched too.

Wilson [29th ID]
posted here
Posts: 623
Threads: 57
Joined: Oct 2005
04-16-2007, 01:55 PM #2

I've been meaning to do something like this for a while, but I doubt I'll get around to it very soon.rnrnI encourage you, Bosta, to try it yourself. You need to loop through all the players and check their team then set their team.rnrnFirst Loop:rnrn

rnrn// Make i start at 1 (first part), then keep increasing (third part) as long rn//as it's less than or equal to 32, the max players (second part)rnfor( new i = 1; i <= 32; i++ )rn{rnrn}rnrn
rnrnThen inside the loop above, you will want to test what team each client (represented by i) is on, and switch him to the other team.rnrnUse the native from amxmodx.inc to get the team:rnrn
rnrn/* Returns team id. When length is greater then 0rn* then a name of team is set. */rnnative get_user_team(index, team[]="", len = 0);rnrn// So it will look like in the loop:rnnew team = get_user_team( i );rnrn
rnrnThen use an if statement to test which team he's on, if(team == ALLIES) and then else if(team == AXIS)rnrnThen use the native from dodfun.inc to set the client's team:rnrn
rnrn/* Sets player team and random class. Don't work for spectators. */rnnative dod_set_user_team(index,teamId,refresh=1);rnrn// Would look like in the loop:rndod_set_user_team( id, ALLIES, 1);rn// or axis, depending on the if statement right above itrnrn
rnrnAnd all this can be inside one function, declared like this:rnrn
public switch_teams() {rn   //code herern}
rnrnAnd bound to a console command like this:rnrn
public plugin_init() {rn   // First arg is the console command, second is the function it callsrn   register_clcmd( "amx_switchteams", "switch_teams" );rn}
rnrnGood luck!

M MBosta
started this thread
Posts: 208
Threads: 30
Joined: Sep 2006
04-16-2007, 02:13 PM #3

lol thanks for the quick reply Wilson, it'll take me a bit of time to understand what you just said

Wilson [29th ID]
posted here
Posts: 623
Threads: 57
Joined: Oct 2005
04-16-2007, 10:07 PM #4

Feel free to ask questions. I'd rather see you able to make this yourself than just make it for you. That whole teach a man to fish instead of give him fish or something :P

M MBosta
started this thread
Posts: 208
Threads: 30
Joined: Sep 2006
04-16-2007, 10:47 PM #5

well, i have never, ever, ever coded anything in my life, so i have no idea where to begin. I'll do a bit of research.

M MBosta
started this thread
Posts: 208
Threads: 30
Joined: Sep 2006
04-17-2007, 12:37 PM #6

um, not sure where to go from here (or if i even did this right)nn

#include <amxmodx>n#include <amxmisc>nn#define PLUGIN "New Plugin"n#define VERSION "1.0"n#define AUTHOR "Author"nnnpublic plugin_init() {n	register_plugin(Team Manager, 1.0, MBosta)n	n}nfor( new i = 1; i <= 32; i++ )n{nn}nnative get_user_team(index, team[]="", len = 0)nnew team = get_user_team( i )nnnative dod_set_user_team(index,teamId,refresh=1)nndod_set_user_team( id, ALLIES, 1)nnpublic plugin_init() {n   // First arg is the console command, second is the function it callsn   register_clcmd( "amx_switchteams", "switch_teams" );n}n
H Hood [10th MD]
posted here
Posts: 84
Threads: 7
Joined: Nov 2006
04-17-2007, 02:43 PM #7

I've got one I've coded to do this thru commands, I'll show you what I did for the spectate section:n

npublic amx_spectate(id, level, cid)n{n	if(!cmd_access(id, level, cid, 2))n		return PLUGIN_HANDLEDn	new Arg1[24]n	read_argv(1, Arg1, 23)n	new player = cmd_target(id, Arg1, 2)n	if (!player)n         {n		console_print(id, "Sorry, player %s could not be found or targetted!", Arg1)n		return PLUGIN_HANDLEDn         } n	else n	{n		dod_set_user_team(player, 3)n         }n	return PLUGIN_HANDLEDn}
nnThat does it for a single user, so if you wanted to create a command for all, the function should look, as Wilson described, like:n
npublic amx_spectateall(id, level, cid)n{n	if(!cmd_access(id, level, cid, 0)) //this would expect 0 variables passedn		return PLUGIN_HANDLEDn	new players[32], numplayers, in	get_players(players, numplayers)n        for(i=0;i<numplayers;i++)n        {n	        if(get_user_team(players[i])!=3) // Compiles fine, have not tested on server w/ this line in.n                dod_set_user_team(players[i],3)n        }n	return PLUGIN_HANDLEDn}n
nI didn't comment much here, so I'll explain below-nExplanation:n"public amx_spectateall(id,level,cid)" defines a function called amx_spectateall, which expects 3 parameters - id,level,cid - these parameters identify the admin who called the command, their access, etc.nn"if(!cmd_acces....)" this section verifies that the user is in fact valid to use this command, according to the access we defined in plugin_init()nn"new ..." this line defines an array to hold players, and 2 variables - one to store how many total players, and one as a counter in the for loop.nn"for().." this loop goes until we've reached the point in the array where it contains no more players.nn"dod_set_user_team..." this changes the team of the user, who is ID'd by where they are in the array "players[i]" and sets their team to 3 = spectate.nnnGeneral feedback on the code you posted:n1. You have too
plugin_init()
sections, put the register_clcmd in the first plugin_init().n2. In your
register_plugin
you need to put "" marks around the name, version, etc.n3. The loop you created is not in a function: if you were to use the code I have, where my function is called "amx_spectateall" then your
register_clcmd
should look like this:
register_clcmd("amx_spectateall", "amx_spectateall", ADMIN_LEVEL_KICK, "<Forces all Players to Spec>")
nThat will tell amxx that anytime an admin puts "amx_spectateall" in console, it goes to the function called "amx_spectateall". The function name is defined by that second variable (they are both the same in this case). So you need to register a function with that name, i.e.n
public amx_spectateall(id,level,cid){}
and your program goes within the {}.nn4. You need to get the array of players, like I've shown, with get_players(), otherwise your dod_set_user_team isn't going to work correctly.nnSorry, this is a little scatter brained - Bosta, feel free to talk to me on steam friends (email: mz4u2001@yahoo.com) and I will gladly help you out with working out the allies/axis sides, which can be more or less complicated depending on what you want to do. Hope this helps!

H Hood [10th MD]
posted here
Posts: 84
Threads: 7
Joined: Nov 2006
04-17-2007, 08:17 PM #8

This is what I've coded based on our talking Bosta, it is glitchy at best, I'd really like someone to look over it and make some suggestions - basically, we find out if user is alive/not, kill if they are, switch them to the team desired, and set their class (check map info for british/american), then spawn them.rnThe team switch, class switch and respawn are in a task with timer of 0.1 - these respawns sometimes work, sometimes don't - but without them, it's unreliable to just use the reinforcement counter...rnBasically, I need help with the respawning correctly.rnrnAlso, this is something I cannot control or find away around:rnSwitching people into spec works perfectly. Switching people out does not work, and is not supposed to according to dod_set_user_team()'s documentationrnrnAnyone is free to try this out - it doesn't crash my server, but it does not work well. Download the source, and read the comments for the commands:rnamx_shift <1/2/3 (allies/axis/spec)> forces all players to a teamrnamx_spectate <player>rnamx_allies <player>rnamx_axis <player>rnamx_rifle <player>rnrnThe rifle one also works fine it seems, but again no guarantees - someone please review and correct!

H Hood [10th MD]
posted here
Posts: 84
Threads: 7
Joined: Nov 2006
04-17-2007, 08:18 PM #9

Can't Post an attachment! ahhh!

M MBosta
started this thread
Posts: 208
Threads: 30
Joined: Sep 2006
04-17-2007, 10:23 PM #10

can you post the source code then

=|[76AD]|= TatsuSaisei
posted here
Posts: 794
Threads: 54
Joined: May 2005
04-18-2007, 11:48 AM #11
;5169']Can't Post an attachment! ahhh!
n ntry posting in the "test plugins" section of the forum... or the non-devs ... might just be that those areas are the only place one can attach stuff... (makes sense)

DoD Plugins Archive · Repository · Old Forum Threads · Maps · Admin · built 14 Sep 2026 00:34 UTC