- 听众
- 收听
- 积分
- 3894
- 主题
- 回帖
- 0
- 精华
注册时间2008-4-22
最后登录1970-1-1
该用户从未签到
|
发表于 2010-3-19 14:11:32
|
显示全部楼层
-
- #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)
- }
复制代码 |
|