Правила форума Гаранты форума
Размещение рекламы AMX-X компилятор

Здравствуйте, гость Вход | Регистрация

Наши новости:

14-дек
24-апр
10-апр
11-апр

> Правила форума

Этот раздел, как вы могли заметить по названию, предназначен для решения вопросов по поводу уже существующих модов и плагинов.
Пожалуйста, если у вас проблема с написанием плагина, не путайте этот раздел с разделом по скриптингу.
Для поиска плагинов и модов существует соответствующий раздел.

Название темы должно соответствовать содержанию. Темы с названием типа "Помогите", "Вопрос", "парни подскажите..." - будут удалены.
Все темы, не относящиеся к "Вопросам по модам и плагинам", будут удалены или перемещены в соответствующий раздел.

Правила оформления темы:
1. Помимо заголовка не забудьте верно сформулировать свой вопрос.
2. Выложите исходник (в тег кода + ) или ссылку на плагин который вызывает у вас вопросы.
3. Выложите лог с ошибками (если имеется) под спойлер

Ошибка при компиляции!

Статус пользователя default67
сообщение 4.4.2015, 12:41
Сообщение #1


Стаж: 11 лет

Сообщений: 121
Благодарностей: 11
Полезность: < 0

Всем Привет!)
Имеется у меня плагин "ShowKeys" - он показывает клавиши, которые нажимает игрок, за которым вы следите.
Проблема такова: Вместо "Duck и Jump" я поставил "Приседание и Прыжок" , но при компиляции вылазит 2 ошибки:

Код:
error 047: array sizes do not match, or destination array is too small
error 047: array sizes do not match, or destination array is too small


А когда ставлю обратно: Duck и Jump , то плагин успешно компилируется!

Код:
#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] = "Приседание"
g_srv_struct[2][6] = "Прыжок"
g_srv_struct[2][7] = " "
g_srv_struct[2][8] = " "
g_srv_struct[2][9] = " "

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)
}
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   Цитировать сообщение
Статус пользователя STR@TEG
сообщение 4.4.2015, 13:32
Сообщение #2
Стаж: 16 лет

Сообщений: 4186
Благодарностей: 1763
Полезность: 837

Строка 24: изменить размер третьего измерения на нужный.
Строка 235: изменить размер массивов на нужный.
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
Поблагодарили 1 раз
   + Цитировать сообщение
Статус пользователя STR@TEG
сообщение 4.4.2015, 13:39
Сообщение #3
Стаж: 16 лет

Сообщений: 4186
Благодарностей: 1763
Полезность: 837

Еще вариант заменить 235 строку на эту:
Код:
new kw[sizeof(g_srv_struct[][])], ka[sizeof(g_srv_struct[][])], ks[sizeof(g_srv_struct[][])], kd[sizeof(g_srv_struct[][])], kjump[sizeof(g_srv_struct[][])], kduck[sizeof(g_srv_struct[][])];
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
Поблагодарили 1 раз
   + Цитировать сообщение
Статус пользователя default67
сообщение 4.4.2015, 13:43
Сообщение #4


Стаж: 11 лет

Сообщений: 121
Благодарностей: 11
Полезность: < 0

Цитата(STR@TEG @ 4.4.2015, 13:32) *
Строка 24: изменить размер третьего измерения на нужный.
Строка 235: изменить размер массивов на нужный.

Сделал так:
Код:
#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][12]

// 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] = "Приседание"
g_srv_struct[2][6] = "Прыжок"
g_srv_struct[2][7] = " "
g_srv_struct[2][8] = " "
g_srv_struct[2][9] = " "

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[12], kduck[12]



#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)
}


Ошибок стало ещё больше:
Код:
hlds/web/www/amxxpc/work/scripting/showkeys.sma(107 -- 108) : error 047: array sizes do not match, or destination array is too small
05
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(108 -- 109) : error 047: array sizes do not match, or destination array is too small
06
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(262 -- 263) : error 047: array sizes do not match, or destination array is too small
07
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(266 -- 267) : error 047: array sizes do not match, or destination array is too small
08
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(271 -- 272) : error 047: array sizes do not match, or destination array is too small
09
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(275 -- 276) : error 047: array sizes do not match, or destination array is too small
10
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(280 -- 281) : error 047: array sizes do not match, or destination array is too small
11
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(284 -- 285) : error 047: array sizes do not match, or destination array is too small
12
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(289 -- 290) : error 047: array sizes do not match, or destination array is too small
13
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(293 -- 294) : error 047: array sizes do not match, or destination array is too small

Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   + Цитировать сообщение
Статус пользователя STR@TEG
сообщение 4.4.2015, 13:45
Сообщение #5
Стаж: 16 лет

Сообщений: 4186
Благодарностей: 1763
Полезность: 837

default67, в 235 строке размерность нужно увеличивать всем массивам.
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
Поблагодарили 1 раз
   + Цитировать сообщение
Статус пользователя default67
сообщение 4.4.2015, 13:50
Сообщение #6


Стаж: 11 лет

Сообщений: 121
Благодарностей: 11
Полезность: < 0

Цитата(STR@TEG @ 4.4.2015, 13:45) *
default67, в 235 строке размерность нужно увеличивать всем массивам.

На всех массивах поставил одно и тоже значение "12", он опять же компилятор выдает ошибку на эту же самую строчку: 107 - 108
Код:
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(107) : error 032: array index out of bounds (variable "g_srv_struct")
5
/hlds/web/www/amxxpc/work/scripting/showkeys.sma(108) : error 032: array index out of bounds (variable "g_srv_struct")


Код:
#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][12]

// 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] = "Приседание"
g_srv_struct[2][6] = "Прыжок"
g_srv_struct[2][7] = " "
g_srv_struct[2][8] = " "
g_srv_struct[2][9] = " "

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[12], ka[12], ks[12], kd[12], kjump[12], kduck[12]



#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)
}


Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   + Цитировать сообщение
Статус пользователя STR@TEG
сообщение 4.4.2015, 13:57
Сообщение #7
Стаж: 16 лет

Сообщений: 4186
Благодарностей: 1763
Полезность: 837

default67, ставь размерность 22. Русские символы занимают больше места.
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
Поблагодарили 1 раз
   + Цитировать сообщение
Статус пользователя default67
сообщение 4.4.2015, 14:00
Сообщение #8


Стаж: 11 лет

Сообщений: 121
Благодарностей: 11
Полезность: < 0

Цитата(STR@TEG @ 4.4.2015, 13:57) *
default67, ставь размерность 22. Русские символы занимают больше места.

Спасибо, плагин успешно скомпилировался!
Код:
#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[22][22][22]

// 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] = "Приседание"
g_srv_struct[2][6] = "Прыжок"
g_srv_struct[2][7] = " "
g_srv_struct[2][8] = " "
g_srv_struct[2][9] = " "

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[22], ka[22], ks[22], kd[22], kjump[22], kduck[22]



#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)
}
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   + Цитировать сообщение
Статус пользователя STR@TEG
сообщение 4.4.2015, 14:03
Сообщение #9
Стаж: 16 лет

Сообщений: 4186
Благодарностей: 1763
Полезность: 837

default67, у массива g_srv_struct в 24 строке не стоило менять размер первых двух измерений. Хотя плагин и скомпилировался без ошибок, они могут возникнуть во время его работы.
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   + Цитировать сообщение
Статус пользователя default67
сообщение 4.4.2015, 14:13
Сообщение #10


Стаж: 11 лет

Сообщений: 121
Благодарностей: 11
Полезность: < 0

Цитата(STR@TEG @ 4.4.2015, 14:03) *
default67, у массива g_srv_struct в 24 строке не стоило менять размер первых двух измерений. Хотя плагин и скомпилировался без ошибок, они могут возникнуть во время его работы.

Изменил. Но есть ещё не большая проблема, когда я BHOP делаю с помощью кнопки "Space" у меня в ShowKeys показывает Прыжок и сразу исчезает, а когда зажимаю Space то не исчезает, а вот когда делаю BHOP с помощью колесика то Прыжок показывает частично, а когда показывает то моргает, а я хочу что бы оно чётко показывало Прыжок, и исчезло.
Код:
#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][22]

// 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] = "Приседание"
g_srv_struct[2][6] = "Прыжок"
g_srv_struct[2][7] = " "
g_srv_struct[2][8] = " "

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[22], ka[22], ks[22], kd[22], kjump[22], kduck[22]



#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)
}
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   + Цитировать сообщение
Статус пользователя STR@TEG
сообщение 4.4.2015, 14:51
Сообщение #11
Стаж: 16 лет

Сообщений: 4186
Благодарностей: 1763
Полезность: 837

Цитата(default67 @ 4.4.2015, 16:13) *
Изменил. Но есть ещё не большая проблема, когда я BHOP делаю с помощью кнопки "Space" у меня в ShowKeys показывает Прыжок и сразу исчезает, а когда зажимаю Space то не исчезает, а вот когда делаю BHOP с помощью колесика то Прыжок показывает частично, а когда показывает то моргает, а я хочу что бы оно чётко показывало Прыжок, и исчезло.
Для начала попробовать keys_channel -1. Но скорее всего дело в том, что текст отрисовывается каждый кадр. Можно, конечно, сделать кучу проверок на то, что сейчас выводится на экран и стоит ли обновлять информацию, но это создаст нагрузку (высокую или низкую - не знаю) и, возможно, это быдлокод.
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
Поблагодарили 1 раз
   + Цитировать сообщение
Статус пользователя default67
сообщение 4.4.2015, 16:23
Сообщение #12


Стаж: 11 лет

Сообщений: 121
Благодарностей: 11
Полезность: < 0

Цитата(STR@TEG @ 4.4.2015, 14:51) *
Для начала попробовать keys_channel -1. Но скорее всего дело в том, что текст отрисовывается каждый кадр. Можно, конечно, сделать кучу проверок на то, что сейчас выводится на экран и стоит ли обновлять информацию, но это создаст нагрузку (высокую или низкую - не знаю) и, возможно, это быдлокод.

keys_channel -1 - не работает!
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   + Цитировать сообщение
  Ответить в данную темуНачать новую тему
 
0 пользователей и 1 гостей читают эту тему: