опитах се сам да задам сума за оръжие, обаче нещо не ми се получи.
Надявам се накой да знае как става и ако може и/или желае да сподели.
Благодаря предварително!
Ето го и кода:
Код за потвърждение: Избери целия код
#include <amxmodx>
#include <hamsandwich>
#include <reapi>
//Link to original: https://dev-cs.ru/threads/1983/
#define WEAPON_CMD "test" // Command
#define WEAPON_ID WEAPON_M4A1 // ID weapon
#define WEAPON_NAME "weapon_m4a1" // Weapon Name
#define WEAPON_PRICE 1
// #define ACCESS_FLAG ADMIN_LEVEL_H // Flag weapon access. Comment to be available to everyone
#define WEAPON_DAMAGE 1.5 // Damage multiplier. Comment to disable
#define WEAPON_CLIP 35 // Weapon Ammp
#define WEAPON_AMMO 120 // Backpack Ammo
// #define WEAPON_SPEED 300.0 // Running speed. Comment for default quantity
// #define WEAPON_GRAVITY 0.8 // Gravity (1.0 == sv_gravity). Comment for default quantity.
#define MODELS // Include weapon models. Comment to disable
#if defined MODELS
#define MODEL_V "models/digital_gaming/chrom_gold/v_m4a1.mdl" // (v_) View Weapon Model.
#define MODEL_P "models/digital_gaming/chrom_gold/p_m4a1.mdl" // (p_) Player Weapon Model.
//#define MODEL_W "models/custom/w_m4a1.mdl" // (w_) World Weapon Model.
#endif
// #define WEAPON_CAN_TOUCH_ONLY_OWNER // Only the owner can pick up teh weapon. Comment to disable
#define WEAPON_UID 1
#define GetWeponID(%1) WeaponIdType:get_member(%1, m_iId)
#define IsCustomWeapon(%1) bool:(get_entvar(%1, var_impulse) == WEAPON_UID)
#if defined MODELS
public plugin_precache() {
precache_model(MODEL_V);
precache_model(MODEL_P);
#if defined MODEL_W
precache_model(MODEL_W);
#endif
}
#endif
#if defined WEAPON_PRICE
new g_iWeaponID, g_iWeaponCost;
#endif
public plugin_init(){
register_clcmd(WEAPON_CMD, "CmdGive");
#if defined MODELS || defined WEAPON_GRAVITY
RegisterHam(Ham_Item_Deploy, WEAPON_NAME, "Item_Deploy_Post", true);
#endif
#if defined WEAPON_GRAVITY
RegisterHam(Ham_Item_Holster, WEAPON_NAME, "Item_Holster_Post", true);
#endif
#if defined MODEL_W
RegisterHookChain(RG_CWeaponBox_SetModel, "CWeaponBox_SetModel_Pre", false);
#endif
#if defined WEAPON_CLIP
RegisterHam(Ham_Weapon_Reload, WEAPON_NAME, "Weapon_Reload_Pre", false);
#endif
#if defined WEAPON_SPEED
RegisterHam(Ham_CS_Item_GetMaxSpeed, WEAPON_NAME, "CS_Item_GetMaxSpeed_Pre", false);
#endif
#if defined WEAPON_CAN_TOUCH_ONLY_OWNER
RegisterHam(Ham_Touch, "weaponbox", "Weaponbox_Touch_Pre", false);
#endif
#if defined WEAPON_PRICE
RegisterHookChain(RG_BuyWeaponByWeaponID, "fw_BuyWeaponByWeaponID_Pre", false);
#endif
}
public CmdGive(id) {
#if defined ACCESS_FLAG
if (~get_user_flags(id) & ACCESS_FLAG) {
return PLUGIN_HANDLED;
}
#endif
new weapon = rg_give_custom_item(id, WEAPON_NAME, GT_REPLACE, WEAPON_UID);
if (is_nullent(weapon)) {
return PLUGIN_HANDLED;
}
#if defined WEAPON_CLIP
rg_set_iteminfo(weapon, ItemInfo_iMaxClip, WEAPON_CLIP);
rg_set_user_ammo(id, WEAPON_ID, WEAPON_CLIP);
#endif
#if defined WEAPON_AMMO
rg_set_user_bpammo(id, WEAPON_ID, WEAPON_AMMO);
#endif
#if defined WEAPON_DAMAGE
set_member(weapon, m_Weapon_flBaseDamage, Float:get_member(weapon, m_Weapon_flBaseDamage) * WEAPON_DAMAGE);
#if WEAPON_ID == WEAPON_M4A1
set_member(weapon, m_M4A1_flBaseDamageSil, Float:get_member(weapon, m_M4A1_flBaseDamageSil) * WEAPON_DAMAGE);
#elseif WEAPON_ID == WEAPON_USP
set_member(weapon, m_USP_flBaseDamageSil, Float:get_member(weapon, m_USP_flBaseDamageSil) * WEAPON_DAMAGE);
#elseif WEAPON_ID == WEAPON_FAMAS
set_member(weapon, m_Famas_flBaseDamageBurst, Float:get_member(weapon, m_Famas_flBaseDamageBurst) * WEAPON_DAMAGE);
#endif
#endif
return PLUGIN_HANDLED;
}
#if defined MODELS || defined WEAPON_GRAVITY
public Item_Deploy_Post(weapon) {
if (!IsCustomWeapon(weapon)) {
return HAM_IGNORED;
}
new id = get_member(weapon, m_pPlayer);
#if defined MODELS
set_entvar(id, var_viewmodel, MODEL_V);
set_entvar(id, var_weaponmodel, MODEL_P);
#endif
#if defined WEAPON_GRAVITY
set_entvar(id, var_gravity, WEAPON_GRAVITY);
#endif
return HAM_IGNORED;
}
#endif
#if defined WEAPON_GRAVITY
public Item_Holster_Post(weapon) {
if (IsCustomWeapon(weapon)) {
new id = get_member(weapon, m_pPlayer);
set_entvar(id, var_gravity, 1.0);
}
}
#endif
#if defined MODEL_W
public CWeaponBox_SetModel_Pre(const weaponbox, const model[]) {
new weapon = getWeaponBoxWeapon(weaponbox);
if (weapon != NULLENT && IsCustomWeapon(weapon)) {
SetHookChainArg(2, ATYPE_STRING, MODEL_W);
}
}
#endif
#if defined WEAPON_CLIP
public Weapon_Reload_Pre(weapon) {
if (!IsCustomWeapon(weapon) || get_member(weapon, m_Weapon_iClip) < WEAPON_CLIP) {
return HAM_IGNORED;
}
new id = get_member(weapon, m_pPlayer);
#if WEAPON_ID == WEAPON_M4A1
sendWeaponAmimation(id, get_member(weapon, m_Weapon_iWeaponState) & WPNSTATE_M4A1_SILENCED ? 0 : 7);
#elseif WEAPON_ID == WEAPON_USP
sendWeaponAmimation(id, get_member(weapon, m_Weapon_iWeaponState) & WPNSTATE_USP_SILENCED ? 0 : 8);
#else
sendWeaponAmimation(id, 0);
#endif
return HAM_SUPERCEDE;
}
#endif
#if defined WEAPON_SPEED
public CS_Item_GetMaxSpeed_Pre(const weapon) {
if (IsCustomWeapon(weapon)) {
SetHamReturnFloat(WEAPON_SPEED);
return HAM_SUPERCEDE;
}
return HAM_IGNORED;
}
#endif
#if defined WEAPON_PRICE
public fw_BuyWeaponByWeaponID_Pre(const iIndex, const WeaponIdType:iId)
{
if(iId != WeaponIdType:g_iWeaponID && !IsCustomWeapon(iId))
return HC_CONTINUE;
new iPlMoney = get_member(iIndex, m_iAccount);
if(iPlMoney >= g_iWeaponCost)
{
rg_drop_item(iIndex, WEAPON_NAME);
} else {
client_print(iIndex, print_center, "Недостаточно средств для покупки данного предмета!");
SetHookChainReturn(ATYPE_INTEGER, 0);
return HC_SUPERCEDE;
}
return HC_CONTINUE;
}
#endif
#if defined WEAPON_CAN_TOUCH_ONLY_OWNER
public Weaponbox_Touch_Pre(const weaponbox, const id) {
new weapon = getWeaponBoxWeapon(weaponbox);
if (weapon == NULLENT || GetWeponID(weapon) != WEAPON_ID || !IsCustomWeapon(weapon) {
return HAM_IGNORED;
}
return get_entvar(weaponbox, var_owner) == id ? HAM_IGNORED : HAM_SUPERCEDE;
}
#endif
stock getWeaponBoxWeapon(const weaponbox) {
for (new i = 0, weapon; i < MAX_ITEM_TYPES; i++) {
weapon = get_member(weaponbox, m_WeaponBox_rgpPlayerItems, i);
if (!is_nullent(weapon)) {
return weapon;
}
}
return NULLENT;
}
stock sendWeaponAmimation(const id, const animation) {
set_entvar(id, var_weaponanim, animation);
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id);
write_byte(animation);
write_byte(0);
message_end();
}