zlove84 发表于 2010-8-13 01:48:49

求修改CsummzCN.sma分三贴发源码

本帖最后由 zlove84 于 2010-8-13 01:51 编辑

编译后发现,随便一个玩家也可以让自己穿衣服,求帮忙修改成只有管理员A权限才可以使用#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 = { 1, ...}, choices, target;

// A user's assigned model
new setmodel;

// ------------------------------------------------------------------------------------------
// --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;
    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 = "";
    }

    new menubody;
    format(menubody,255,"\y为玩家更换服装(指定玩家, 第 %d 页):^n^n",page);

    // get players
    new players, num;
    get_players(players,num);

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

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

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

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

      // get user's team
      new team;
      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;
      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;
      num_to_str(players,idstr,32);

      // save player's id for easy access
      choices = idstr;

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

    // if another page
    if(num-((page-1)*8) > 8) {
      choices = "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;
    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;
    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;
}

zlove84 发表于 2010-8-13 01:49:52

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

    // counter-terrorist model list

    new menubody;
    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 = "";
    }

    new menubody;
    format(menubody,255,"\y改变服饰为 (指定的服饰, 第 %d 页):^n^n",page);

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

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

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

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

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

      // save model's name for easy access
      choices = models;

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

    // if another page
    if(num-((page-1)*8) > 8) {
      choices = "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 = "@T";
      menu3Display(id);
      return 1;
    }

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

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

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

    // 5. Yourself
    if(key == 4) {
      new idstr;
      num_to_str(id,idstr,32);
      target = 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 == 1) {
      menu1Display(id);
      return 1;
    }
    else if(key == 9 && page > 1) {
      page -=1 ;
      menu2Display(id);
      return 1;
    }

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

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

    // 9. Next
    if(key == 8 && equal(choices,"Next")) {
      page += 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,".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,"terror");
      return 1;
    }

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

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

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

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

    return 1;
}

zlove84 发表于 2010-8-13 01:50:56

// --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,"urban");
      return 1;
    }

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

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

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

    // 5. VIP
    if(key == 4) {
      modelAction(id,target,"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 == 1) {
      menu3Display(id);
      return 1;
    }
    else if(key == 9 && page > 1) {
      page -=1 ;
      menu6Display(id);
      return 1;
    }

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

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

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

    return 1;
}

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

    new username, authid;
    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) ? "#" : "",target);

      // show activity
      switch(get_cvar_num("amx_show_activity")) {
      case 1: client_print(0,print_chat,"管理: 重新设定服饰为 %s%s",isdigit(target) ? "#" : "",target);
      case 2: client_print(0,print_chat,"管理 %s: 重新设定服饰为 %s%s",username,isdigit(target) ? "#" : "",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) ? "#" : "",target);

      // show activity
      switch(get_cvar_num("amx_show_activity")) {
      case 1: client_print(0,print_chat,"管理: 设定 %s 为 %s%s的服饰",model,isdigit(target) ? "#" : "",target);
      case 2: client_print(0,print_chat,"管理 %s: 设定 %s 为 %s%s的服饰",username,model,isdigit(target) ? "#" : "",target);
      }

    }

    new flags, team;

    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)) { // 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, 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 = "";
      }
      else {
      cs_set_user_model(player,model);
      setmodel = model;
      }
    }

    return 1;
}

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

    // get a list of custom models

    new dirpos, output, 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;
      format(modelfile,63,"models/player/%s/%s.mdl",output,output);

      // if it exists
      if(file_exists(modelfile)) {
          format(array,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,"")) {
      cs_set_user_model(id,setmodel);
    }

}

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

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

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

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

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

}

public currmodel(id) {
    new model;
    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");
}

// hook amx_csummz to check permissions
public consoleCommand(id,level,cid) {

    if(!cmd_access(id,level,cid,1)) {
      return PLUGIN_HANDLED;
    }

    return menu1Display(id);
}

guchen5192 发表于 2011-1-19 00:30:04

看看学习下

homework 发表于 2011-1-19 10:56:00

好长的一段。。。。。。。。。。帮顶。。。
页: [1]
查看完整版本: 求修改CsummzCN.sma分三贴发源码