PDA

View Full Version : Setting player classes


strontiumdog
01-12-2007, 10:02 PM
OK...I'm stuck and confused...!
I've taken the dod_swapteams plugin and have tried to modify it so that not only does it swap but it also sets the corresponding class (kinda).

Could somebody take a look through this and tell me why if I swap a Garand class, I end up as a Panzerjager. or if I swap from a Panzerjager, I end up a Sniper.....:eek:

//
// AMX Mod X Script
//
// Developed by The AMX Mod X DoD Community
// http://www.dodplugins.net
//
// Author: [RST] FireStorm
// Edited: StrontiumDog
//

#include <amxmodx>
#include <amxmisc>
#include <dodx>
#include <dodfun>

public plugin_init(){
register_plugin("DoD Swap Teams","1.1b","AMXX DoD Team")
register_concmd("amx_swapteams","admin_swapteams",ADMIN_SLAY,"swap all players' teams")
}

public plugin_modules(){
require_module("dodx")
}

// Code by DoD Team, edited by StrontiumDog
// Code was reliant on players joining in correct team
// This just checks their team and swaps them

public admin_swapteams(id,level,cid){
if (!cmd_access(id,level,cid,1))
{
console_print(id,"[TEAMS] You need to be an Admin to use this command")
return PLUGIN_HANDLED
}
new plist_public[32],pnum_public
new pl_class

get_players(plist_public, pnum_public)

// Is the map British or American (Thanks Diamond-Optic!)
new uk = dod_get_map_info(MI_ALLIES_TEAM)

for(new i=0; i<pnum_public; i++){

// On Allied side - transfer to Axis
if(is_user_connected(plist_public[i]) == 1 && get_user_team(plist_public[i]) == 2)
{
pl_class = dod_get_user_class(plist_public[i])
dod_set_user_team(plist_public[i], 1, 1);
switch (uk)
{
case 0:
{
switch (pl_class)
{
case DODC_GARAND:
{
dod_set_user_class(plist_public[i], DODC_KAR)
}
case DODC_CARBINE:
{
dod_set_user_class(plist_public[i], DODC_K43)
}
case DODC_THOMPSON:
{
dod_set_user_class(plist_public[i], DODC_MP40)
}
case DODC_GREASE:
{
dod_set_user_class(plist_public[i], DODC_MP44)
}
case DODC_BAR:
{
dod_set_user_class(plist_public[i], DODC_MP44)
}
case DODC_SNIPER:
{
dod_set_user_class(plist_public[i], DODC_SCHARFSCHUTZE)
}
case DODC_30CAL:
{
dod_set_user_class(plist_public[i], DODC_MG42)
}
case DODC_BAZOOKA:
{
dod_set_user_class(plist_public[i], DODC_PANZERJAGER)
}
}
}
case 1:
{
switch (pl_class)
{
case DODC_ENFIELD:
{
dod_set_user_class(plist_public[i], DODC_KAR)
}
case DODC_STEN:
{
dod_set_user_class(plist_public[i], DODC_MP40)
}
case DODC_BREN:
{
dod_set_user_class(plist_public[i], DODC_MP44)
}
case DODC_MARKSMAN:
{
dod_set_user_class(plist_public[i], DODC_SCHARFSCHUTZE)
}
case DODC_PIAT:
{
dod_set_user_class(plist_public[i], DODC_PANZERJAGER)
}
}

}
}
}


// On Axis side - transfer to Allied
else if(is_user_connected(plist_public[i]) == 1 && get_user_team(plist_public[i]) == 1)
{
pl_class = dod_get_user_class(plist_public[i])
dod_set_user_team(plist_public[i], 2, 1);

switch (uk)
{
case 0:
{
switch (pl_class)
{
case DODC_KAR:
{
dod_set_user_class(plist_public[i], DODC_GARAND)
}
case DODC_K43:
{
dod_set_user_class(plist_public[i], DODC_CARBINE)
}
case DODC_MP40:
{
dod_set_user_class(plist_public[i], DODC_THOMPSON)
}
case DODC_MP44:
{
dod_set_user_class(plist_public[i], DODC_GREASE)
}
case DODC_SCHARFSCHUTZE:
{
dod_set_user_class(plist_public[i], DODC_SNIPER)
}
case DODC_FG42:
{
dod_set_user_class(plist_public[i], DODC_BAR)
}
case DODC_SCOPED_FG42:
{
dod_set_user_class(plist_public[i], DODC_BAR)
}
case DODC_MG34:
{
dod_set_user_class(plist_public[i], DODC_30CAL)
}
case DODC_MG42:
{
dod_set_user_class(plist_public[i], DODC_30CAL)
}
case DODC_PANZERJAGER:
{
dod_set_user_class(plist_public[i], DODC_BAZOOKA)
}
}
}
case 1:
{
switch (pl_class)
{
case DODC_KAR:
{
dod_set_user_class(plist_public[i], DODC_ENFIELD)
}
case DODC_K43:
{
dod_set_user_class(plist_public[i], DODC_ENFIELD)
}
case DODC_MP40:
{
dod_set_user_class(plist_public[i], DODC_STEN)
}
case DODC_MP44:
{
dod_set_user_class(plist_public[i], DODC_STEN)
}
case DODC_SCHARFSCHUTZE:
{
dod_set_user_class(plist_public[i], DODC_MARKSMAN)
}
case DODC_FG42:
{
dod_set_user_class(plist_public[i], DODC_BREN)
}
case DODC_SCOPED_FG42:
{
dod_set_user_class(plist_public[i], DODC_BREN)
}
case DODC_MG34:
{
dod_set_user_class(plist_public[i], DODC_BREN)
}
case DODC_MG42:
{
dod_set_user_class(plist_public[i], DODC_BREN)
}
case DODC_PANZERJAGER:
{
dod_set_user_class(plist_public[i], DODC_PIAT)
}
}
}
}

}
}
client_print(0,print_chat,"[TEAMS] Teams were swapped")

return PLUGIN_HANDLED
}

strontiumdog
01-13-2007, 12:05 AM
dod_set_user_team sets a random class....

Any other ways to change team without setting the random class?

diamond-optic
01-13-2007, 12:21 AM
well here is how the team manager switches a players team:

client_print(id,print_chat,"&#37;s has been switched to Axis!",playername)

if(is_user_alive(player) == 1)
{
dod_user_kill(player)
}
engclient_cmd(player,"jointeam","2")
jointeam: 1=allies 2=axis

not sure if that will help at all with setting classes... maybe after doing the jointeam command.. maybe try calling the slot# cmds and maybe it will act as if the user pressed like 1 for rifle man 2 for etc etc etc

=|[76AD]|= TatsuSaisei
01-13-2007, 02:04 AM
your code works fine... the problem is a couple of "typos"

// On Allied side - transfer to Axis
if(is_user_connected(plist_public[i]) == 1 && get_user_team(plist_public[i]) == 2)
{
pl_class = dod_get_user_class(plist_public[i])
dod_set_user_team(plist_public[i], 1, 1);
SHOULD BE...
// On Allied side - transfer to Axis
if(is_user_connected(plist_public[i]) == 1 && get_user_team(plist_public[i]) == 1)
{
pl_class = dod_get_user_class(plist_public[i])
dod_set_user_team(plist_public[i], 2, 1);



// On Axis side - transfer to Allied
else if(is_user_connected(plist_public[i]) == 1 && get_user_team(plist_public[i]) == 1)
{
pl_class = dod_get_user_class(plist_public[i])
dod_set_user_team(plist_public[i], 2, 1);
SHOULD BE...

// On Axis side - transfer to Allied
else if(is_user_connected(plist_public[i]) == 1 && get_user_team(plist_public[i]) == 2)
{
pl_class = dod_get_user_class(plist_public[i])
dod_set_user_team(plist_public[i], 1, 1);

strontiumdog
01-13-2007, 04:30 AM
Thanks D-O and Tatsu (yup comments didn't match code!)

However, the problem seems to be when a player is changed team with dod_set_user_team a random class is selected for them. What I'm trying to do is to find the player's class before changing teams (and getting the random class set), and then set a new class once the team has been swapped over.

So say an American player with a Garand is swapped over to Axis, they get a corresponding Kar. Or an MP44 gets swapped over to a BAR.

Right now, when the plugin is run, players just get random weapons when they respawn. Interestingly enough, after dying, they then get the weapon class. So is there some refresh thingy I'm missing?

strontiumdog
01-13-2007, 04:31 AM
Oh...D-O...I tried the slot1/slot2 commands but these had no effect....thanks anyway!

=|[76AD]|= TatsuSaisei
01-13-2007, 02:49 PM
Thanks D-O and Tatsu (yup comments didn't match code!)

However, the problem seems to be when a player is changed team with dod_set_user_team a random class is selected for them. What I'm trying to do is to find the player's class before changing teams (and getting the random class set), and then set a new class once the team has been swapped over.

So say an American player with a Garand is swapped over to Axis, they get a corresponding Kar. Or an MP44 gets swapped over to a BAR.

Right now, when the plugin is run, players just get random weapons when they respawn. Interestingly enough, after dying, they then get the weapon class. So is there some refresh thingy I'm missing?

your code DOES work now... it works flawless for me when I tested it making the 4 minor corrections... by itself executing a dod_set_user_team will assign a player to a random class, but immediately following all that you then have that code that assigns a class based on the old detected class.... what you want IS working for me... I am going to test one more time to be sure and then I will simply post the code I was using incase it varies in any degree from yours posted....

http://customdod.com/movies/swapteams1.avi (right click and Save target as...)

strontiumdog
01-13-2007, 04:24 PM
w00T!

Thank you Tatsu!
Excellent...works a treat. :D

http://www.dodplugins.net/forums/showthread.php?t=608