- 听众
- 收听
- 积分
- 3894
- 主题
- 回帖
- 0
- 精华
注册时间2008-4-22
最后登录1970-1-1
该用户从未签到
|
发表于 2010-1-18 20:05:03
|
显示全部楼层
本帖最后由 Pledges 于 2010-1-18 20:19 编辑
Installation:
0. You need to have installed amxmodx to run this.
1. Put the file showkeys.amxx into /cstrike/addons/amxmodx/plugins/
2. Open /cstrike/addons/amxmodx/configs/plugins.ini with notepad
3. Add line "showkeys.amxx" at the end of plugins.ini.
4. Make shure that fakemeta module is running. You can find that out by opening /cstrike/addons/amxmodx/configs/modules.ini with notepad.
User commands:
say /keys
turns plugin on/off
say /keyscfg
configuration menu (position, color...)
Server cvar:
keys_channel 4
If you don't see other important text on hud you can try to change this value in interval of 1 to 4. The value -1 means that it will try to find unused channel, however I don't recommend you to use -1.
keys_autostart 0
If this is set to 1 /keys will be enabled by default.
Known bugs
Showkeys saves the configuration into "setinfo" string. Half-life has a limit of 7 setinfo strings. So if you will have problems with saving configuration, check your /cstrike/config.cfg and remove unused "setinfo" strings.
this is sma :
-
- #include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- #define PLUGIN "Showkeys"
- #define VERSION "2.1"
- #define AUTHOR "coderiz"
- #define MENU_CONFIG MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_4 | MENU_KEY_5 | MENU_KEY_6 | MENU_KEY_0
- #define MENU_POSITION MENU_KEY_0
- #define MENU_COLOR MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_0
- // Uncoment this for some bhop info on hud.
- //#define BHOP 1
- // cvar pointers
- new cvar_keys_channel
- new cvar_autostart
- // Server settings
- new g_srv_channel
- new g_srv_struct[10][12][10]
- // player settings
- new bool:g_plr_showkeys[32]
- new bool:g_plr_showspeed[32]
- new g_plr_struct[32]
- new Float:g_plr_hudpos[32][2]
- new g_plr_hudcolor[32][3]
- // config menu
- new g_plr_configon[32]
- new g_plr_buttons[32][5]
- new g_plr_editcolor[32]
- #if defined BHOP
- new g_counter[32]
- new g_flags[32]
- #endif
- // Main
- // -------------------------------------------------------------------------------------------------
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- cvar_keys_channel = register_cvar ( "keys_channel", "4", FCVAR_SERVER)
- cvar_autostart = register_cvar ( "keys_autostart", "0", FCVAR_SERVER)
- g_srv_channel = get_pcvar_num ( cvar_keys_channel )
- if(g_srv_channel < 1 || g_srv_channel > 4)
- {
- g_srv_channel = -1
- }
- // CMD
- register_clcmd("say /keys","cl_ShowKeys")
- register_clcmd("show_keys","cl_ShowKeys")
- register_clcmd("say /keysmenu","cl_config")
- register_clcmd("say /keyscfg","cl_config")
- register_clcmd("say /keysconf","cl_config")
- register_clcmd("say /keysconfig","cl_config")
- // Menu
- register_menu("Showkeys config", MENU_CONFIG,"menu_config_act")
- register_menu("Showkeys position", MENU_CONFIG,"menu_position_act")
- register_menu("Showkeys color", MENU_CONFIG,"menu_color_act")
- // Forwards
- register_forward(FM_PlayerPreThink, "fwd_PlayerPreThink")
- register_forward(FM_ClientPutInServer, "fwd_ClientPutInServer")
- //
- g_srv_struct[0][0] = "[w]"
- g_srv_struct[0][1] = "[s]"
- g_srv_struct[0][2] = "[a]"
- g_srv_struct[0][3] = "[d]"
- g_srv_struct[0][4] = "[-]"
- g_srv_struct[0][5] = "[Duck]"
- g_srv_struct[0][6] = "[Jump]"
- g_srv_struct[0][7] = "[----]"
- g_srv_struct[0][8] = "[----]"
- g_srv_struct[0][9] = "Speed: %s"
- g_srv_struct[1][0] = "w"
- g_srv_struct[1][1] = "s"
- g_srv_struct[1][2] = "a"
- g_srv_struct[1][3] = "d"
- g_srv_struct[1][4] = "-"
- g_srv_struct[1][5] = "duck"
- g_srv_struct[1][6] = "jump"
- g_srv_struct[1][7] = " "
- g_srv_struct[1][8] = " "
- g_srv_struct[1][9] = "%s"
- g_srv_struct[2][0] = "w"
- g_srv_struct[2][1] = "s"
- g_srv_struct[2][2] = "a"
- g_srv_struct[2][3] = "d"
- g_srv_struct[2][4] = "-"
- g_srv_struct[2][5] = "Duck"
- g_srv_struct[2][6] = "Jump"
- g_srv_struct[2][7] = "----"
- g_srv_struct[2][8] = "----"
- g_srv_struct[2][9] = "Speed: %s"
- g_srv_struct[3][0] = "w"
- g_srv_struct[3][1] = "s"
- g_srv_struct[3][2] = "a"
- g_srv_struct[3][3] = "d"
- g_srv_struct[3][4] = "-"
- g_srv_struct[3][5] = "duck"
- g_srv_struct[3][6] = "jump"
- g_srv_struct[3][7] = "-----"
- g_srv_struct[3][8] = "-----"
- g_srv_struct[3][9] = "speed: %s"
- g_srv_struct[4][0] = "W"
- g_srv_struct[4][1] = "S"
- g_srv_struct[4][2] = "A"
- g_srv_struct[4][3] = "D"
- g_srv_struct[4][4] = "#"
- g_srv_struct[4][5] = "Duck"
- g_srv_struct[4][6] = "Jump"
- g_srv_struct[4][7] = "--..--"
- g_srv_struct[4][8] = "--..--"
- g_srv_struct[4][9] = " | %s"
- }
- // Client functions
- // -------------------------------------------------------------------------------------------------
- /*
- Command: say /keys
- Toggles plugin ON/OFF
- */
- public cl_ShowKeys (id)
- {
- new index = id - 1
- new arg[10]
- read_argv(0, arg, 9)
- if(equal(arg, "show_keys"))
- {
- read_argv(1, arg, 9)
-
- if(equal(arg, "on") || equal(arg, "1"))
- {
- g_plr_showkeys[index] = true
- } else if(equal(arg, "off") || equal(arg, "0"))
- {
- g_plr_showkeys[index] = false
- } else {
- client_print(id, print_console, "Usage: show_keys <on|off>")
- }
-
- return 1
- }
- if(!is_user_connected(id))
- {
- g_plr_showkeys[index] = false
- return 1
- }
- if(g_plr_showkeys[index])
- {
- g_plr_showkeys[index] = false
- return 0
- }
- else
- {
- g_plr_showkeys[index] = true
- return 0
- }
- return 0
- }
- /*
- say /keysmenu
- Shows config menu
- */
- public cl_config(id)
- {
- menu_config_show(id)
- return 0
- }
- // Forwards
- // -------------------------------------------------------------------------------------------------
- public fwd_ClientPutInServer(id)
- {
- new index = id - 1
- if(get_pcvar_num(cvar_autostart) == 1) g_plr_showkeys[index] = true
- else g_plr_showkeys[index] = false
- g_plr_hudpos[index][0] = 0.8
- g_plr_hudpos[index][1] = 0.01
- g_plr_hudcolor[index][0] = 150
- g_plr_hudcolor[index][1] = 0
- g_plr_hudcolor[index][2] = 0
- g_plr_showspeed[index] = true
- config_load(id)
- }
- public fwd_PlayerPreThink(id)
- {
- static index
- index = id - 1
- if(is_user_connected(id) && is_user_alive(id) && g_plr_showkeys[index])
- {
- new buttons = pev(id, pev_button)
- new kw[10], ka[10], ks[10], kd[10], kjump[10], kduck[10]
-
-
-
- #if defined BHOP
- new flags = pev(id, pev_flags)
- if(flags & FL_ONGROUND)
- {
- if(g_counter[index] < 99)
- g_counter[index]++
- }
- if( (g_flags[index] & FL_ONGROUND) && !(flags & FL_ONGROUND) )
- {
- if(g_counter[index] < 10)
- {
- set_hudmessage(0, 150, 0, -1.0, 0.1, 0, 0.0, 2.0, 0.0, 0.2, 2)
- show_hudmessage(id, "Bhop frames: %i", g_counter[index])
- }
-
- g_counter[index] = 0
- }
- g_flags[index] = flags
- #endif
-
-
- if(buttons & IN_FORWARD)
- {
- kw = g_srv_struct[g_plr_struct[index]][0]
- }
- else
- {
- kw = g_srv_struct[g_plr_struct[index]][4]
- }
-
- if(buttons & IN_MOVELEFT)
- {
- ka = g_srv_struct[g_plr_struct[index]][2]
- }
- else
- {
- ka = g_srv_struct[g_plr_struct[index]][4]
- }
-
- if(buttons & IN_MOVERIGHT)
- {
- kd = g_srv_struct[g_plr_struct[index]][3]
- }
- else
- {
- kd = g_srv_struct[g_plr_struct[index]][4]
- }
-
- if(buttons & IN_BACK)
- {
- ks = g_srv_struct[g_plr_struct[index]][1]
- }
- else
- {
- ks = g_srv_struct[g_plr_struct[index]][4]
- }
-
- if(buttons & IN_JUMP)
- {
- kjump = g_srv_struct[g_plr_struct[index]][6]
- }
- else
- {
- kjump = g_srv_struct[g_plr_struct[index]][8]
- }
-
- if(buttons & IN_DUCK)
- {
- kduck = g_srv_struct[g_plr_struct[index]][5]
- }
- else
- {
- kduck = g_srv_struct[g_plr_struct[index]][7]
- }
-
- set_hudmessage(g_plr_hudcolor[index][0], g_plr_hudcolor[index][1], g_plr_hudcolor[index][2],
- g_plr_hudpos[index][0], g_plr_hudpos[index][1], 0, 2.5, 0.0, 0.0, 0.1,
- g_srv_channel)
-
- new speedstr[32] = ""
-
- if(g_plr_showspeed[index])
- {
- new Float:speed[3]
- pev(id, pev_velocity, speed)
-
- float_to_str (
- floatsqroot(floatadd(floatpower(speed[0], 2.0), floatpower(speed[1], 2.0)))
- , speedstr, 5)
- format(speedstr, 31, g_srv_struct[g_plr_struct[index]][9], speedstr)
- }
-
- switch(g_plr_struct[index])
- {
- case 0:
- show_hudmessage(id, " %s^n%s %s %s^n%s %s^n^n%s",
- kw, ka, ks, kd, kduck, kjump, speedstr)
- case 1:
- show_hudmessage(id, " %s^n %s %s %s^n%s %s^n %s",
- kw, ka, ks, kd, kduck, kjump, speedstr)
- case 2:
- show_hudmessage(id, " %s %s^n%s %s %s %s^n%s",
- kw, kduck, ka, ks, kd, kjump, speedstr)
- case 3:
- show_hudmessage(id, " %s %s %s^n%s %s %s %s",
- kw, kduck, kjump, ka, ks, kd, speedstr)
- case 4:
- show_hudmessage(id, " %s | %s %s %s | %s %s%s",
- kw, ka, ks, kd, kduck, kjump, speedstr)
-
- }
- }
- switch(g_plr_configon[index])
- {
- case 1: config_position_think(id)
- case 2: config_color_think(id)
- }
- return 1
- }
- //
- // -------------------------------------------------------------------------------------------------
- public config_save(id)
- {
- new index = id - 1
- new color[8], position[18], speed[2], struct[2], config[32]
- color_enc(color, g_plr_hudcolor[index][0], g_plr_hudcolor[index][1], g_plr_hudcolor[index][2])
- position_enc(position, g_plr_hudpos[index][0], g_plr_hudpos[index][1])
- if(g_plr_showspeed[index]) speed = "1"
- else speed = "0"
- num_to_str(g_plr_struct[index], struct, 1)
- format(config, 31, "%sq%sq%sq%s", color, position, speed, struct)
- client_cmd(id, "setinfo ^"showkeys^" ^"%s^"", config)
- }
- public config_load(id)
- {
- new index = id - 1
- new config[32]
- get_user_info(id, "showkeys", config, 31)
- if(strlen(config) < 1)
- {
- g_plr_struct[index] = 3
- g_plr_showspeed[index] = true
- g_plr_hudcolor[index] = {15, 15, 200}
- g_plr_hudpos[index][0] = 0.4
- g_plr_hudpos[index][1] = 0.05
- } else {
- new color[8], position[18], speed[2], struct[2]
-
- format(color, 7, config)
- format(position, 17, config[8])
- format(speed, 1, config[26])
- format(struct, 1, config[28])
-
- color_dec(color, g_plr_hudcolor[index][0], g_plr_hudcolor[index][1], g_plr_hudcolor[index][2])
- position_dec(position, g_plr_hudpos[index][0], g_plr_hudpos[index][1])
-
- g_plr_showspeed[index] = equal(speed, "1") ? true : false
- g_plr_struct[index] = str_to_num(struct)
- }
- }
- // Config Menu
- //--------------------------------------------------------------------------------------------------
- public menu_config_show(id) {
- new index = id - 1
- new menustr[512]
- g_plr_showkeys[index] = true
- new str[32]
- add(menustr, 511, "\yShowkeys config^n^n")
- add(menustr, 511, "\r01. \wPosition^n")
- add(menustr, 511, "\r02. \wColor^n")
- add(menustr, 511, "\r03. \wStructure")
- format(str, 31, " \d[%i/5]^n", g_plr_struct[index]+1)
- add(menustr, 511, str)
- if(g_plr_showspeed[index]) add(menustr, 511, "\r04. \wShow Speed \d[ON]^n")
- else add(menustr, 511, "\r04. \wShow Speed \d[OFF]^n")
- add(menustr, 511, "\r05. \wReload Settings^n")
- add(menustr, 511, "\r06. \wSave Settings^n^n")
- add(menustr, 511, "\y00. Close")
- show_menu(id, MENU_CONFIG, menustr)
- }
- public menu_config_act(id, key) {
- new index = id - 1
- switch (key) {
- case 0: {
- menu_position_show(id)
- return 1
- }
- case 1: {
- menu_color_show(id)
- return 1
- }
- case 2: {
- g_plr_struct[index] = g_plr_struct[index] > 3 ? 0 : g_plr_struct[index] + 1
- menu_config_show(id)
- }
- case 3: {
- g_plr_showspeed[index] = !g_plr_showspeed[index]
- menu_config_show(id)
- }
- case 4: {
- client_print(id, print_chat, "[Showkeys] Settings loaded.")
- config_load(id)
- menu_config_show(id)
- }
- case 5: {
- client_print(id, print_chat, "[Showkeys] Settings saved.")
- config_save(id)
- menu_config_show(id)
- }
- case 6: {
-
- }
- }
- return 1
- }
- // Color and position menu
- // -------------------------------------------------------------------------------------------------
- public menu_position_show(id)
- {
- new index = id - 1
- new menustr[512]
- add(menustr, 511, "\yShowkeys position^n^n")
- add(menustr, 511, "\r a. \dLeft^n")
- add(menustr, 511, "\r d. \dRight^n")
- add(menustr, 511, "\r w. \dUp^n")
- add(menustr, 511, "\r s. \dDown^n^n")
- add(menustr, 511, "\rJump. \yGo back")
- show_menu(id, MENU_POSITION, menustr)
- g_plr_configon[index] = 1
- g_plr_showkeys[index] = true
- }
- public menu_position_act(id)
- {
- new index = id - 1
- g_plr_configon[index] = 0
- menu_config_show(id)
- return 1
- }
- public menu_color_show(id)
- {
- new index = id - 1
- new menustr[512]
- g_plr_configon[index] = 2
- g_plr_showkeys[index] = true
- new red[64], green[64], blue[64]
- switch (g_plr_editcolor[index])
- {
- case 1: {
- format(red, 63, "\r01. \wRed (%i)^n", g_plr_hudcolor[index][0])
- format(green, 63, "\r02. \dGreen (%i)^n", g_plr_hudcolor[index][1])
- format(blue, 63, "\r03. \dBlue (%i)^n", g_plr_hudcolor[index][2])
- } case 2: {
- format(red, 63, "\r01. \dRed (%i)^n", g_plr_hudcolor[index][0])
- format(green, 63, "\r02. \wGreen (%i)^n", g_plr_hudcolor[index][1])
- format(blue, 63, "\r03. \dBlue (%i)^n", g_plr_hudcolor[index][2])
- } case 3: {
- format(red, 63, "\r01. \dRed (%i)^n", g_plr_hudcolor[index][0])
- format(green, 63, "\r02. \dGreen (%i)^n", g_plr_hudcolor[index][1])
- format(blue, 63, "\r03. \wBlue (%i)^n", g_plr_hudcolor[index][2])
- } default: {
- format(red, 63, "\r01. \dRed (%i)^n", g_plr_hudcolor[index][0])
- format(green, 63, "\r02. \dGreen (%i)^n", g_plr_hudcolor[index][1])
- format(blue, 63, "\r03. \dBlue (%i)^n", g_plr_hudcolor[index][2])
- }
- }
- add(menustr, 511, "\yShowkeys color^n^n")
- add(menustr, 511, red)
- add(menustr, 511, green)
- add(menustr, 511, blue)
- add(menustr, 511, "\dUse \rw\d and \rs\d to set the value.^n^n")
- add(menustr, 511, "\y00. Go back")
- format(menustr, 511, menustr, red, green, blue)
- show_menu(id, MENU_COLOR, menustr)
- }
- public menu_color_act(id, key)
- {
- new index = id - 1
- switch(key)
- {
- case 0:{
- g_plr_configon[index] = 2
- g_plr_editcolor[index] = 1
- menu_color_show(id)
- } case 1: {
- g_plr_configon[index] = 2
- g_plr_editcolor[index] = 2
- menu_color_show(id)
- } case 2: {
- g_plr_configon[index] = 2
- g_plr_editcolor[index] = 3
- menu_color_show(id)
- } default: {
- set_pev(id, pev_maxspeed, 250.0)
- g_plr_configon[index] = 0
- menu_config_show(id)
- }
- }
- return 1
- }
- // Position and color config think.
- // -------------------------------------------------------------------------------------------------
- public config_position_think(id)
- {
- new index = id - 1
- new buttons = pev(id, pev_button)
- set_pev(id, pev_maxspeed, -1.0)
- new Float:speed=0.005
- // left
- if(buttons & IN_MOVELEFT) g_plr_buttons[index][0]++
- else g_plr_buttons[index][0] = 0
- // right
- if(buttons & IN_MOVERIGHT) g_plr_buttons[index][1]++
- else g_plr_buttons[index][1] = 0
- // forward
- if(buttons & IN_FORWARD) g_plr_buttons[index][2]++
- else g_plr_buttons[index][2] = 0
- // back
- if(buttons & IN_BACK) g_plr_buttons[index][3]++
- else g_plr_buttons[index][3] = 0
- // any
- if((buttons&IN_MOVELEFT)||(buttons&IN_MOVERIGHT)||(buttons&IN_FORWARD)||
- (buttons&IN_BACK)) g_plr_buttons[index][4]++
- else g_plr_buttons[index][4] = 0
- if(g_plr_buttons[index][4] < 10) speed=0.0005
- else if(g_plr_buttons[index][4] < 20) speed=0.001
- else if(g_plr_buttons[index][4] < 30) speed=0.002
- if(g_plr_buttons[index][0] > 0)
- if(g_plr_hudpos[index][0]-speed >= 0.0) g_plr_hudpos[index][0] -= speed // left
- if(g_plr_buttons[index][1] > 0)
- if(g_plr_hudpos[index][0]+speed <= 1.0) g_plr_hudpos[index][0] += speed // right
- if(g_plr_buttons[index][2] > 0)
- if(g_plr_hudpos[index][1]-speed >= 0.0) g_plr_hudpos[index][1] -= speed // up
- if(g_plr_buttons[index][3] > 0)
- if(g_plr_hudpos[index][1]+speed <= 1.0) g_plr_hudpos[index][1] += speed // down
- if(buttons & IN_JUMP)
- {
- set_pev(id, pev_maxspeed, 250.0)
- g_plr_configon[index] = 0
- menu_config_show(id)
- } else {
- if(g_plr_buttons[index][4] >= 10 && g_plr_buttons[index][4] % 10 == 0) menu_position_show(id)
- }
- }
- public config_color_think(id)
- {
- new index = id - 1
- if(g_plr_editcolor[index] < 1) return 0
- new color = g_plr_editcolor[index] - 1
- new buttons = pev(id, pev_button)
- set_pev(id, pev_maxspeed, -1.0)
- new oldw, olds
- oldw = g_plr_buttons[index][2]
- olds = g_plr_buttons[index][3]
- // forward
- if(buttons & IN_FORWARD) g_plr_buttons[index][2]++
- else g_plr_buttons[index][2] = 0
- // back
- if(buttons & IN_BACK) g_plr_buttons[index][3]++
- else g_plr_buttons[index][3] = 0
- if(
- (oldw==0 && g_plr_buttons[index][2]>0) ||
- (g_plr_buttons[index][2] > 30 && g_plr_buttons[index][2] % 5 == 0)
- ){
- if(g_plr_hudcolor[index][color] + 5 <= 255) g_plr_hudcolor[index][color] += 5
- else g_plr_hudcolor[index][color] = 255
-
- menu_color_show(id)
- }
- if(
- (olds==0 && g_plr_buttons[index][3]>0) ||
- (g_plr_buttons[index][3] > 30 && g_plr_buttons[index][3] % 5 == 0)
- ){
- if(g_plr_hudcolor[index][color] - 5 >= 0) g_plr_hudcolor[index][color] -= 5
- else g_plr_hudcolor[index][color] = 0
-
- menu_color_show(id)
- }
- return 0
- }
- // Color enc/dec html hex / dec rgb
- // -------------------------------------------------------------------------------------------------
- // encode rgb to html hex
- stock color_enc(output[], r, g, b)
- {
- new red[3], green[3], blue[3]
- num_to_hex(red, 2, r)
- num_to_hex(green, 2, g)
- num_to_hex(blue, 2, b)
- format(output, 7, "#%s%s%s", red, green, blue)
- }
- stock num_to_hex(output[], len, num)
- {
- new i[2]
- i[1] = 0
- if(num == 0) format(output, len,"00")
- else if(num < 16) {
- i[0] = (num < 10 ? num + 48 : num + 55)
- format(output, len, "0%s", i)
- } else while (num > 0)
- {
- i[0] = num % 16
- num = num / 16
-
- if(i[0] <= 9) i[0] += 48
- else i[0] += 55
-
- format(output, len, "%s%s", i, output)
- }
- }
- stock hex_to_num(const hex[])
- {
- new r, num
- for(new i=0; i<strlen(hex); i++)
- {
- num = hex[i]
- num = num >= 65 ? num - 55 : num - 48
-
- if(num < 0 || num > 15) return 0
-
- r = r * 16 + num
- }
- return r
- }
- // decode html hex to dec rgb
- stock color_dec(const color[], &r, &g, &b)
- {
- new i[3]
- i[2] = 0
- i[0] = color[1]
- i[1] = color[2]
- r = hex_to_num(i)
- i[0] = color[3]
- i[1] = color[4]
- g = hex_to_num(i)
- i[0] = color[5]
- i[1] = color[6]
- b = hex_to_num(i)
- }
- // Position enc/dec from float to string...
- // -------------------------------------------------------------------------------------------------
- stock position_enc(output[], Float:x, Float:y)
- {
- format(output, 17, "%fx%f", x, y)
- }
- stock position_dec(position[], & Float:x, & Float:y)
- {
- new xstr[9], ystr[9]
- format(xstr, 8, position)
- format(ystr, 5, position[9])
- x = str_to_float(xstr)
- y = str_to_float(ystr)
- }
复制代码
//--------------------------------------------------------------------------
//And Multifunction is ,
//SpecInfo v1.3.1.sma:
//Description:
//This plugin displays a list of spectators currently viewing the live player.
//This list is visible to the living player as well as other players currently
//spectating that player. Also spectators can see which movement commands the
//the live player is using.
//Commands:
//say /speclist : Toggle viewing list of spectators.
//say /speckeys : Toggle viewing keys of player you are spectating.
//say /spechide : Immune admins toggle whether or not they're hidden from list.
//say /showkeys : View your own keys on screen while alive.
-
- #include <amxmodx>
- #include <amxmisc>
- #include <engine>
- #include <fakemeta>
- new const VERSION[ ] = "1.3.1"
- new const TRKCVAR[ ] = "specinfo_version"
- #define IMMUNE_FLAG ADMIN_IMMUNITY
- #define KEYS_STR_LEN 31
- #define LIST_STR_LEN 610
- #define BOTH_STR_LEN KEYS_STR_LEN + LIST_STR_LEN
- //cl_prefs constants
- #define FL_LIST ( 1 << 0 )
- #define FL_KEYS ( 1 << 1 )
- #define FL_OWNKEYS ( 1 << 2 )
- #define FL_HIDE ( 1 << 3 )
- //cvar pointers
- new p_enabled, p_list_enabled, p_keys_enabled, p_list_default, p_keys_default;
- new p_red, p_grn, p_blu, p_immunity;
- //data arrays
- new cl_keys[33], cl_prefs[33];
- new keys_string[33][KEYS_STR_LEN + 1], list_string[33][LIST_STR_LEN + 1]
- new cl_names[33][21], spec_ids[33][33];
- public plugin_init( )
- {
- register_plugin( "SpecInfo", VERSION, "Ian Cammarata" );
- register_cvar( TRKCVAR, VERSION, FCVAR_SERVER );
- set_cvar_string( TRKCVAR, VERSION );
-
- p_enabled = register_cvar( "si_enabled", "1" );
- p_list_enabled = register_cvar( "si_list_enabled", "1" );
- p_keys_enabled = register_cvar( "si_keys_enabled", "1" );
- p_list_default = register_cvar( "si_list_default", "1" );
- p_keys_default = register_cvar( "si_keys_default", "1" );
- p_immunity = register_cvar( "si_immunity", "1" );
- p_red = register_cvar( "si_msg_r", "45" );
- p_grn = register_cvar( "si_msg_g", "89" );
- p_blu = register_cvar( "si_msg_b", "116" );
-
- register_clcmd( "say /speclist", "toggle_list", _, "Toggle spectator list." );
- register_clcmd( "say /speckeys", "toggle_keys", _, "Toggle spectator keys." );
- register_clcmd( "say /showkeys", "toggle_ownkeys", _, "Toggle viewing own keys." );
- register_clcmd( "say /spechide", "toggle_hide", IMMUNE_FLAG, "Admins toggle being hidden from list." );
-
- set_task( 1.0, "list_update", _, _, _, "b" );
- set_task( 0.1, "keys_update", _, _, _, "b" );
-
- register_dictionary( "specinfo.txt" );
- }
- public client_connect( id )
- {
- cl_prefs[id] = 0;
- if( !is_user_bot( id ) )
- {
- if( get_pcvar_num( p_list_default ) ) cl_prefs[id] |= FL_LIST;
- if( get_pcvar_num( p_keys_default ) ) cl_prefs[id] |= FL_KEYS;
- }
- get_user_name( id, cl_names[id], 20 );
- return PLUGIN_CONTINUE;
- }
- public client_infochanged( id )
- {
- get_user_name( id, cl_names[id], 20 );
- return PLUGIN_CONTINUE;
- }
- public list_update( )
- {
- if( get_pcvar_num( p_enabled ) && get_pcvar_num ( p_list_enabled ) )
- {
- new players[32], num, id, id2, i, j;
- for( i = 1; i < 33; i++ ) spec_ids[i][0] = 0;
-
- get_players( players, num, "bch" );
- for( i = 0; i < num; i++ )
- {
- id = players[i];
- if( !( get_user_flags( id ) & IMMUNE_FLAG && get_pcvar_num( p_immunity ) && cl_prefs[id] & FL_HIDE ) )
- {
- id2 = pev( id, pev_iuser2 );
- if( id2 )
- {
- spec_ids[ id2 ][ 0 ]++;
- spec_ids[ id2 ][ spec_ids[ id2 ][ 0 ] ] = id;
- }
- }
- }
- new tmplist[ LIST_STR_LEN + 1 ], tmpstr[41];
- new count, namelen, tmpname[21];
- for( i=1; i<33; i++ )
- {
- count = spec_ids[i][0];
- if( count )
- {
- namelen = ( LIST_STR_LEN - 10 ) / count;
- clamp( namelen, 10, 20 );
- format( tmpname, namelen, cl_names[i] );
- formatex( tmplist, LIST_STR_LEN - 1, "^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t(%d) %s %s:^n", count, "%L", tmpname);
- for( j=1; j<=count; j++ )
- {
- format( tmpname, namelen, cl_names[spec_ids[i][j]]);
- formatex( tmpstr, 40, "^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t%s", tmpname );
- if( strlen( tmplist ) + strlen( tmpstr ) + ( 11 - j ) < ( LIST_STR_LEN - 1 ) )
- format( tmplist, LIST_STR_LEN - 10, "%s%s^n", tmplist, tmpstr );
- else
- {
- format( tmplist, LIST_STR_LEN, "%s...^n", tmplist );
- break;
- }
- }
- if( count < 10 )
- format( tmplist, LIST_STR_LEN,
- "%s^n^n^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^tSpecInfo v%s^n",
- tmplist, VERSION
- );
- for( j+=0; j<10; j++ )
- format( tmplist, LIST_STR_LEN, "%s%s", tmplist, "^n" );
- list_string[i] = tmplist;
- }
- }
- get_players( players, num, "ch" );
- for( i=0; i<num; i++ ) clmsg( players[i] );
- }
- return PLUGIN_HANDLED;
- }
- public keys_update( )
- {
- if( !get_pcvar_num( p_enabled ) && !get_pcvar_num( p_keys_enabled ) ) return;
- new players[32], num, id, i;
- get_players( players, num, "a" );
- for( i = 0; i < num; i++ )
- {
- id = players[i];
- formatex( keys_string[id], KEYS_STR_LEN, " ^n^t^t%s^t^t^t%s^n^t%s %s %s^t^t%s",
- cl_keys[id] & IN_FORWARD ? "W" : " .",
- "%L",
- cl_keys[id] & IN_MOVELEFT ? "A" : ".",
- cl_keys[id] & IN_BACK ? "S" : ".",
- cl_keys[id] & IN_MOVERIGHT ? "D" : ".",
- "%L"
- );
-
- //Flags stored in string to fill translation char in clmsg function
- keys_string[id][0] = 0;
- if( cl_keys[id] & IN_JUMP ) keys_string[id][0] |= IN_JUMP;
- if( cl_keys[id] & IN_DUCK ) keys_string[id][0] |= IN_DUCK;
-
- cl_keys[id] = 0;
- }
-
- new id2;
- get_players( players, num, "ch" );
- for( i=0; i<num; i++ )
- {
- id = players[i];
- if( is_user_alive( id ) )
- {
- if( cl_prefs[id] & FL_OWNKEYS ) clmsg( id );
- }
- else
- {
- id2 = pev( id, pev_iuser2 );
- if( cl_prefs[id] & FL_KEYS && id2 && id2 != id ) clmsg( id );
- }
- }
- }
- public server_frame( )
- {
- if( get_pcvar_num( p_enabled ) && get_pcvar_num( p_keys_enabled ) )
- {
- new players[32], num, id;
- get_players( players, num, "a" );
- for( new i = 0; i < num; i++ )
- {
- id = players[i];
- if( get_user_button( id ) & IN_FORWARD )
- cl_keys[id] |= IN_FORWARD;
- if( get_user_button( id ) & IN_BACK )
- cl_keys[id] |= IN_BACK;
- if( get_user_button( id ) & IN_MOVELEFT )
- cl_keys[id] |= IN_MOVELEFT;
- if( get_user_button( id ) & IN_MOVERIGHT )
- cl_keys[id] |= IN_MOVERIGHT;
- if( get_user_button( id ) & IN_DUCK )
- cl_keys[id] |= IN_DUCK;
- if( get_user_button( id ) & IN_JUMP )
- cl_keys[id] |= IN_JUMP;
- }
- }
- return PLUGIN_CONTINUE
- }
- public clmsg( id )
- {
- if( !id ) return;
-
- new prefs = cl_prefs[id];
-
- new bool:show_own = false;
- if( is_user_alive( id ) && prefs & FL_OWNKEYS ) show_own = true;
-
- if( is_user_alive( id ) && !show_own )
- {
- if( prefs & FL_LIST && spec_ids[id][0] && get_pcvar_num( p_list_enabled ) )
- {
- set_hudmessage(
- get_pcvar_num( p_red ),
- get_pcvar_num( p_grn ),
- get_pcvar_num( p_blu ),
- 0.7, /*x*/
- 0.1, /*y*/
- 0, /*fx*/
- 0.0, /*fx time*/
- 1.1, /*hold time*/
- 0.1, /*fade in*/
- 0.1, /*fade out*/
- 3 /*chan*/
- );
- show_hudmessage( id, list_string[id], id, "SPECTATING" );
- }
- }
- else
- {
- new id2;
- if( show_own ) id2 = id;
- else id2 = pev( id, pev_iuser2 );
- if( !id2 ) return;
-
- if( prefs & FL_LIST || prefs & FL_KEYS || show_own )
- {
- set_hudmessage(
- get_pcvar_num( p_red ),
- get_pcvar_num( p_grn ),
- get_pcvar_num( p_blu ),
- 0.48, /*x*/
- 0.14, /*y*/
- 0, /*fx*/
- 0.0, /*fx time*/
- prefs & FL_KEYS || show_own ? 0.1 : 1.1, /*hold time*/
- 0.1, /*fade in*/
- 0.1, /*fade out*/
- 3 /*chan*/
- );
- new msg[BOTH_STR_LEN + 1];
- if( prefs & FL_LIST && get_pcvar_num( p_list_enabled ) && spec_ids[id2][0] )
- formatex(msg,BOTH_STR_LEN,list_string[id2],id,"SPECTATING");
- else msg ="^n^n^n^n^n^n^n^n^n^n^n^n";
- if( get_pcvar_num( p_keys_enabled ) && ( prefs & FL_KEYS || show_own ) )
- {
- format( msg, BOTH_STR_LEN, "%s%s", msg, keys_string[id2][1] );
- format( msg, BOTH_STR_LEN, msg,
- id, keys_string[id2][0] & IN_JUMP ? "JUMP" : "LAME",
- id, keys_string[id2][0] & IN_DUCK ? "DUCK" : "LAME"
- );
- }
- show_hudmessage( id, msg );
- }
- }
- }
- public set_hudmsg_flg_notify( )
- {
- set_hudmessage(
- get_pcvar_num( p_red ),
- get_pcvar_num( p_grn ),
- get_pcvar_num( p_blu ),
- -1.0, /*x*/
- 0.8, /*y*/
- 0, /*fx*/
- 0.0, /*fx time*/
- 3.0, /*hold time*/
- 0.0, /*fade in*/
- 0.0, /*fade out*/
- -1 /*chan*/
- );
- }
- public toggle_list( id )
- {
- set_hudmsg_flg_notify( );
- cl_prefs[id] ^= FL_LIST;
- show_hudmessage( id, "%L", id, cl_prefs[id] & FL_LIST ? "SPEC_LIST_ENABLED" : "SPEC_LIST_DISABLED" );
- return PLUGIN_HANDLED;
- }
- public toggle_keys( id )
- {
- set_hudmsg_flg_notify( );
- cl_prefs[id] ^= FL_KEYS;
- show_hudmessage( id, "%L", id, cl_prefs[id] & FL_KEYS ? "SPEC_KEYS_ENABLED" : "SPEC_KEYS_DISABLED" );
- return PLUGIN_HANDLED;
- }
- public toggle_ownkeys( id )
- {
- set_hudmsg_flg_notify( );
- cl_prefs[id] ^= FL_OWNKEYS;
- show_hudmessage( id, "%L", id, cl_prefs[id] & FL_OWNKEYS ? "SPEC_OWNKEYS_ENABLED" : "SPEC_OWNKEYS_DISABLED" );
- return PLUGIN_HANDLED;
- }
- public toggle_hide( id, level, cid )
- {
- if( cmd_access( id, level, cid, 0 ) )
- {
- set_hudmsg_flg_notify( );
- cl_prefs[id] ^= FL_HIDE;
- show_hudmessage( id, "%L", id, cl_prefs[id] & FL_HIDE ? "SPEC_HIDE_ENABLED" : "SPEC_HIDE_DISABLED" );
- }
- return PLUGIN_HANDLED;
- }
复制代码 |
|