Помогите скомпилировать плагин

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
27
Реакции
0
Ошибка
error 047: array sizes do not match, or destination array is too small
Компилятор
Локальный
Amx Mod X
1.9.0
Исходный код
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#include <hook>

public stock const PluginName[] = "Hook"
public stock const PluginVersion[] = "4.0.0"
public stock const PluginAuthor[] = "twisterniq"

/****************************************************************************************
****************************************************************************************/

// Path to the sprite of the hook
new const SPRITE[] = "sprites/hook/yellow_circle.spr"

/****************************************************************************************
****************************************************************************************/

#define CHECK_NATIVE_PLAYER(%0,%1) \
if (!is_user_valid(%0)) \
{ \
log_error(AMX_ERR_NATIVE, "Player out of range (%d).", %0); \
return %1; \
}

// Checks for whether the player is in air or not
const FL_ONGROUND2 = (FL_ONGROUND | FL_PARTIALGROUND | FL_INWATER | FL_CONVEYOR | FL_FLOAT)

enum _:Forwards
{
FWD_ACCESS_MODIFIED,
FWD_ON_START,
FWD_ON_FINISH,
FWD_ON_USE
}

enum _:CVars
{
CVAR_ENABLED,
CVAR_DEFAULT_TYPE,
Float:CVAR_DEFAULT_SPEED,
Float:CVAR_MIN_SPEED,
Float:CVAR_MAX_SPEED,
CVAR_LIFETIME
}

enum _:PlayerStruct
{
ACCESS_LEVEL,
TYPE,
Float:SPEED,
bool:USING,
bool:NEED_REFRESH,
HOOK_ORIGIN[3]
}

new g_pSprite

new g_hForwards[Forwards]
new g_eCVars[CVars]
new g_ePlayerData[MAX_PLAYERS + 1][PlayerStruct]

public plugin_precache()
{
register_plugin(PluginName, PluginVersion, PluginAuthor)

if (!file_exists(SPRITE))
{
set_fail_state("Sprite ^"%s^" doesn't exist", SPRITE)
}

g_pSprite = precache_model(SPRITE)
}

