搜索
查看: 4474|回复: 11

一个投票换图的插件

[复制链接]
发表于 2010-8-7 06:39:57 | 显示全部楼层 |阅读模式 来自 广西南宁
按Y输入/maps 或在控制台输入/maps可请求投票换图
当7成的玩家请求投票换图时系统会随即抽取6张地图发起投票
new Float:VoteTemp = maxpaly * 0.7; 这里改比例

  1. #include <amxmodx>
  2. #include <amxmisc>

  3. #define KeysSet_Maps_Menu (1<<9)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)

  4. new bool:LpVote[33];
  5. new VoteCoun=0;
  6. new LpMapNums;
  7. new Array:LpMapName;
  8. new Array:VoteMapName;
  9. new LpVoteCount[6];

  10. public plugin_init(){
  11.         register_plugin("请求换图", "1.0", "小坏")
  12.         register_clcmd("say /maps","Set_Maps");
  13.         register_clcmd("/maps","Set_Maps");
  14.         register_menucmd(register_menuid("Set_Maps_Menu"), KeysSet_Maps_Menu, "Pressed_Set_Maps_Menu")
  15.        
  16.        
  17.         LpMapName = ArrayCreate(32);
  18.         VoteMapName = ArrayCreate(32);
  19.         VoteCoun = 0;
  20.         return PLUGIN_CONTINUE
  21. }

  22. public plugin_cfg()
  23. {
  24.         Text(1456);
  25.         set_task(120.0,"Text",111223+456,"",0,"b");
  26.         new maps_ini_file[64];
  27.         get_configsdir(maps_ini_file, 63);
  28.         format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
  29.         if (!file_exists(maps_ini_file))
  30.                 get_cvar_string("mapcyclefile", maps_ini_file, sizeof(maps_ini_file) - 1);
  31.                
  32.         if (!file_exists(maps_ini_file))
  33.                 format(maps_ini_file, 63, "mapcycle.txt")
  34.        
  35.         load_settings(maps_ini_file)
  36. }

  37. public client_connect(id)
  38. {
  39.         LpVote[id] = false;
  40.         return PLUGIN_HANDLED       
  41. }

  42. public client_disconnect (id)
  43. {
  44.         if(LpVote[id]){
  45.                 LpVote[id] = false;
  46.                 VoteCoun--;
  47.         }
  48.         return PLUGIN_HANDLED       
  49. }

  50. public Text(id)
  51. {
  52.         client_print(0, print_chat, "按Y输入/maps 或在控制台输入/maps可请求投票换图");
  53.         client_print(0, print_chat, "当7成的玩家请求投票换图时系统会随即抽取6张地图发起投票");
  54. }

  55. public Set_Maps(id)
  56. {
  57.         if(LpVote[id])
  58.         {
  59.                 client_print(id,print_center,"你已经发起投票指令 请等待其他玩家决定!");
  60.         } else {
  61.                 LpVote[id] = true;
  62.                 VoteCoun++;
  63.                 new name[32];
  64.                 get_user_name(id,name,31);
  65.                 client_print(0, print_chat, "玩家[ %s ]请求投票换图",name);
  66.                 client_print(0, print_chat, "当7成的玩家请求投票换图时系统会随即抽取6张地图发起投票");
  67.                 new maxpaly = get_playersnum();
  68.                 new Float:VoteTemp = maxpaly * 0.7;
  69.                 if(VoteCoun >= floatround(VoteTemp)){
  70.                         client_print(0, print_chat, "超过7成的玩家请求投票换图系统随即抽取6张地图发起投票");
  71.                         new menustr[512]
  72.                         ArrayClear(VoteMapName);
  73.                         new len = format(menustr,512,"\r投票换图[AcFun.Gaming]:^n^n");
  74.                         for(new i=4; i<10;i++)
  75.                         {
  76.                                 new LpItem;
  77.                                 new tempMap[32];
  78.                                 LpItem = random_num(0,LpMapNums);
  79.                                 ArrayGetString(LpMapName, LpItem, tempMap, charsmax(tempMap));
  80.                                 len += format(menustr[len],512-len, "\r%i. \w%s^n",i,tempMap);
  81.                                 ArrayPushString(VoteMapName, tempMap);
  82.                                 LpVoteCount[i-4] = 0;
  83.                         }
  84.                         len += format(menustr[len],512-len, "\r0. \w弃权^n");
  85.                         for(new i=0;i<maxpaly;i++)
  86.                         {
  87.                                 show_menu(id, KeysSet_Maps_Menu, menustr, 20, "Set_Maps_Menu");
  88.                         }
  89.                         client_print(0, print_chat, "系统将在25秒后按投票结果进行换图");
  90.                         client_print(0, print_center, "系统将在25秒后按投票结果进行换图");
  91.                         set_task(25.0, "Maps",78917474)
  92.                 }
  93.         }
  94.        
  95. }

  96. public Pressed_Set_Maps_Menu(id, key)
  97. {
  98.         switch (key)
  99.         {
  100.                 case 3:{
  101.                         LpVoteCount[0]++;
  102.                 }
  103.                 case 4:{
  104.                         LpVoteCount[1]++;
  105.                 }
  106.                 case 5:{
  107.                         LpVoteCount[2]++;
  108.                 }
  109.                 case 6:{
  110.                         LpVoteCount[3]++;
  111.                 }
  112.                 case 7:{
  113.                         LpVoteCount[4]++;
  114.                 }
  115.                 case 8:{
  116.                         LpVoteCount[5]++;
  117.                 }
  118.         }
  119.         new name[32],tempMap[32];
  120.         get_user_name(id,name,31);
  121.         if(key == 9)
  122.         {
  123.                 tempMap= "弃权"
  124.         } else {
  125.                 ArrayGetString(VoteMapName, key-3, tempMap, charsmax(tempMap));
  126.         }
  127.         client_print(0, print_chat, "[ %s ]选择: %s",name,tempMap);
  128.         return PLUGIN_CONTINUE
  129. }


  130. public Maps()
  131. {
  132.         new a = 0;
  133.         new tempMap[33];
  134.         for (new i = 0; i < 6; ++i)
  135.         {
  136.                 if (LpVoteCount[a] < LpVoteCount[i])
  137.                 {
  138.                         a = i
  139.                 }
  140.         }
  141.         ArrayGetString(VoteMapName, a, tempMap, charsmax(tempMap));
  142.         set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
  143.         ArrayClear(VoteMapName);
  144.         return 1;
  145. }

  146. public delayedChange(mapname[])
  147.         server_cmd("changelevel %s", mapname)

  148. load_settings(filename[])
  149. {
  150.         new fp = fopen(filename, "r");
  151.        
  152.         if (!fp)
  153.         {
  154.                 return 0;
  155.         }
  156.                

  157.         new text[256];
  158.         new tempMap[32];
  159.        
  160.         while (!feof(fp))
  161.         {
  162.                 fgets(fp, text, charsmax(text));
  163.                
  164.                 if (text[0] == ';')
  165.                 {
  166.                         continue;
  167.                 }
  168.                 if (parse(text, tempMap, charsmax(tempMap)) < 1)
  169.                 {
  170.                         continue;
  171.                 }
  172.                 if (!ValidMap(tempMap))
  173.                 {
  174.                         continue;
  175.                 }
  176.                
  177.                 ArrayPushString(LpMapName, tempMap);
  178.                 LpMapNums++;
  179.         }

  180.         return 1;
  181. }

  182. stock bool:ValidMap(mapname[])
  183. {
  184.         if ( is_map_valid(mapname) )
  185.         {
  186.                 return true;
  187.         }
  188.         new len = strlen(mapname) - 4;
  189.        
  190.         if (len < 0)
  191.         {
  192.                 return false;
  193.         }
  194.         if ( equali(mapname[len], ".bsp") )
  195.         {
  196.                 mapname[len] = '^0';
  197.                 if ( is_map_valid(mapname) )
  198.                 {
  199.                         return true;
  200.                 }
  201.         }
  202.        
  203.         return false;
  204. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
发表于 2010-8-7 11:07:18 | 显示全部楼层 来自 广东清远
小坏
回复

使用道具 举报

 楼主| 发表于 2010-8-7 13:19:17 | 显示全部楼层 来自 广西南宁
2# rsdtt


干嘛???
回复

使用道具 举报

发表于 2010-8-7 19:02:33 | 显示全部楼层 来自 天津
2# rsdtt


干嘛???
lovehuai 发表于 2010-8-7 13:19

呀啦那一卡
回复

使用道具 举报

 楼主| 发表于 2010-8-7 19:24:43 | 显示全部楼层 来自 广西南宁
4# 8874323


死开基佬
贫道性取向正常
贫道只对软妹子有爱
萝莉大爱
兽耳萝莉最爱
回复

使用道具 举报

发表于 2010-8-7 21:07:15 | 显示全部楼层 来自 天津
4# 8874323


死开基佬
贫道性取向正常
贫道只对软妹子有爱
萝莉大爱
兽耳萝莉最爱
lovehuai 发表于 2010-8-7 19:24

2楼其实loli,头像是为了隐藏身份:lol
回复

使用道具 举报

发表于 2010-8-9 19:03:00 | 显示全部楼层 来自 重庆
votekick.smavotekick.smavotekick.smavotekick.sma
回复

使用道具 举报

发表于 2010-8-9 19:08:16 | 显示全部楼层 来自 重庆
votekick.smavotekick.smavotekick.smavotekick.sma
回复

使用道具 举报

发表于 2010-8-9 19:27:56 | 显示全部楼层 来自 香港
嘿嘿, 直接贴上源码很好
对潜力选手的一种优待
回复

使用道具 举报

发表于 2010-8-11 19:20:12 | 显示全部楼层 来自 香港
死开基佬
贫道性取向正常
贫道只对软妹子有爱
萝莉大爱
兽耳萝莉最爱
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表