Участник
Пользователь
- Сообщения
- 893
- Реакции
- 149
- Помог
- 25 раз(а)
Привет всем. Столкнулся с проблемой, что не могу корректно получить айди оружия.
Суть такова, что мне нужно прибавить (да-да, не установить, а прибавить к уже тем патронам, которые выдаются после покупке) патроны в запаску при покупке оружия. (Именно при покупке, хук для этого у меня есть). Но в этом хуке я не могу понять, как получить айди оружия. Пытался разными способами - не помогло.
Код ниже.
Суть такова, что мне нужно прибавить (да-да, не установить, а прибавить к уже тем патронам, которые выдаются после покупке) патроны в запаску при покупке оружия. (Именно при покупке, хук для этого у меня есть). Но в этом хуке я не могу понять, как получить айди оружия. Пытался разными способами - не помогло.
Код ниже.
Код:
#include <AmxModX>
#include <ReApi>
#include <SqlX>
new szInfoPlugin[][] = {
"[UPGRADE] Addon: Weapon Menu Upgrade",
"0.1",
"Immortal-"
};
/*~ Нативы ~*/
native upgrade_get_user_points(iPlayer);
native upgrade_set_user_points(iPlayer, iParam);
native upgrade_get_user_hour(iPlayer);
native upgrade_get_user_min(iPlayer);
native upgrade_get_user_sec(iPlayer);
#define DEBUG
/*~ Энами ~*/
enum _:iMassive{
PLAYER_DAMAGE,
PLAYER_DAMAGE_LIMIT,
PLAYER_AMMO,
PLAYER_AMMO_LIMIT,
PLAYER_BPAMMO,
PLAYER_BPAMMO_LIMIT
};
enum Cvar {
g_iSqlHost[32],
g_iSqlUser[32],
g_iSqlPass[32],
g_iSqlNameDb[32],
g_iSqlTable[32],
/*~ Урон ~*/
g_iLimitDamage,
g_iCostDamage,
g_iAddDamage,
/*~ Патроны ~*/
g_iLimitAmmo,
g_iCostAmmo,
g_iAddAmmo,
/*~ Запасные патроны ~*/
g_iLimitBpAmmo,
g_iCostBpAmmo,
g_iAddBpAmmo
};
/*~ Массивы ~*/
new
g_szQuery[512],
bool:UserLoaded[33],
UserSteamID[33][34],
g_iUser[33][iMassive],
g_iCvar[Cvar];
/*~ Хэндлы ~*/
new
Handle:MYSQL_Tuple,
Handle:MYSQL_Connect;
/*~ Константы ~*/
/*~ Вход/Выход Игрока ~*/
public client_putinserver(iPlayer)
LoadData(iPlayer);
public client_disconnected(iPlayer) {
if(!UserLoaded[iPlayer])
return;
formatex(g_szQuery, charsmax(g_szQuery), "UPDATE `%s` SET `Damage` = '%d', `LimitDamage` = '%d', `Ammo` = '%d', `LimitAmmo` = '%d', `BpAmmo` = '%d', `LimitBpAmmo` = '%d' WHERE `%s`.`SteamID` = '%s';", g_iCvar[g_iSqlTable], g_iUser[iPlayer][PLAYER_DAMAGE], g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT], g_iUser[iPlayer][PLAYER_AMMO], g_iUser[iPlayer][PLAYER_AMMO_LIMIT], g_iUser[iPlayer][PLAYER_BPAMMO], g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT], g_iCvar[g_iSqlTable], UserSteamID[iPlayer]);
SQL_ThreadQuery(MYSQL_Tuple, "SQL_Thread", g_szQuery);
}
/*~ Основное ~*/
public plugin_init() {
InitCore();
InitHook();
InitCmd();
InitCvars();
InitMenu();
}
public InitCore() {
register_plugin(szInfoPlugin[0], szInfoPlugin[1], szInfoPlugin[2]);
register_dictionary("AmxxUpgradeAddonWeapon.txt");
}
public InitHook() {
RegisterHookChain(RG_CBasePlayer_TakeDamage, "RG_CBasePlayer_TakeDamage_Pre", .post = false);
RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "RG_CBasePlayer_HasRestrictItem_Pre", .post = false);
}
public InitCmd() {
register_clcmd("upgrade_weapon_menu", "ClientCommand_WeaponMenu");
}
public InitCvars() {
bind_pcvar_string(create_cvar(
"amxx_upgrade_weapon_sql_host",
"127.0.0.1",
FCVAR_NONE,
"IP/Хост от Базы данных."
), g_iCvar[g_iSqlHost], charsmax(g_iCvar[g_iSqlHost]));
bind_pcvar_string(create_cvar(
"amxx_upgrade_weapon_sql_user",
"root",
FCVAR_NONE,
"Логин (Имя пользователя) от Базы данных."
), g_iCvar[g_iSqlUser], charsmax(g_iCvar[g_iSqlUser]));
bind_pcvar_string(create_cvar(
"amxx_upgrade_weapon_sql_password",
"",
FCVAR_NONE,
"Пароль от Базы данных."
), g_iCvar[g_iSqlPass], charsmax(g_iCvar[g_iSqlPass]));
bind_pcvar_string(create_cvar(
"amxx_upgrade_weapon_sql_dbname",
"sborka",
FCVAR_NONE,
"Название Базы данных."
), g_iCvar[g_iSqlNameDb], charsmax(g_iCvar[g_iSqlNameDb]));
bind_pcvar_string(create_cvar(
"amxx_upgrade_weapon_sql_table",
"AmxxUpgradeAddonWeapon",
FCVAR_NONE,
"Название Базы данных."
), g_iCvar[g_iSqlTable], charsmax(g_iCvar[g_iSqlTable]));
bind_pcvar_num(create_cvar(
"amxx_upgrade_cost_damage",
"5",
FCVAR_NONE,
"Цена за 1 прокачку урона"
), g_iCvar[g_iCostDamage]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_max_count_upgrade_damage",
"5",
FCVAR_NONE,
"Сколько раз можо прокачать урон?"
), g_iCvar[g_iLimitDamage]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_how_give_damage",
"5",
FCVAR_NONE,
"По сколько урона добавлять за каждую прокачку? (5 = 5%, и так далее)"
), g_iCvar[g_iAddDamage]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_cost_ammo",
"5",
FCVAR_NONE,
"Цена за 1 прокачку патрон"
), g_iCvar[g_iCostAmmo]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_max_count_upgrade_ammo",
"5",
FCVAR_NONE,
"Сколько раз можо прокачать патроны?"
), g_iCvar[g_iLimitAmmo]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_how_give_ammo",
"5",
FCVAR_NONE,
"По сколько патрон добавлять за каждую прокачку?"
), g_iCvar[g_iAddAmmo]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_cost_bp_ammo",
"5",
FCVAR_NONE,
"Цена за 1 прокачку запасных патрон"
), g_iCvar[g_iCostBpAmmo]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_max_count_upgrade_bp_ammo",
"5",
FCVAR_NONE,
"Сколько раз можо прокачать запасные патроны?"
), g_iCvar[g_iLimitBpAmmo]);
bind_pcvar_num(create_cvar(
"amxx_upgrade_how_give_bp_ammo",
"5",
FCVAR_NONE,
"По сколько запасных патрон добавлять за каждую прокачку?"
), g_iCvar[g_iAddBpAmmo]);
AutoExecConfig(true, "AmxxUpgradeAddonWeapon");
}
public InitMenu() {
register_menucmd(register_menuid("Show_Weapon_Menu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_Weapon_Menu");
register_menucmd(register_menuid("Show_Damage_Menu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_Damage_Menu");
register_menucmd(register_menuid("Show_Ammo_Menu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_Ammo_Menu");
register_menucmd(register_menuid("Show_BpAmmo_Menu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_BpAmmo_Menu");
}
/*~ Хуки ~*/
public RG_CBasePlayer_TakeDamage_Pre(iVictim, iWeapon, iAttacker, Float:fDamage, iDamageBits) {
if(!is_user_connected(iAttacker))
return;
SetHookChainArg(4, ATYPE_FLOAT, fDamage * 1.0 + (float(g_iUser[iAttacker][PLAYER_DAMAGE])) / 100.0);
#if defined DEBUG
client_print(iAttacker, print_chat, "Damage: %f", 1.0 + (float(g_iUser[iAttacker][PLAYER_DAMAGE])) / 100.0);
#endif
}
public RG_CBasePlayer_HasRestrictItem_Pre(iPlayer, ItemID:iItem, ItemRestType:iType) {
if(iType != ITEM_TYPE_BUYING)
return HC_CONTINUE;
if(iItem == ITEM_SHIELDGUN || iItem == ITEM_SMOKEGRENADE || iItem == ITEM_HEGRENADE || iItem == ITEM_FLASHBANG)
return HC_CONTINUE;
#if defined DEBUG
client_print(iPlayer, print_chat, "debug_buy");
#endif
new WeaponIdType:iWeaponID = rg_get_weapon_info(ItemID:iItem, WI_ID)
rg_set_user_bpammo(iPlayer, iWeaponID, rg_get_user_bpammo(iPlayer, iWeaponID) + 50);
return HC_CONTINUE;
}
/*~ Меню ~*/
public ClientCommand_WeaponMenu(iPlayer) {
if(!is_user_alive(iPlayer)) {
client_print_color(iPlayer, print_team_default, "Только для ^4Живых!");
return;
}
Show_Weapon_Menu(iPlayer);
}
public Show_Weapon_Menu(iPlayer) {
new szMenu[MAX_MENU_LENGTH], iKeys = (1<<7|1<<9);
new iLen = formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "UPGRADE_MENU_CORE_TITLE", iPlayer, upgrade_get_user_points(iPlayer));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_INFO_TIME", upgrade_get_user_hour(iPlayer), upgrade_get_user_min(iPlayer), upgrade_get_user_sec(iPlayer));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_DAMAGE", 1);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_AMMO", 2);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_BPAMMO", 3);
iKeys |= (1<<0|1<<1|1<<2);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_EXIT", iPlayer, 0);
return show_menu(iPlayer, iKeys, szMenu, -1, "Show_Weapon_Menu");
}
public Handle_Weapon_Menu(iPlayer, iKey) {
switch(iKey) {
case 0: {
return Show_Damage_Menu(iPlayer);
}
case 1: {
return Show_Ammo_Menu(iPlayer);
}
case 2: {
return Show_BpAmmo_Menu(iPlayer);
}
case 9: return PLUGIN_HANDLED;
}
return Show_Weapon_Menu(iPlayer);
}
public Show_Damage_Menu(iPlayer) {
new szMenu[MAX_MENU_LENGTH], iKeys = (1<<7|1<<9);
new iLen = formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "UPGRADE_MENU_DAMAGE_TITLE", upgrade_get_user_points(iPlayer), g_iUser[iPlayer][PLAYER_DAMAGE], g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT], g_iCvar[g_iLimitDamage]);
if(g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT] < g_iCvar[g_iLimitDamage])
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_MENU_ADD_DAMAGE", 1);
else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_MENU_ADD_DAMAGE_LIMIT");
iKeys |= (1<<0);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_EXIT", iPlayer, 0);
return show_menu(iPlayer, iKeys, szMenu, -1, "Show_Damage_Menu");
}
public Handle_Damage_Menu(iPlayer, iKey) {
switch(iKey) {
case 0: {
if(g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT] >= g_iCvar[g_iLimitDamage]) {
return PLUGIN_HANDLED;
}
if(upgrade_get_user_points(iPlayer) >= g_iCvar[g_iCostDamage]) {
upgrade_set_user_points(iPlayer, upgrade_get_user_points(iPlayer) - g_iCvar[g_iCostDamage]);
g_iUser[iPlayer][PLAYER_DAMAGE] += g_iCvar[g_iAddDamage];
g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT] ++;
}
}
case 9: return PLUGIN_HANDLED;
}
return Show_Damage_Menu(iPlayer);
}
public Show_Ammo_Menu(iPlayer) {
new szMenu[MAX_MENU_LENGTH], iKeys = (1<<7|1<<9);
new iLen = formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "UPGRADE_MENU_AMMO_TITLE", upgrade_get_user_points(iPlayer), g_iUser[iPlayer][PLAYER_AMMO], g_iUser[iPlayer][PLAYER_AMMO_LIMIT], g_iCvar[g_iLimitAmmo]);
if(g_iUser[iPlayer][PLAYER_AMMO_LIMIT] < g_iCvar[g_iLimitAmmo])
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_MENU_ADD_AMMO", 1);
else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_MENU_ADD_AMMO_LIMIT");
iKeys |= (1<<0);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_EXIT", iPlayer, 0);
return show_menu(iPlayer, iKeys, szMenu, -1, "Show_Ammo_Menu");
}
public Handle_Ammo_Menu(iPlayer, iKey) {
switch(iKey) {
case 0: {
if(g_iUser[iPlayer][PLAYER_AMMO_LIMIT] >= g_iCvar[g_iLimitAmmo]) {
return PLUGIN_HANDLED;
}
if(upgrade_get_user_points(iPlayer) >= g_iCvar[g_iCostAmmo]) {
upgrade_set_user_points(iPlayer, upgrade_get_user_points(iPlayer) - g_iCvar[g_iCostAmmo]);
g_iUser[iPlayer][PLAYER_AMMO] += g_iCvar[g_iAddAmmo];
g_iUser[iPlayer][PLAYER_AMMO_LIMIT] ++;
}
}
case 9: return PLUGIN_HANDLED;
}
return Show_Ammo_Menu(iPlayer);
}
public Show_BpAmmo_Menu(iPlayer) {
new szMenu[MAX_MENU_LENGTH], iKeys = (1<<7|1<<9);
new iLen = formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "UPGRADE_MENU_BPAMMO_TITLE", upgrade_get_user_points(iPlayer), g_iUser[iPlayer][PLAYER_BPAMMO], g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT], g_iCvar[g_iLimitBpAmmo]);
if(g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT] < g_iCvar[g_iLimitBpAmmo])
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_MENU_ADD_BPAMMO", 1);
else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_MENU_ADD_BPAMMO_LIMIT");
iKeys |= (1<<0);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "%L", LANG_PLAYER, "UPGRADE_EXIT", iPlayer, 0);
return show_menu(iPlayer, iKeys, szMenu, -1, "Show_BpAmmo_Menu");
}
public Handle_BpAmmo_Menu(iPlayer, iKey) {
switch(iKey) {
case 0: {
if(g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT] >= g_iCvar[g_iLimitBpAmmo]) {
return PLUGIN_HANDLED;
}
if(upgrade_get_user_points(iPlayer) >= g_iCvar[g_iCostBpAmmo]) {
upgrade_set_user_points(iPlayer, upgrade_get_user_points(iPlayer) - g_iCvar[g_iCostBpAmmo]);
g_iUser[iPlayer][PLAYER_BPAMMO] += g_iCvar[g_iAddBpAmmo];
g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT] ++;
}
}
case 9: return PLUGIN_HANDLED;
}
return Show_BpAmmo_Menu(iPlayer);
}
/*~ Работа С Базой Данных ~*/
public plugin_cfg() {
SQL_LoadDebug();
}
public plugin_end() {
if(MYSQL_Tuple)
SQL_FreeHandle(MYSQL_Tuple);
if(MYSQL_Connect)
SQL_FreeHandle(MYSQL_Connect);
}
public SQL_LoadDebug() {
new szError[512];
new iErrorCode;
MYSQL_Tuple = SQL_MakeDbTuple(g_iCvar[g_iSqlHost], g_iCvar[g_iSqlUser], g_iCvar[g_iSqlPass], g_iCvar[g_iSqlNameDb]);
MYSQL_Connect = SQL_Connect(MYSQL_Tuple, iErrorCode, szError, charsmax(szError));
if(MYSQL_Connect == Empty_Handle)
set_fail_state(szError);
if(!SQL_TableExists(MYSQL_Connect, g_iCvar[g_iSqlTable])) {
new Handle:hQueries;
new szQuery[512];
formatex(szQuery, charsmax(szQuery), "CREATE TABLE IF NOT EXISTS `%s` (SteamID VARCHAR(32) CHARACTER SET cp1250 COLLATE cp1250_general_ci NOT NULL, Damage INT NOT NULL, LimitDamage INT NOT NULL, Ammo INT NOT NULL, LimitAmmo INT NOT NULL, BpAmmo INT NOT NULL, LimitBpAmmo INT NOT NULL, PRIMARY KEY (SteamID))", g_iCvar[g_iSqlTable]);
hQueries = SQL_PrepareQuery(MYSQL_Connect, szQuery);
if(!SQL_Execute(hQueries)) {
SQL_QueryError(hQueries, szError, charsmax(szError));
set_fail_state(szError);
}
SQL_FreeHandle(hQueries);
}
SQL_QueryAndIgnore(MYSQL_Connect, "SET NAMES utf8");
}
public SQL_Query(const iState, Handle: hQuery, szError[], iErrorCode, iParams[], iParamsSize) {
switch(iState) {
case TQUERY_CONNECT_FAILED: log_amx("Load - Could not connect to SQL database. [%d] %s", iErrorCode, szError)
case TQUERY_QUERY_FAILED: log_amx("Load Query failed. [%d] %s", iErrorCode, szError)
}
new iPlayer = iParams[0];
UserLoaded[iPlayer] = true;
if(SQL_NumResults(hQuery) < 1) {
if(equal(UserSteamID[iPlayer], "ID_PENDING"))
return PLUGIN_HANDLED;
formatex(g_szQuery, charsmax(g_szQuery), "INSERT INTO `%s` (`SteamID`, `Damage`, `LimitDamage`, `Ammo`, `LimitAmmo`, `BpAmmo`, `LimitBpAmmo`) VALUES ('%s', '%d', '%d', '%d', '%d', '%d', '%d');", g_iCvar[g_iSqlTable], UserSteamID[iPlayer], g_iUser[iPlayer][PLAYER_DAMAGE], g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT],
g_iUser[iPlayer][PLAYER_AMMO], g_iUser[iPlayer][PLAYER_AMMO_LIMIT], g_iUser[iPlayer][PLAYER_BPAMMO], g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT]);
SQL_ThreadQuery(MYSQL_Tuple, "SQL_Thread", g_szQuery);
return PLUGIN_HANDLED;
}
else {
g_iUser[iPlayer][PLAYER_DAMAGE] = SQL_ReadResult(hQuery, 1);
g_iUser[iPlayer][PLAYER_DAMAGE_LIMIT] = SQL_ReadResult(hQuery, 2);
g_iUser[iPlayer][PLAYER_AMMO] = SQL_ReadResult(hQuery, 3);
g_iUser[iPlayer][PLAYER_AMMO_LIMIT] = SQL_ReadResult(hQuery, 4);
g_iUser[iPlayer][PLAYER_BPAMMO] = SQL_ReadResult(hQuery, 5);
g_iUser[iPlayer][PLAYER_BPAMMO_LIMIT] = SQL_ReadResult(hQuery, 6);
}
return PLUGIN_HANDLED;
}
public LoadData(iPlayer) {
if(!is_user_connected(iPlayer))
return;
new iParams[1];
iParams[0] = iPlayer;
get_user_authid(iPlayer, UserSteamID[iPlayer], charsmax(UserSteamID[]));
formatex(g_szQuery, charsmax(g_szQuery), "SELECT * FROM `%s` WHERE (`%s`.`SteamID` = '%s')", g_iCvar[g_iSqlTable], g_iCvar[g_iSqlTable], UserSteamID[iPlayer]);
SQL_ThreadQuery(MYSQL_Tuple, "SQL_Query", g_szQuery, iParams, sizeof iParams);
}
public SQL_Thread(const iState, Handle: hQuery, szError[], iErrorCode, iParams[], iParamsSize) {
if(iState == 0)
return;
log_amx("SQL Error: %d (%s)", iErrorCode, szError);
}
/*~ Стоки ~*/
stock bool: SQL_TableExists(Handle: hDataBase, const szTable[]) {
new Handle: hQuery = SQL_PrepareQuery(hDataBase, "SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;", szTable);
new szError[MAX_PLAYERS * 16];
if(!SQL_Execute(hQuery)) {
SQL_QueryError(hQuery, szError, charsmax(szError));
set_fail_state(szError);
}
else if( !SQL_NumResults(hQuery)) {
SQL_FreeHandle(hQuery);
return false;
}
SQL_FreeHandle(hQuery);
return true;
}