搜索
查看: 2241|回复: 5

请大哥们看看这个源码

[复制链接]
发表于 2007-1-21 16:54:06 | 显示全部楼层 |阅读模式 来自 中国–天津–天津
这是我在DT下的换皮肤的AMXX。有2个问题,1:好象没有设置权限,2:是否可以在CS1.5中使用,请老大们给出意见,和解决办法。
#include <amxmodx>
  #include <amxmisc>
  #include <cstrike>

  #define MENUTIME 30 // how long menus stay up

  // Key Defines (for ease of use and readability)
  #define KEY1 (1<<0)
  #define KEY2 (1<<1)
  #define KEY3 (1<<2)
  #define KEY4 (1<<3)
  #define KEY5 (1<<4)
  #define KEY6 (1<<5)
  #define KEY7 (1<<6)
  #define KEY8 (1<<7)
  #define KEY9 (1<<8)
  #define KEY0 (1<<9)

  // Temporary Menu Variables
  new page[33] = { 1, ...}, choices[33][9][33], target[33][33];

  // A user's assigned model
  new setmodel[33][33];

  // ------------------------------------------------------------------------------------------
  // --MENU DISPLAYS--------------------------------------------------------------------------
  // ------------------------------------------------------------------------------------------

  // Here are all of our functions for displaying the menus themselves

  // --MENU 1 DISPLAY--------------------------------------------------------------------------
  public menu1Display(id) {

    // choose who to perform actions on

    new menubody[256];
    format(menubody,255,"\y绠$悊鍛樹负鐜╁鏇存崲鏈嶈鑿滃崟 :^n^n");
    add(menubody,255,"\w1. 涓烘墍鏈夋亹鎬栦唤瀛恀n");
    add(menubody,255,"\w2. 涓烘墍鏈夊弽鎭愮簿鑻盺n");
    add(menubody,255,"\w3. 涓烘寚瀹氱帺瀹禴n");
    add(menubody,255,"\w4. 涓哄叏閮ㄧ帺瀹禴n");
    add(menubody,255,"\w5. 涓轰綘鑷繁^n");
    add(menubody,255,"\w^n0. 閫€鍑?);

    show_menu(id,KEY1|KEY2|KEY3|KEY4|KEY5|KEY0,menubody,MENUTIME,"menu1");

    return PLUGIN_HANDLED;
  }

  // --MENU 2 DISPLAY--------------------------------------------------------------------------
  public menu2Display(id) {

    // our list of players

    // clear choices
    for(new n=0;n<9;n++) {
      choices[id][n] = "";
    }

    new menubody[256];
    format(menubody,255,"\y涓虹帺瀹舵洿鎹㈡湇瑁? (鎸囧畾鐜╁, 绗?%d 椤?:^n^n",page[id]);

    // get players
    new players[32], num;
    get_players(players,num);

    // if too many for one page
    new loopamt = num-((page[id]-1)*8);
    if(num-((page[id]-1)*8) > 8) {
      loopamt = 8;
    }

    new offset = (page[id] * 8) - 8; // starting offset

    // loop through players
    for(new i=offset;i<loopamt+offset;i++) {

      // get name
      new username[33];
      get_user_name(players,username,32);

      // get user's team
      new team[5];
      if(get_user_team(players) == 1) { team = "T"; }
      else if(get_user_team(players) == 2) { team = "CT"; }
      else { team = "SPEC"; }

      // our string to add
      new string[256];
      format(string,255,"\w%d. %s (%s%s)^n",i+1-offset,username,team,is_user_admin(players) ? ",@" : "");

      // get string value of player's id
      new idstr[33];
      num_to_str(players,idstr,32);

      // save player's id for easy access
      choices[id][i-offset] = idstr;

      // add it to menu
      add(menubody,255,string);
    }

    // if another page
    if(num-((page[id]-1)*8) > 8) {
      choices[id][8] = "Next";
      add(menubody,255,"\w^n9. 涓嬩竴椤?);
    }

    add(menubody,255,"\w^n0. 杩斿洖");

    show_menu(id,KEY1|KEY2|KEY3|KEY4|KEY5|KEY6|KEY7|KEY8|KEY9|KEY0,menubody,MENUTIME,"menu2");

    return PLUGIN_HANDLED;
  }

  // --MENU 3 DISPLAY--------------------------------------------------------------------------
  public menu3Display(id) {

    // choose what model category to browse in

    new menubody[256];
    format(menubody,255,"\y鏀瑰彉鏈嶈涓?(璇烽€夋嫨鏌愪竴绫诲瀷):^n^n");
    add(menubody,255,"\w1. 鍖緬鏈嶉グ^n");
    add(menubody,255,"\w2. 璀﹀療鏈嶉グ^n");
    add(menubody,255,"\w3. 鍏ㄩ儴鏈嶉グ^n");
    add(menubody,255,"\w4. 閲嶆柊閫夋嫨^n");
    add(menubody,255,"\w^n0. 杩斿洖");

    show_menu(id,KEY1|KEY2|KEY3|KEY4|KEY0,menubody,MENUTIME,"menu3");

    return PLUGIN_HANDLED;
  }

  // --MENU 4 DISPLAY--------------------------------------------------------------------------
  public menu4Display(id) {

    // terrorist model list

    new menubody[256];
    format(menubody,255,"\y鏀瑰彉鏈嶉グ涓?(鍖緬鏈嶉グ):^n^n");
    add(menubody,255,"\w1. 鍑ゅ嚢鍩庢亹鎬栫粍缁嘵n");
    add(menubody,255,"\w2. 鍗楃編娲茬壒鍒殫鏉€灏忕粍^n");
    add(menubody,255,"\w3. 鐟炲吀鍖楁瀬澶嶄粐鑰區n");
    add(menubody,255,"\w4. 涓笢娓稿嚮闃焇n");
    add(menubody,255,"\w^n0. 杩斿洖");

    show_menu(id,KEY1|KEY2|KEY3|KEY4|KEY0,menubody,MENUTIME,"menu4");

    return PLUGIN_HANDLED;
  }

  // --MENU 5 DISPLAY--------------------------------------------------------------------------
  public menu5Display(id) {

    // counter-terrorist model list

    new menubody[256];
    format(menubody,255,"\y鏀瑰彉鏈嶉グ涓?(璀﹀療鏈嶉グ):^n^n");
    add(menubody,255,"\w1. 缇庡浗娴疯惫绐佸嚮闃熺鍏垎闃焇n");
    add(menubody,255,"\w2. 寰峰浗杈归槻绗節鏃區n");
    add(menubody,255,"\w3. 鑻卞浗鐨囧鐗瑰埆绌哄嫟鍥n");
    add(menubody,255,"\w4. 娉曞浗瀹叺骞查闃焇n");
    add(menubody,255,"\w5. VIP^n");
    add(menubody,255,"\w^n0. 杩斿洖");

    show_menu(id,KEY1|KEY2|KEY3|KEY4|KEY5|KEY0,menubody,MENUTIME,"menu5");

    return PLUGIN_HANDLED;
  }

  // --MENU 6 DISPLAY--------------------------------------------------------------------------
  public menu6Display(id) {

    // our list of custom models

    // clear choices
    for(new i=0;i<9;i++) {
      choices[id] = "";
    }

    new menubody[256];
    format(menubody,255,"\y鏀瑰彉鏈嶉グ涓?(鎸囧畾鐨勬湇楗? 绗?%d 椤?:^n^n",page[id]);

    // get custom models
    new models[32][33], num;
    num = get_models(models,32);

    // if too many for one page
    new loopamt = num-((page[id]-1)*8);
    if(num-((page[id]-1)*8) > 8) {
      loopamt = 8;
    }

    new offset = (page[id] * 8) - 8; // starting offset

    // loop through players
    for(new i=offset;i<loopamt+offset;i++) {

      // our string to add
      new string[256];
      format(string,255,"\w%d. %s^n",i+1-offset,models);

      // save model's name for easy access
      choices[id][i-offset] = models;

      // add it to menu
      add(menubody,255,string);
    }

    // if another page
    if(num-((page[id]-1)*8) > 8) {
      choices[id][8] = "Next";
      add(menubody,255,"\w^n9. 涓嬩竴椤?);
    }

    add(menubody,255,"\w^n0. 杩斿洖");

    show_menu(id,KEY1|KEY2|KEY3|KEY4|KEY5|KEY6|KEY7|KEY8|KEY9|KEY0,menubody,MENUTIME,"menu6");

    return PLUGIN_HANDLED;
  }

  // ------------------------------------------------------------------------------------------
  // --MENU ACTIONS---------------------------------------------------------------------------
  // ------------------------------------------------------------------------------------------

  // This handles the actions of all of our menus

  // --MENU 1 ACTION---------------------------------------------------------------------------
  public menu1Action(id,key) {

    // 1. Terrorist
    if(key == 0) {
      target[id] = "@T";
      menu3Display(id);
      return 1;
    }

    // 2. Counter-Terrorist
    if(key == 1) {
      target[id] = "@CT";
      menu3Display(id);
      return 1;
    }

    // 3. Specific Player
    if(key == 2) {
      menu2Display(id);
      return 1;
    }

    // 4. All Players
    if(key == 3) {
      target[id] = "*";
      menu3Display(id);
      return 1;
    }

    // 5. Yourself
    if(key == 4) {
      new idstr[33];
      num_to_str(id,idstr,32);
      target[id] = idstr;
      menu3Display(id);
      return 1;
    }

    // 0. Exit
    // Nothing happens and the menu closes

    return 1;
  }

  // --MENU 2 ACTION---------------------------------------------------------------------------
  public menu2Action(id,key) {

    // 0. Back
    if(key == 9 && page[id] == 1) {
      menu1Display(id);
      return 1;
    }
    else if(key == 9 && page[id] > 1) {
      page[id] -=1 ;
      menu2Display(id);
      return 1;
    }

    // if choice is blank
    if(equal(choices[id][key],"")) {
      menu2Display(id); // reset menu
      return 1;
    }

    // 1-8. Varies
    if(key < 8) {
      target[id] = choices[id][key];
      menu3Display(id);
      return 1;
    }

    // 9. Next
    if(key == 8 && equal(choices[id][key],"Next")) {
      page[id] += 1;
      menu2Display(id);
      return 1;
    }  

    return 1;
  }

  // --MENU 3 ACTION---------------------------------------------------------------------------
  public menu3Action(id,key) {

    // 1. T Models
    if(key == 0) {
      menu4Display(id);
      return 1;
    }

    // 2. CT Models
    if(key == 1) {
      menu5Display(id);
      return 1;
    }

    // 3. Custom Models
    if(key == 2) {
      menu6Display(id);
      return 1;
    }

    // 4. Reset Models
    if(key == 3) {
      modelAction(id,target[id],".reset");
      return 1;
    }

    // 0. Back
    if(key == 9) {
      menu1Display(id);
      return 1;
    }   

    return 1;
  }

  // --MENU 4 ACTION---------------------------------------------------------------------------
  public menu4Action(id,key) {

    // 1. Phoenix Connexion
    if(key == 0) {
      modelAction(id,target[id],"terror");
      return 1;
    }

    // 2. 1337 Krew
    if(key == 1) {
      modelAction(id,target[id],"leet");
      return 1;
    }

    // 3. Arctic Avengers
    if(key == 2) {
      modelAction(id,target[id],"arctic");
      return 1;
    }

    // 4. Guerilla Warfare
    if(key == 3) {
      modelAction(id,target[id],"guerilla");
      return 1;
    }

    // 0. Back
    if(key == 9) {
      menu3Display(id);
      return 1;
    }

    return 1;
  }

  // --MENU 5 ACTION---------------------------------------------------------------------------
  public menu5Action(id,key) {

    // 6. Choose Random
    if(key == 5) {
      key = random_num(0,4);
    }

    // 1. US Seal Team 6
    if(key == 0) {
      modelAction(id,target[id],"urban");
      return 1;
    }

    // 2. German GSG-9
    if(key == 1) {
      modelAction(id,target[id],"gsg9");
      return 1;
    }

    // 3. UK Special Air Service
    if(key == 2) {
      modelAction(id,target[id],"sas");
      return 1;
    }

    // 4. French GIGN
    if(key == 3) {
      modelAction(id,target[id],"gign");
      return 1;
    }

    // 5. VIP
    if(key == 4) {
      modelAction(id,target[id],"vip");
      return 1;
    }

    // 0. Back
    if(key == 9) {
      menu3Display(id);
      return 1;
    }

    return 1;
  }

  // --MENU 6 ACTION---------------------------------------------------------------------------
  public menu6Action(id,key) {

    // 0. Back
    if(key == 9 && page[id] == 1) {
      menu3Display(id);
      return 1;
    }
    else if(key == 9 && page[id] > 1) {
      page[id] -=1 ;
      menu6Display(id);
      return 1;
    }

    // if choice is blank
    if(equal(choices[id][key],"")) {
      menu6Display(id); // reset menu
      return 1;
    }

    // 1-8. Varies
    if(key < 8) {
      modelAction(id,target[id],choices[id][key]);
      return 1;
    }

    // 9. Next
    if(key == 8 && equal(choices[id][key],"Next")) {
      page[id] += 1;
      menu6Display(id);
      return 1;
    }

    return 1;
  }

  // ------------------------------------------------------------------------------------------
  // --SET MODEL ACTION-----------------------------------------------------------------------
  // ------------------------------------------------------------------------------------------
  public modelAction(id,target[33],model[33]) {

    new username[33], authid[33];
    get_user_name(id,username,32);
    get_user_authid(id,authid,32);

    // if clearing models
    if(equal(model,".reset")) {

      // log the command
      log_amx("Cmd: ^"%s<%d><%s><>^" reset model for %s%s",username,get_user_userid(id),authid,isdigit(target[0]) ? "#" : "",target);

      // show activity
      switch(get_cvar_num("amx_show_activity")) {
        case 1: client_print(0,print_chat,"绠$悊: 閲嶆柊璁惧畾鏈嶉グ涓?%s%s",isdigit(target[0]) ? "#" : "",target);
        case 2: client_print(0,print_chat,"绠$悊 %s: 閲嶆柊璁惧畾鏈嶉グ涓?%s%s",username,isdigit(target[0]) ? "#" : "",target);
      }

    }
    else { // if setting models

      // log the command
      log_amx("Cmd: ^"%s<%d><%s><>^" set model %s on %s%s",username,get_user_userid(id),authid,model,isdigit(target[0]) ? "#" : "",target);

      // show activity
      switch(get_cvar_num("amx_show_activity")) {
        case 1: client_print(0,print_chat,"绠$悊: 璁惧畾 %s 涓?%s%s鐨勬湇楗?,model,isdigit(target[0]) ? "#" : "",target);
        case 2: client_print(0,print_chat,"绠$悊 %s: 璁惧畾 %s 涓?%s%s鐨勬湇楗?,username,model,isdigit(target[0]) ? "#" : "",target);
      }

    }

    new flags[2], team[33];

    if(equal(target,"@T")) { // All Terrorists
      flags = "e"; // team
      team = "TERRORIST";
    }
    else if(equal(target,"@CT")) { // All Counter-Terrorists
      flags = "e"; // team
      team = "CT";
    }
    else if(isdigit(target[0])) { // Specific Player or Yourself
      flags = "f"; // name
      get_user_name(str_to_num(target),team,32);
    }

    // Otherwise this leaves us with nothing, which is All Players

    // get targets
    new players[32], num;
    get_players(players,num,flags,team);

    // loop through
    for(new i=0;i<num;i++) {
      new player = players; // our player

      if(equal(model,".reset")) { // if reset
        cs_reset_user_model(player);
        setmodel[player] = "";
      }
      else {
        cs_set_user_model(player,model);
        setmodel[player] = model;
      }
    }

    return 1;
  }

  // ------------------------------------------------------------------------------------------
  // --CUSTOM MODEL LIST----------------------------------------------------------------------
  // ------------------------------------------------------------------------------------------
  public get_models(array[32][],len) {

    // get a list of custom models

    new dirpos, output[64], outlen, filledamt;

    // go through custom models
    while((dirpos = read_dir("models/player",dirpos,output,255,outlen)) != 0) {

      if(containi(output,".") == -1) { // if not a file (but a directory)

        // check if model is actually there
        new modelfile[64];
        format(modelfile,63,"models/player/%s/%s.mdl",output,output);

        // if it exists
        if(file_exists(modelfile)) {
          format(array[filledamt],len,"%s",output);
          filledamt += 1;
        }

        // if we are out of array space now
        if(filledamt > 32) {
          return filledamt;
        }

      }

    }

    return filledamt;
  }

  // ------------------------------------------------------------------------------------------
  // --RESET MODEL ON RESPAWN-----------------------------------------------------------------
  // ------------------------------------------------------------------------------------------
  public event_resethud(id) {

    if(!equal(setmodel[id],"")) {
      cs_set_user_model(id,setmodel[id]);
    }

  }

  // ------------------------------------------------------------------------------------------
  // --CONNECTION AND DISCONNECTION-----------------------------------------------------------
  // ------------------------------------------------------------------------------------------
  public client_connect(id) {
    page[id] = 1;
    setmodel[id] = "";
  }

  public client_disconnect(id) {
    page[id] = 1;
    setmodel[id] = "";
  }

  // ------------------------------------------------------------------------------------------
  // --PLUGIN PRECACHE------------------------------------------------------------------------
  // ------------------------------------------------------------------------------------------
  public plugin_precache() {

    // get custom models
    new models[32][33], num;
    num = get_models(models,32);

    // loop through them
    for(new i=0;i<num;i++) {
      new modelstring[64];
      format(modelstring,63,"models/player/%s/%s.mdl",models,models);
      precache_model(modelstring);
    }

  }

  public currmodel(id) {
    new model[33];
    cs_get_user_model(id,model,32);
    client_print(id,print_chat,"* 浣犵殑鏈嶉グ鏄?%s",model);
    return PLUGIN_HANDLED;
  }

  // ------------------------------------------------------------------------------------------
  // --PLUGIN ININITATION---------------------------------------------------------------------
  // ------------------------------------------------------------------------------------------
  public plugin_init() {
    register_plugin("CS鏈嶉グ绠$悊绯荤粺CN","0.11","Avalanche AND btvsohu");
    console_print(0,"* Loaded CS User Model Menuz 0.11 by Avalanche");

    register_clcmd("amx_csummz","menu1Display",ADMIN_BAN,"- 绠$悊鏈嶉グ鑿滃崟");
    register_event("ResetHUD","event_resethud","b");

    register_clcmd("say /currmodel","currmodel",-1);

    // Register Menu IDs
    new menu1ID = register_menuid("menu1");
    new menu2ID = register_menuid("menu2");
    new menu3ID = register_menuid("menu3");
    new menu4ID = register_menuid("menu4");
    new menu5ID = register_menuid("menu5");
    new menu6ID = register_menuid("menu6");

    // Register Menu Commands
    register_menucmd(menu1ID,1023,"menu1Action");
    register_menucmd(menu2ID,1023,"menu2Action");
    register_menucmd(menu3ID,1023,"menu3Action");
    register_menucmd(menu4ID,1023,"menu4Action");
    register_menucmd(menu5ID,1023,"menu5Action");
    register_menucmd(menu6ID,1023,"menu6Action");
  }
发表于 2009-7-6 20:19:45 | 显示全部楼层 来自 中国–宁夏–银川
谢谢楼主分享哦,还是点通高手多,学习中!{:3_57:}


没有AMX的吗?
回复 1 0

使用道具 举报

 楼主| 发表于 2007-1-21 23:54:55 | 显示全部楼层 来自 中国–辽宁–沈阳

回复: 请大哥们看看这个源码

谢谢这位大哥。。。。。。。。已经收藏
回复 1 0

使用道具 举报

发表于 2007-1-21 22:56:42 | 显示全部楼层 来自 中国–江苏–南京

回复: 请大哥们看看这个源码

官方原版,你最好下了那个sma自己重新编译一下

http://forums.alliedmods.net/showthread.php?t=8631
回复 1 0

使用道具 举报

 楼主| 发表于 2007-1-21 21:42:19 | 显示全部楼层 来自 中国–辽宁–沈阳

回复: 请大哥们看看这个源码

楼上的大哥有没有英文版的,有的话,给我一个啊~~~还有你的QQ,我可以加你吗?
回复 1 0

使用道具 举报

发表于 2007-1-21 20:30:48 | 显示全部楼层 来自 中国–江苏–南京

回复: 请大哥们看看这个源码

1.admin_ban
2.1.5下要中文改英文
回复 1 0

使用道具 举报

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

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