|
按Y输入/maps 或在控制台输入/maps可请求投票换图
当7成的玩家请求投票换图时系统会随即抽取6张地图发起投票
new Float:VoteTemp = maxpaly * 0.7; 这里改比例
- #include <amxmodx>
- #include <amxmisc>
- #define KeysSet_Maps_Menu (1<<9)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)
- new bool:LpVote[33];
- new VoteCoun=0;
- new LpMapNums;
- new Array:LpMapName;
- new Array:VoteMapName;
- new LpVoteCount[6];
- public plugin_init(){
- register_plugin("请求换图", "1.0", "小坏")
- register_clcmd("say /maps","Set_Maps");
- register_clcmd("/maps","Set_Maps");
- register_menucmd(register_menuid("Set_Maps_Menu"), KeysSet_Maps_Menu, "Pressed_Set_Maps_Menu")
-
-
- LpMapName = ArrayCreate(32);
- VoteMapName = ArrayCreate(32);
- VoteCoun = 0;
- return PLUGIN_CONTINUE
- }
- public plugin_cfg()
- {
- Text(1456);
- set_task(120.0,"Text",111223+456,"",0,"b");
- new maps_ini_file[64];
- get_configsdir(maps_ini_file, 63);
- format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
- if (!file_exists(maps_ini_file))
- get_cvar_string("mapcyclefile", maps_ini_file, sizeof(maps_ini_file) - 1);
-
- if (!file_exists(maps_ini_file))
- format(maps_ini_file, 63, "mapcycle.txt")
-
- load_settings(maps_ini_file)
- }
- public client_connect(id)
- {
- LpVote[id] = false;
- return PLUGIN_HANDLED
- }
- public client_disconnect (id)
- {
- if(LpVote[id]){
- LpVote[id] = false;
- VoteCoun--;
- }
- return PLUGIN_HANDLED
- }
- public Text(id)
- {
- client_print(0, print_chat, "按Y输入/maps 或在控制台输入/maps可请求投票换图");
- client_print(0, print_chat, "当7成的玩家请求投票换图时系统会随即抽取6张地图发起投票");
- }
- public Set_Maps(id)
- {
- if(LpVote[id])
- {
- client_print(id,print_center,"你已经发起投票指令 请等待其他玩家决定!");
- } else {
- LpVote[id] = true;
- VoteCoun++;
- new name[32];
- get_user_name(id,name,31);
- client_print(0, print_chat, "玩家[ %s ]请求投票换图",name);
- client_print(0, print_chat, "当7成的玩家请求投票换图时系统会随即抽取6张地图发起投票");
- new maxpaly = get_playersnum();
- new Float:VoteTemp = maxpaly * 0.7;
- if(VoteCoun >= floatround(VoteTemp)){
- client_print(0, print_chat, "超过7成的玩家请求投票换图系统随即抽取6张地图发起投票");
- new menustr[512]
- ArrayClear(VoteMapName);
- new len = format(menustr,512,"\r投票换图[AcFun.Gaming]:^n^n");
- for(new i=4; i<10;i++)
- {
- new LpItem;
- new tempMap[32];
- LpItem = random_num(0,LpMapNums);
- ArrayGetString(LpMapName, LpItem, tempMap, charsmax(tempMap));
- len += format(menustr[len],512-len, "\r%i. \w%s^n",i,tempMap);
- ArrayPushString(VoteMapName, tempMap);
- LpVoteCount[i-4] = 0;
- }
- len += format(menustr[len],512-len, "\r0. \w弃权^n");
- for(new i=0;i<maxpaly;i++)
- {
- show_menu(id, KeysSet_Maps_Menu, menustr, 20, "Set_Maps_Menu");
- }
- client_print(0, print_chat, "系统将在25秒后按投票结果进行换图");
- client_print(0, print_center, "系统将在25秒后按投票结果进行换图");
- set_task(25.0, "Maps",78917474)
- }
- }
-
- }
- public Pressed_Set_Maps_Menu(id, key)
- {
- switch (key)
- {
- case 3:{
- LpVoteCount[0]++;
- }
- case 4:{
- LpVoteCount[1]++;
- }
- case 5:{
- LpVoteCount[2]++;
- }
- case 6:{
- LpVoteCount[3]++;
- }
- case 7:{
- LpVoteCount[4]++;
- }
- case 8:{
- LpVoteCount[5]++;
- }
- }
- new name[32],tempMap[32];
- get_user_name(id,name,31);
- if(key == 9)
- {
- tempMap= "弃权"
- } else {
- ArrayGetString(VoteMapName, key-3, tempMap, charsmax(tempMap));
- }
- client_print(0, print_chat, "[ %s ]选择: %s",name,tempMap);
- return PLUGIN_CONTINUE
- }
- public Maps()
- {
- new a = 0;
- new tempMap[33];
- for (new i = 0; i < 6; ++i)
- {
- if (LpVoteCount[a] < LpVoteCount[i])
- {
- a = i
- }
- }
- ArrayGetString(VoteMapName, a, tempMap, charsmax(tempMap));
- set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
- ArrayClear(VoteMapName);
- return 1;
- }
- public delayedChange(mapname[])
- server_cmd("changelevel %s", mapname)
- load_settings(filename[])
- {
- new fp = fopen(filename, "r");
-
- if (!fp)
- {
- return 0;
- }
-
- new text[256];
- new tempMap[32];
-
- while (!feof(fp))
- {
- fgets(fp, text, charsmax(text));
-
- if (text[0] == ';')
- {
- continue;
- }
- if (parse(text, tempMap, charsmax(tempMap)) < 1)
- {
- continue;
- }
- if (!ValidMap(tempMap))
- {
- continue;
- }
-
- ArrayPushString(LpMapName, tempMap);
- LpMapNums++;
- }
- return 1;
- }
- stock bool:ValidMap(mapname[])
- {
- if ( is_map_valid(mapname) )
- {
- return true;
- }
- new len = strlen(mapname) - 4;
-
- if (len < 0)
- {
- return false;
- }
- if ( equali(mapname[len], ".bsp") )
- {
- mapname[len] = '^0';
- if ( is_map_valid(mapname) )
- {
- return true;
- }
- }
-
- return false;
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注个册吧
×
|