public plugin_init()
{
register_dictionary("hook.txt")

register_clcmd("+hook", "enableHook")
register_clcmd("-hook", "disableHook")

RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn_Post", true)
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", true)
RegisterHookChain(RG_CBasePlayer_PreThink, "CBasePlayer_PreThink_Post", true)

g_hForwards[FWD_ACCESS_MODIFIED] = CreateMultiForward("hook_access_modified", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
g_hForwards[FWD_ON_START] = CreateMultiForward("hook_on_start", ET_STOP, FP_CELL)
g_hForwards[FWD_ON_FINISH] = CreateMultiForward("hook_on_finish", ET_IGNORE, FP_CELL)
g_hForwards[FWD_ON_USE] = CreateMultiForward("hook_on_use", ET_STOP, FP_CELL)

createCVars()
}

createCVars()
{
bind_pcvar_num(
create_cvar(
.name = "hook_enabled",
.string = "1",
.flags = FCVAR_NONE,
.description = fmt("%L", LANG_SERVER, "HOOK_CVAR_ENABLED"),
.has_min = true,
.min_val = 0.0,
.has_max = true,
.max_val = 1.0
), g_eCVars[CVAR_ENABLED]
)

bind_pcvar_num(
create_cvar(
.name = "hook_default_type",
.string = "0",
.flags = FCVAR_NONE,
.description = fmt("%L", LANG_SERVER, "HOOK_CVAR_DEFAULT_TYPE"),
.has_min = true,
.min_val = 0.0,
.has_max = true,
.max_val = 1.0
), g_eCVars[CVAR_DEFAULT_TYPE]
)

bind_pcvar_float(
create_cvar(
.name = "hook_default_speed",
.string = "700",
.flags = FCVAR_NONE,
.description = fmt("%L", LANG_SERVER, "HOOK_CVAR_DEFAULT_SPEED"),
.has_min = true,
.min_val = 1.0
), g_eCVars[CVAR_DEFAULT_SPEED]
)

bind_pcvar_float(
create_cvar(
.name = "hook_min_speed",
.string = "500",
.flags = FCVAR_NONE,
.description = fmt("%L", LANG_SERVER, "HOOK_CVAR_MIN_SPEED"),
.has_min = true,
.min_val = 1.0
), g_eCVars[CVAR_MIN_SPEED]
)

bind_pcvar_float(
create_cvar(
.name = "hook_max_speed",
.string = "1400",
.flags = FCVAR_NONE,
.description = fmt("%L", LANG_SERVER, "HOOK_CVAR_MAX_SPEED"),
.has_min = true,
.min_val = 1.0
), g_eCVars[CVAR_MAX_SPEED]
)

bind_pcvar_num(
create_cvar(
.name = "hook_lifetime",
.string = "2",
.flags = FCVAR_NONE,
.description = fmt("%L", LANG_SERVER, "HOOK_CVAR_LIFETIME"),
.has_min = true,
.min_val = 0.0,
.has_max = true,
.max_val = 25.0
), g_eCVars[CVAR_LIFETIME]
)

AutoExecConfig(true, "hook")
}

public plugin_natives()
{
register_native("hook_set_user_access", "native_hook_set_user_access")
register_native("hook_get_user_access", "native_hook_get_user_access")
register_native("hook_set_user_type", "native_hook_set_user_type")
register_native("hook_get_user_type", "native_hook_get_user_type")
register_native("hook_set_user_speed", "native_hook_set_user_speed")
register_native("hook_get_user_speed", "native_hook_get_user_speed")
register_native("hook_is_using", "native_hook_is_using")
register_native("hook_disable", "native_hook_disable")
}

public native_hook_set_user_access()
{
enum { arg_player = 1, arg_level }

new id = get_param(arg_player)
new iNewLevel = get_param(arg_level)
new iOldLevel

if (id)
{
CHECK_NATIVE_PLAYER(id, false)

iOldLevel = g_ePlayerData[id][ACCESS_LEVEL]
g_ePlayerData[id][ACCESS_LEVEL] = iNewLevel

ExecuteForward(g_hForwards[FWD_ACCESS_MODIFIED], _, id, iOldLevel, iNewLevel)
}
else
{
for (new i = 1; i <= MaxClients; i++)
{
if (!is_user_connected(i))
{
continue
}

iOldLevel = g_ePlayerData[i][ACCESS_LEVEL]
g_ePlayerData[i][ACCESS_LEVEL] = iNewLevel

ExecuteForward(g_hForwards[FWD_ACCESS_MODIFIED], _, i, iOldLevel, iNewLevel)
}
}

return true
}

public native_hook_get_user_access()
{
enum { arg_player = 1 }

new id = get_param(arg_player)
CHECK_NATIVE_PLAYER(id, false)

return g_ePlayerData[id][ACCESS_LEVEL]
}

public native_hook_set_user_type()
{
enum { arg_player = 1, arg_type }

new id = get_param(arg_player)
new iType = clamp(get_param(arg_type), HT_FIXED, HookType)

if (id)
{
CHECK_NATIVE_PLAYER(id, false)
}

setNativeValue(id, TYPE, iType)
return true
}

public native_hook_get_user_type()
{
enum { arg_player = 1 }

new id = get_param(arg_player)
CHECK_NATIVE_PLAYER(id, false)

return g_ePlayerData[id][TYPE]
}

public native_hook_set_user_speed()
{
enum { arg_player = 1, arg_speed }

new id = get_param(arg_player)
new Float:flSpeed = floatclamp(
get_param_f(arg_speed),
g_eCVars[CVAR_MIN_SPEED],
g_eCVars[CVAR_MAX_SPEED]
)

if (id)
{
CHECK_NATIVE_PLAYER(id, false)
}

setNativeValue(id, SPEED, flSpeed)
return true
}

public Float:native_hook_get_user_speed()
{
enum { arg_player = 1 }

new id = get_param(arg_player)
CHECK_NATIVE_PLAYER(id, 0.0)

return g_ePlayerData[id][SPEED]
}

public bool:native_hook_is_using()
{
enum { arg_player = 1 }

new id = get_param(arg_player)
CHECK_NATIVE_PLAYER(id, false)

return g_ePlayerData[id][USING]
}

public bool:native_hook_disable()
{
enum { arg_player = 1 }

new id = get_param(arg_player)

if (id)
{
CHECK_NATIVE_PLAYER(id, false)
disableHook(id)
}
else
{
for (new i = 1; i <= MaxClients; i++)
{
disableHook(i)
}
}

return true
}

setNativeValue(const id, type, any:value)
{
if (id)
{
g_ePlayerData[id][type] = value
}
else
{
for (new i = 1; i <= MaxClients; i++)
{
if (!is_user_connected(i))
{
continue
}

g_ePlayerData[i][type] = value
}
}
}

public CBasePlayer_Spawn_Post(const id)
{
disableHook(id)
}

public CBasePlayer_Killed_Post(const iVictim)
{
disableHook(iVictim)
}

public CBasePlayer_PreThink_Post(const id)
{
if (!g_ePlayerData[id][USING])
{
return
}

hookThink(id)
}

hookThink(const id)
{
static iRet
ExecuteForward(g_hForwards[FWD_ON_USE], iRet, id)

if (iRet == HOOK_BLOCKED)
{
disableHook(id)
return
}

static iOrigin[3], Float:flVelocity[3], iDistance

if (g_ePlayerData[id][TYPE] == HT_FREE)
{
get_user_origin(id, g_ePlayerData[id][HOOK_ORIGIN], Origin_AimEndEyes)
}

get_user_origin(id, iOrigin)
iDistance = get_distance(g_ePlayerData[id][HOOK_ORIGIN], iOrigin)

if (iDistance > 25)
{
flVelocity[0] = (g_ePlayerData[id][HOOK_ORIGIN][0] - iOrigin[0]) * (g_ePlayerData[id][SPEED] / iDistance)
flVelocity[1] = (g_ePlayerData[id][HOOK_ORIGIN][1] - iOrigin[1]) * (g_ePlayerData[id][SPEED] / iDistance)
flVelocity[2] = (g_ePlayerData[id][HOOK_ORIGIN][2] - iOrigin[2]) * (g_ePlayerData[id][SPEED] / iDistance)
}

set_entvar(id, var_velocity, flVelocity)
}

public client_putinserver(id)
{
g_ePlayerData[id][TYPE] = g_eCVars[CVAR_DEFAULT_TYPE]

if (g_ePlayerData[id][SPEED] == 0.0)
{
g_ePlayerData[id][SPEED] = g_eCVars[CVAR_DEFAULT_SPEED]
}
}

public client_disconnected(id)
{
disableHook(id)
arrayset(g_ePlayerData[id], 0, PlayerStruct)
}

public enableHook(const id)
{
if (!g_eCVars[CVAR_ENABLED])
{
// Hook is disabled
return PLUGIN_HANDLED
}

if (!g_ePlayerData[id][ACCESS_LEVEL])
{
// Player has no access
return PLUGIN_HANDLED
}

if (!is_user_alive(id))
{
// Player cannot use hook when is dead
return PLUGIN_HANDLED
}

new iRet
ExecuteForward(g_hForwards[FWD_ON_START], iRet, id)

if (iRet == HOOK_BLOCKED)
{
// It's not allowed to use it now
return PLUGIN_HANDLED
}

// warmup, weekend, wanted count

if (g_ePlayerData[id][TYPE] == HT_FIXED)
{
// Gets where player currently is looking -- Added by brody in version 3.1.0
get_user_origin(id, g_ePlayerData[id][HOOK_ORIGIN], Origin_AimEndEyes)
}

if (!task_exists(id))
{
removeTrail(id)
setTrail(id)
set_task_ex(0.1, "taskTrail", id, .flags = SetTask_Repeat)
}

g_ePlayerData[id][USING] = true

return PLUGIN_HANDLED
}

public disableHook(const id)
{
if (g_ePlayerData[id][USING])
{
g_ePlayerData[id][USING] = false
ExecuteForward(g_hForwards[FWD_ON_FINISH], _, id)
}

return PLUGIN_HANDLED
}

setTrail(const id)
{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMFOLLOW)
write_short(id) // entity
write_short(g_pSprite) // sprite index
write_byte(g_eCVars[CVAR_LIFETIME] * 10) // life
write_byte(15) // width
write_byte(255) // red
write_byte(255) // green
write_byte(255) // blue
write_byte(255) // brightness
message_end()
}

