hlmod.hu
https://hlmod.hu/

Team Join Management
https://hlmod.hu/viewtopic.php?f=10&t=5469
Oldal: 1 / 1

Szerző:  tson_ [2012.07.29. 22:01 ]
Hozzászólás témája:  Team Join Management

Ebbe valaki bír rakni egy ki-be kapcsoló cvart?
Kód:
  1. #include <amxmodx>

  2.  

  3. enum

  4. {

  5.         TEAM_NONE = 0,

  6.         TEAM_T,

  7.         TEAM_CT,

  8.         TEAM_SPEC,

  9.        

  10.         MAX_TEAMS

  11. };

  12. new const g_cTeamChars[MAX_TEAMS] =

  13. {

  14.         'U',

  15.         'T',

  16.         'C',

  17.         'S'

  18. };

  19. new const g_sTeamNums[MAX_TEAMS][] =

  20. {

  21.         "0",

  22.         "1",

  23.         "2",

  24.         "3"

  25. };

  26. new const g_sClassNums[MAX_TEAMS][] =

  27. {

  28.         "1",

  29.         "2",

  30.         "3",

  31.         "4"

  32. };

  33.  

  34. // Old Style Menus

  35. stock const FIRST_JOIN_MSG[] =          "#Team_Select";

  36. stock const FIRST_JOIN_MSG_SPEC[] =     "#Team_Select_Spect";

  37. stock const INGAME_JOIN_MSG[] =         "#IG_Team_Select";

  38. stock const INGAME_JOIN_MSG_SPEC[] =    "#IG_Team_Select_Spect";

  39. const iMaxLen = sizeof(INGAME_JOIN_MSG_SPEC);

  40.  

  41. // New VGUI Menus

  42. stock const VGUI_JOIN_TEAM_NUM =                2;

  43.  

  44. new g_iTeam[33];

  45. new g_iPlayers[MAX_TEAMS];

  46.  

  47. new tjm_join_team;

  48. new tjm_switch_team;

  49. new tjm_class[MAX_TEAMS];

  50. new tjm_block_change;

  51.  

  52. public plugin_init()

  53. {

  54.         register_plugin("Team Join Management", "0.3", "Exolent");

  55.         register_event("TeamInfo", "event_TeamInfo", "a");

  56.         register_message(get_user_msgid("ShowMenu"), "message_ShowMenu");

  57.         register_message(get_user_msgid("VGUIMenu"), "message_VGUIMenu");

  58.         tjm_join_team = register_cvar("tjm_join_team", "1");

  59.         tjm_switch_team = register_cvar("tjm_switch_team", "1");

  60.         tjm_class[TEAM_T] = register_cvar("tjm_class_t", "2");

  61.         tjm_class[TEAM_CT] = register_cvar("tjm_class_ct", "4");

  62.         tjm_block_change = register_cvar("tjm_block_change", "1");

  63. }

  64.  

  65. public plugin_cfg()

  66. {

  67.         set_cvar_num("mp_limitteams", 32);

  68.         set_cvar_num("sv_restart", 1);

  69. }

  70.  

  71. public client_disconnect(id)

  72. {

  73.         remove_task(id);

  74. }

  75.  

  76. public event_TeamInfo()

  77. {

  78.         new id = read_data(1);

  79.         new sTeam[32], iTeam;

  80.         read_data(2, sTeam, sizeof(sTeam) - 1);

  81.         for(new i = 0; i < MAX_TEAMS; i++)

  82.         {

  83.                 if(g_cTeamChars[i] == sTeam[0])

  84.                 {

  85.                         iTeam = i;

  86.                         break;

  87.                 }

  88.         }

  89.        

  90.         if(g_iTeam[id] != iTeam)

  91.         {

  92.                 g_iPlayers[g_iTeam[id]]--;

  93.                 g_iTeam[id] = iTeam;

  94.                 g_iPlayers[iTeam]++;

  95.         }

  96. }

  97.  

  98. public message_ShowMenu(iMsgid, iDest, id)

  99. {

  100.         static sMenuCode[iMaxLen];

  101.         get_msg_arg_string(4, sMenuCode, sizeof(sMenuCode) - 1);

  102.         if(equal(sMenuCode, FIRST_JOIN_MSG) || equal(sMenuCode, FIRST_JOIN_MSG_SPEC))

  103.         {

  104.                 if(should_autojoin(id))

  105.                 {

  106.                         set_autojoin_task(id, iMsgid);

  107.                         return PLUGIN_HANDLED;

  108.                 }

  109.         }

  110.         else if(equal(sMenuCode, INGAME_JOIN_MSG) || equal(sMenuCode, INGAME_JOIN_MSG_SPEC))

  111.         {

  112.                 if(should_autoswitch(id))

  113.                 {

  114.                         set_autoswitch_task(id, iMsgid);

  115.                         return PLUGIN_HANDLED;

  116.                 }

  117.                 else if(get_pcvar_num(tjm_block_change))

  118.                 {

  119.                         return PLUGIN_HANDLED;

  120.                 }

  121.         }

  122.         return PLUGIN_CONTINUE;

  123. }

  124.  

  125. public message_VGUIMenu(iMsgid, iDest, id)

  126. {

  127.         if(get_msg_arg_int(1) != VGUI_JOIN_TEAM_NUM)

  128.         {

  129.                 return PLUGIN_CONTINUE;

  130.         }

  131.        

  132.         if(should_autojoin(id))

  133.         {

  134.                 set_autojoin_task(id, iMsgid);

  135.                 return PLUGIN_HANDLED;

  136.         }

  137.         else if(should_autoswitch(id))

  138.         {

  139.                 set_autoswitch_task(id, iMsgid);

  140.                 return PLUGIN_HANDLED;

  141.         }

  142.         else if((TEAM_NONE < g_iTeam[id] < TEAM_SPEC) && get_pcvar_num(tjm_block_change))

  143.         {

  144.                 return PLUGIN_HANDLED;

  145.         }

  146.         return PLUGIN_CONTINUE;

  147. }

  148.  

  149. public task_Autojoin(iParam[], id)

  150. {

  151.         new iTeam = get_new_team(get_pcvar_num(tjm_join_team));

  152.         if(iTeam != -1)

  153.         {

  154.                 handle_join(id, iParam[0], iTeam);

  155.         }

  156. }

  157.  

  158. public task_Autoswitch(iParam[], id)

  159. {

  160.         new iTeam = get_switch_team(id);

  161.         if(iTeam != -1)

  162.         {

  163.                 handle_join(id, iParam[0], iTeam);

  164.         }

  165. }

  166.  

  167. stock handle_join(id, iMsgid, iTeam)

  168. {

  169.         new iMsgBlock = get_msg_block(iMsgid);

  170.         set_msg_block(iMsgid, BLOCK_SET);

  171.        

  172.         engclient_cmd(id, "jointeam", g_sTeamNums[iTeam]);

  173.        

  174.         new iClass = get_team_class(iTeam);

  175.         if(1 <= iClass <= 4)

  176.         {

  177.                 engclient_cmd(id, "joinclass", g_sClassNums[iClass - 1]);

  178.         }

  179.         set_msg_block(iMsgid, iMsgBlock);

  180. }

  181.  

  182. stock get_new_team(iCvar)

  183. {

  184.         switch(iCvar)

  185.         {

  186.                 case 1:

  187.                 {

  188.                         return TEAM_T;

  189.                 }

  190.                 case 2:

  191.                 {

  192.                         return TEAM_CT;

  193.                 }

  194.                 case 3:

  195.                 {

  196.                         return TEAM_SPEC;

  197.                 }

  198.                 case 4:

  199.                 {

  200.                         new iTCount = g_iPlayers[TEAM_T];

  201.                         new iCTCount = g_iPlayers[TEAM_CT];

  202.                         if(iTCount < iCTCount)

  203.                         {

  204.                                 return TEAM_T;

  205.                         }

  206.                         else if(iTCount > iCTCount)

  207.                         {

  208.                                 return TEAM_CT;

  209.                         }

  210.                         else

  211.                         {

  212.                                 return random_num(TEAM_T, TEAM_CT);

  213.                         }

  214.                 }

  215.         }

  216.         return -1;

  217. }

  218.  

  219. stock get_switch_team(id)

  220. {

  221.         new iTeam;

  222.        

  223.         new iTCount = g_iPlayers[TEAM_T];

  224.         new iCTCount = g_iPlayers[TEAM_CT];

  225.         switch(g_iTeam[id])

  226.         {

  227.                 case TEAM_T: iTCount--;

  228.                 case TEAM_CT: iCTCount--;

  229.         }

  230.         if(iTCount < iCTCount)

  231.         {

  232.                 iTeam = TEAM_T;

  233.         }

  234.         else if(iTCount > iCTCount)

  235.         {

  236.                 iTeam = TEAM_CT;

  237.         }

  238.         else

  239.         {

  240.                 iTeam = random_num(TEAM_T, TEAM_CT);

  241.         }

  242.        

  243.         if(iTeam != g_iTeam[id])

  244.         {

  245.                 return iTeam;

  246.         }

  247.        

  248.         return -1;

  249. }

  250.  

  251. stock get_team_class(iTeam)

  252. {

  253.         new iClass;

  254.         if(TEAM_NONE < iTeam < TEAM_SPEC)

  255.         {

  256.                 iClass = get_pcvar_num(tjm_class[iTeam]);

  257.                 if(iClass < 1 || iClass > 4)

  258.                 {

  259.                         iClass = random_num(1, 4);

  260.                 }

  261.         }

  262.         return iClass;

  263. }

  264.  

  265. stock set_autojoin_task(id, iMsgid)

  266. {

  267.         new iParam[2];

  268.         iParam[0] = iMsgid;

  269.         set_task(0.1, "task_Autojoin", id, iParam, sizeof(iParam));

  270. }

  271.  

  272. stock set_autoswitch_task(id, iMsgid)

  273. {

  274.         new iParam[2];

  275.         iParam[0] = iMsgid;

  276.         set_task(0.1, "task_Autoswitch", id, iParam, sizeof(iParam));

  277. }

  278.  

  279. stock bool:should_autojoin(id)

  280. {

  281.         return ((5 > get_pcvar_num(tjm_join_team) > 0) && is_user_connected(id) && !(TEAM_NONE < g_iTeam[id] < TEAM_SPEC) && !task_exists(id));

  282. }

  283.  

  284. stock bool:should_autoswitch(id)

  285. {

  286.         return (get_pcvar_num(tjm_switch_team) && is_user_connected(id) && (TEAM_NONE < g_iTeam[id] < TEAM_SPEC) && !task_exists(id));

  287. }

  288.  

Szerző:  IrOn [2012.07.29. 22:05 ]
Hozzászólás témája:  Re: Team Join Management

Kód:
  1. #include <amxmodx>

  2.  

  3. enum

  4. {

  5.         TEAM_NONE = 0,

  6.         TEAM_T,

  7.         TEAM_CT,

  8.         TEAM_SPEC,

  9.        

  10.         MAX_TEAMS

  11. };

  12. new const g_cTeamChars[MAX_TEAMS] =

  13. {

  14.         'U',

  15.         'T',

  16.         'C',

  17.         'S'

  18. };

  19. new const g_sTeamNums[MAX_TEAMS][] =

  20. {

  21.         "0",

  22.         "1",

  23.         "2",

  24.         "3"

  25. };

  26. new const g_sClassNums[MAX_TEAMS][] =

  27. {

  28.         "1",

  29.         "2",

  30.         "3",

  31.         "4"

  32. };

  33.  

  34. // Old Style Menus

  35. stock const FIRST_JOIN_MSG[] =          "#Team_Select";

  36. stock const FIRST_JOIN_MSG_SPEC[] =     "#Team_Select_Spect";

  37. stock const INGAME_JOIN_MSG[] =         "#IG_Team_Select";

  38. stock const INGAME_JOIN_MSG_SPEC[] =    "#IG_Team_Select_Spect";

  39. const iMaxLen = sizeof(INGAME_JOIN_MSG_SPEC);

  40.  

  41. // New VGUI Menus

  42. stock const VGUI_JOIN_TEAM_NUM =                2;

  43.  

  44. new g_iTeam[33];

  45. new g_iPlayers[MAX_TEAMS];

  46.  

  47. new tjm_join_team;

  48. new tjm_switch_team;

  49. new tjm_class[MAX_TEAMS];

  50. new tjm_block_change;

  51. new kibekapcsolo;

  52.  

  53. public plugin_init()

  54. {

  55.         register_plugin("Team Join Management", "0.3", "Exolent");

  56.         register_event("TeamInfo", "event_TeamInfo", "a");

  57.         register_message(get_user_msgid("ShowMenu"), "message_ShowMenu");

  58.         register_message(get_user_msgid("VGUIMenu"), "message_VGUIMenu");

  59.         tjm_join_team = register_cvar("tjm_join_team", "1");

  60.         tjm_switch_team = register_cvar("tjm_switch_team", "1");

  61.         tjm_class[TEAM_T] = register_cvar("tjm_class_t", "2");

  62.         tjm_class[TEAM_CT] = register_cvar("tjm_class_ct", "4");

  63.         tjm_block_change = register_cvar("tjm_block_change", "1");

  64.         kibekapcsolo = register_cvar("ki-be", "1");

  65. }

  66.  

  67. public plugin_cfg()

  68. {

  69.         if(get_pcvar_num(kibekapcsolo) == 1)

  70.         {

  71.                 set_cvar_num("mp_limitteams", 32);

  72.                 set_cvar_num("sv_restart", 1);

  73.         }

  74. }

  75.  

  76. public client_disconnect(id)

  77. {

  78.         if(get_pcvar_num(kibekapcsolo) == 1)

  79.         {

  80.                 remove_task(id);

  81.         }

  82. }

  83.  

  84. public event_TeamInfo()

  85. {

  86.         if(get_pcvar_num(kibekapcsolo) == 1)

  87.         {

  88.                 new id = read_data(1);

  89.                 new sTeam[32], iTeam;

  90.                 read_data(2, sTeam, sizeof(sTeam) - 1);

  91.                 for(new i = 0; i < MAX_TEAMS; i++)

  92.                 {

  93.                         if(g_cTeamChars[i] == sTeam[0])

  94.                         {

  95.                                 iTeam = i;

  96.                                 break;

  97.                         }

  98.                 }

  99.                

  100.                 if(g_iTeam[id] != iTeam)

  101.                 {

  102.                         g_iPlayers[g_iTeam[id]]--;

  103.                         g_iTeam[id] = iTeam;

  104.                         g_iPlayers[iTeam]++;

  105.                 }

  106.         }

  107. }

  108.  

  109. public message_ShowMenu(iMsgid, iDest, id)

  110. {

  111.         if(get_pcvar_num(kibekapcsolo) == 1)

  112.         {

  113.                 static sMenuCode[iMaxLen];

  114.                 get_msg_arg_string(4, sMenuCode, sizeof(sMenuCode) - 1);

  115.                 if(equal(sMenuCode, FIRST_JOIN_MSG) || equal(sMenuCode, FIRST_JOIN_MSG_SPEC))

  116.                 {

  117.                         if(should_autojoin(id))

  118.                         {

  119.                                 set_autojoin_task(id, iMsgid);

  120.                                 return PLUGIN_HANDLED;

  121.                         }

  122.                 }

  123.                 else if(equal(sMenuCode, INGAME_JOIN_MSG) || equal(sMenuCode, INGAME_JOIN_MSG_SPEC))

  124.                 {

  125.                         if(should_autoswitch(id))

  126.                         {

  127.                                 set_autoswitch_task(id, iMsgid);

  128.                                 return PLUGIN_HANDLED;

  129.                         }

  130.                         else if(get_pcvar_num(tjm_block_change))

  131.                         {

  132.                                 return PLUGIN_HANDLED;

  133.                         }

  134.                 }

  135.         }

  136.         return PLUGIN_CONTINUE;

  137. }

  138.  

  139. public message_VGUIMenu(iMsgid, iDest, id)

  140. {

  141.         if(get_pcvar_num(kibekapcsolo) == 1)

  142.         {

  143.                 if(get_msg_arg_int(1) != VGUI_JOIN_TEAM_NUM)

  144.                 {

  145.                         return PLUGIN_CONTINUE;

  146.                 }

  147.                

  148.                 if(should_autojoin(id))

  149.                 {

  150.                         set_autojoin_task(id, iMsgid);

  151.                         return PLUGIN_HANDLED;

  152.                 }

  153.                 else if(should_autoswitch(id))

  154.                 {

  155.                         set_autoswitch_task(id, iMsgid);

  156.                         return PLUGIN_HANDLED;

  157.                 }

  158.                 else if((TEAM_NONE < g_iTeam[id] < TEAM_SPEC) && get_pcvar_num(tjm_block_change))

  159.                 {

  160.                         return PLUGIN_HANDLED;

  161.                 }

  162.         }

  163.         return PLUGIN_CONTINUE;

  164. }

  165.  

  166. public task_Autojoin(iParam[], id)

  167. {

  168.         if(get_pcvar_num(kibekapcsolo) == 1)

  169.         {

  170.                 new iTeam = get_new_team(get_pcvar_num(tjm_join_team));

  171.                 if(iTeam != -1)

  172.                 {

  173.                         handle_join(id, iParam[0], iTeam);

  174.                 }

  175.         }

  176. }

  177.  

  178. public task_Autoswitch(iParam[], id)

  179. {

  180.         if(get_pcvar_num(kibekapcsolo) == 1)

  181.         {

  182.                 new iTeam = get_switch_team(id);

  183.                 if(iTeam != -1)

  184.                 {

  185.                         handle_join(id, iParam[0], iTeam);

  186.                 }

  187.         }

  188. }

  189.  

  190. stock handle_join(id, iMsgid, iTeam)

  191. {

  192.         new iMsgBlock = get_msg_block(iMsgid);

  193.         set_msg_block(iMsgid, BLOCK_SET);

  194.        

  195.         engclient_cmd(id, "jointeam", g_sTeamNums[iTeam]);

  196.        

  197.         new iClass = get_team_class(iTeam);

  198.         if(1 <= iClass <= 4)

  199.         {

  200.                 engclient_cmd(id, "joinclass", g_sClassNums[iClass - 1]);

  201.         }

  202.         set_msg_block(iMsgid, iMsgBlock);

  203. }

  204.  

  205. stock get_new_team(iCvar)

  206. {

  207.         switch(iCvar)

  208.         {

  209.                 case 1:

  210.                 {

  211.                         return TEAM_T;

  212.                 }

  213.                 case 2:

  214.                 {

  215.                         return TEAM_CT;

  216.                 }

  217.                 case 3:

  218.                 {

  219.                         return TEAM_SPEC;

  220.                 }

  221.                 case 4:

  222.                 {

  223.                         new iTCount = g_iPlayers[TEAM_T];

  224.                         new iCTCount = g_iPlayers[TEAM_CT];

  225.                         if(iTCount < iCTCount)

  226.                         {

  227.                                 return TEAM_T;

  228.                         }

  229.                         else if(iTCount > iCTCount)

  230.                         {

  231.                                 return TEAM_CT;

  232.                         }

  233.                         else

  234.                         {

  235.                                 return random_num(TEAM_T, TEAM_CT);

  236.                         }

  237.                 }

  238.         }

  239.         return -1;

  240. }

  241.  

  242. stock get_switch_team(id)

  243. {

  244.         new iTeam;

  245.        

  246.         new iTCount = g_iPlayers[TEAM_T];

  247.         new iCTCount = g_iPlayers[TEAM_CT];

  248.         switch(g_iTeam[id])

  249.         {

  250.                 case TEAM_T: iTCount--;

  251.                 case TEAM_CT: iCTCount--;

  252.         }

  253.         if(iTCount < iCTCount)

  254.         {

  255.                 iTeam = TEAM_T;

  256.         }

  257.         else if(iTCount > iCTCount)

  258.         {

  259.                 iTeam = TEAM_CT;

  260.         }

  261.         else

  262.         {

  263.                 iTeam = random_num(TEAM_T, TEAM_CT);

  264.         }

  265.        

  266.         if(iTeam != g_iTeam[id])

  267.         {

  268.                 return iTeam;

  269.         }

  270.        

  271.         return -1;

  272. }

  273.  

  274. stock get_team_class(iTeam)

  275. {

  276.         new iClass;

  277.         if(TEAM_NONE < iTeam < TEAM_SPEC)

  278.         {

  279.                 iClass = get_pcvar_num(tjm_class[iTeam]);

  280.                 if(iClass < 1 || iClass > 4)

  281.                 {

  282.                         iClass = random_num(1, 4);

  283.                 }

  284.         }

  285.         return iClass;

  286. }

  287.  

  288. stock set_autojoin_task(id, iMsgid)

  289. {

  290.         new iParam[2];

  291.         iParam[0] = iMsgid;

  292.         set_task(0.1, "task_Autojoin", id, iParam, sizeof(iParam));

  293. }

  294.  

  295. stock set_autoswitch_task(id, iMsgid)

  296. {

  297.         new iParam[2];

  298.         iParam[0] = iMsgid;

  299.         set_task(0.1, "task_Autoswitch", id, iParam, sizeof(iParam));

  300. }

  301.  

  302. stock bool:should_autojoin(id)

  303. {

  304.         return ((5 > get_pcvar_num(tjm_join_team) > 0) && is_user_connected(id) && !(TEAM_NONE < g_iTeam[id] < TEAM_SPEC) && !task_exists(id));

  305. }

  306.  

  307. stock bool:should_autoswitch(id)

  308. {

  309.         return (get_pcvar_num(tjm_switch_team) && is_user_connected(id) && (TEAM_NONE < g_iTeam[id] < TEAM_SPEC) && !task_exists(id));

  310. }

  311.  

Oldal: 1 / 1 Minden időpont UTC+02:00 időzóna szerinti
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/