removeTrail(const id)
{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_KILLBEAM)
write_short(id)
message_end()
}

public taskTrail(const id)
{
if (!is_user_alive(id)
|| !g_ePlayerData[id][USING] && get_entvar(id, var_flags) & FL_ONGROUND2)
{
remove_task(id)
removeTrail(id)
return
}

static Float:flVelocity[3]
get_entvar(id, var_velocity, flVelocity)

if (vector_length(flVelocity) < 10.0)
{
g_ePlayerData[id][NEED_REFRESH] = true
}
else if (g_ePlayerData[id][NEED_REFRESH])
{
g_ePlayerData[id][NEED_REFRESH] = false
removeTrail(id)
setTrail(id)
}
}

stock bool:is_user_valid(const id)
{
return (id > 0 && id <= MaxClients)
}
Добрый день. Помогите скомпилировать плагин. Исходник, инклюд и ошибку компилятора прикрепил.
 
В этой теме было размещено решение! Перейти к решению.

Download all Attachments

Сообщения
1,082
Реакции
58
Помог
11 раз(а)
g_ePlayerData размерность массива проверь
 

fgd

Сообщения
92
Реакции
25
Помог
12 раз(а)
Функция get_user_origin ожидает аргумент в виде ссылки на массив размером [3] для хранения координат, но вы передаете ей элемент структуры HOOK_ORIGIN, который сам по себе является массивом. В AMX Mod X, при передаче массива из структуры, вам нужно обеспечить, что передаваемый элемент массива действительно соответствует ожидаемому формату и размеру, ожидаемому функцией.

Чтобы исправить эту ошибку, вам нужно убедиться, что передача массива HOOK_ORIGIN из структуры g_ePlayerData происходит корректно. Вам необходимо передать ссылку на первый элемент массива. Вот как это можно сделать:

C++:
new Float:origin[3];
get_user_origin(id, origin, Origin_AimEndEyes);
g_ePlayerData[id][HOOK_ORIGIN][0] = origin[0];
g_ePlayerData[id][HOOK_ORIGIN][1] = origin[1];
g_ePlayerData[id][HOOK_ORIGIN][2] = origin[2];
 
Сообщения
16
Реакции
0
Помог
2 раз(а)
Готово, добавил g_iHookOrigin[id]

Можно закрывать.
 

Вложения

  • 12.3 KB Просмотры: 29
Последнее редактирование модератором:
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу