Skip to content

Commit 5c3441b

Browse files
committed
Add DeployTime param for weapons
1 parent 48658ef commit 5c3441b

5 files changed

Lines changed: 27 additions & 32 deletions

File tree

amxmodx/configs/plugins/CustomWeaponsAPI/Weapons/TestWeapon.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"DamageMult": 5.0,
55
"MaxClip": 42,
66
"MaxAmmo": 84,
7+
"DeployTime": 0.1,
78

89
"Models": {
910
"View": "models/v_p228.mdl",

amxmodx/scripting/Cwapi/Core/CWeapons/Hooks.inc

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ static CWeapons_Hooks__RegReapi() {
3737
RegisterHookChain(RG_CWeaponBox_SetModel, "Hook_WeaponBoxSetModel_Pre", false);
3838
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "Hook_AddPlayerItem_Pre", false);
3939
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy, "Hook_DefaultDeploy_Pre", false);
40+
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy, "Hook_DefaultDeploy_Post", true);
4041
// RegisterHookChain(RG_CBasePlayer_TakeDamage, "Hook_PlayerTakeDamage", false);
4142
// RegisterHookChain(RG_CSGameRules_PlayerKilled, "Hook_PlayerKilled", true);
42-
// RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy, "Hook_DefaultDeploy_Post", true);
4343
// RegisterHookChain(RG_CBasePlayerWeapon_DefaultReload, "Hook_DefaultReload_Pre", false);
4444
// RegisterHookChain(RG_CBasePlayerWeapon_DefaultReload, "Hook_DefaultReload_Post", true);
4545
// RegisterHookChain(RG_CBasePlayerWeapon_DefaultShotgunReload, "Hook_DefaultShotgunReload", false);
@@ -137,11 +137,6 @@ public Hook_AddPlayerItem_Pre(const UserId, const ItemId) {
137137

138138
CWeapons_Call(Weapon, CWeapon_OnAddPlayerItem, [iWeapon, ItemId, UserId]);
139139

140-
// Так и не понял, чё с этим будет... Пусть пока так.
141-
// if (Events_IsRet(CWAPI_STOP_MAIN)) {
142-
// return HC_BREAK;
143-
// }
144-
145140
return HC_CONTINUE;
146141
}
147142

@@ -170,7 +165,7 @@ public Hook_WeaponBoxSetModel_Pre(const iWeaponBox, const szModelName[]) {
170165
return HC_CONTINUE;
171166
}
172167

173-
public Hook_DefaultDeploy_Pre(const ItemId, szViewModel[], szWeaponModel[], iAnim, szAnimExt[], skiplocal) {
168+
public Hook_DefaultDeploy_Pre(const ItemId, szViewModel[], szWeaponModel[]) {
174169
new Weapon[S_CustomWeapon], T_CustomWeapon:iWeapon;
175170
if (!CWeapons_GetByItem(ItemId, Weapon, iWeapon)) {
176171
return HC_CONTINUE;
@@ -188,15 +183,27 @@ public Hook_DefaultDeploy_Pre(const ItemId, szViewModel[], szWeaponModel[], iAni
188183
Dbg_PrintServer("Hook_DefaultDeploy_Pre(%d): Set '%s' as player model.", ItemId, Weapon[CWeapon_Models][CWeapon_Model_Player]);
189184
}
190185

191-
// if (Data[CWAPI_WD_DeployTime] >= 0.0) {
192-
// SetWeaponNextAttack(ItemId, Data[CWAPI_WD_DeployTime]);
193-
// }
186+
return HC_CONTINUE;
187+
}
188+
189+
public Hook_DefaultDeploy_Post(const ItemId) {
190+
new Weapon[S_CustomWeapon], T_CustomWeapon:iWeapon;
191+
if (!CWeapons_GetByItem(ItemId, Weapon, iWeapon)) {
192+
return HC_CONTINUE;
193+
}
194+
195+
Dbg_PrintServer("Hook_DefaultDeploy_Post(%d): For weapon '%s'.", ItemId, Weapon[CWeapon_Name]);
196+
197+
if (Weapon[CWeapon_DeployTime] >= 0.0) {
198+
SetWeaponNextAttack(ItemId, Weapon[CWeapon_DeployTime]);
199+
Dbg_PrintServer("Hook_DefaultDeploy_Post(%d): Set next attack after %.2f seconds.", ItemId, Weapon[CWeapon_DeployTime]);
200+
}
194201

195202
// if (Data[CWAPI_WD_Accuracy] >= 0.0) {
196203
// set_member(ItemId, m_Weapon_flAccuracy, Data[CWAPI_WD_Accuracy]);
197204
// }
198205

199-
// CallWeaponEvent(GetWeapId(ItemId), CWAPI_WE_Deploy, ItemId);
206+
CWeapons_Call(Weapon, CWeapon_OnDeploy, [iWeapon, ItemId]);
200207

201208
return HC_CONTINUE;
202209
}
@@ -279,22 +286,6 @@ public Hook_DefaultDeploy_Pre(const ItemId, szViewModel[], szWeaponModel[], iAni
279286
// return HC_CONTINUE;
280287
// }
281288

282-
// public Hook_DefaultDeploy_Post(const ItemId, szViewModel[], szWeaponModel[], iAnim, szAnimExt[], skiplocal) {
283-
// new WeaponId = GetWeapId(ItemId);
284-
// if (!IsCustomWeapon(WeaponId)) {
285-
// return;
286-
// }
287-
288-
// new Data[CWAPI_WeaponData];
289-
// ArrayGetArray(CustomWeapons, WeaponId, Data);
290-
291-
// if (Data[CWAPI_WD_Accuracy] >= 0.0) {
292-
// set_member(ItemId, m_Weapon_flAccuracy, Data[CWAPI_WD_Accuracy]);
293-
// }
294-
295-
// CallWeaponEvent(WeaponId, CWAPI_WE_Deploy, ItemId);
296-
// }
297-
298289
// public Hook_DefaultReload_Post(const ItemId, iClipSize, iAnim, Float:fDelay) {
299290
// new WeaponId = GetWeapId(ItemId);
300291
// if (!IsCustomWeapon(WeaponId)) {

amxmodx/scripting/Cwapi/Core/CustomWeapons.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ enum _:S_CustomWeapon {
2323
CWeapon_Weight,
2424
CWeapon_MaxClip,
2525
CWeapon_MaxAmmo,
26+
Float:CWeapon_DeployTime,
2627

2728
// Float:CWeapon_MaxWalkSpeed,
28-
// Float:CWeapon_DeployTime,
2929
// Float:CWeapon_ReloadTime,
3030
// Float:CWeapon_PrimaryAttackRate,
3131
// Float:CWeapon_SecondaryAttackRate,
@@ -162,7 +162,7 @@ CWeapons_AddEventListener(
162162

163163
new iListener = -1;
164164
switch (iEvent) {
165-
case CWeapon_OnSpawn:
165+
case CWeapon_OnSpawn, CWeapon_OnDeploy:
166166
// (const T_CustomWeapon:iWeapon, const ItemId)
167167
iListener = CreateOneForward(iPlugin, sCallback, FP_CELL, FP_CELL);
168168
case CWeapon_OnSetWeaponBoxModel:
@@ -266,6 +266,7 @@ T_CustomWeapon:CWeapons_LoadFromCfg(const sFile[], const bool:bAbsolutePath = fa
266266
WeaponData[CWeapon_MaxAmmo] = JsonObject_ReadInt(jWeapon, "MaxAmmo", -1);
267267
WeaponData[CWeapon_Weight] = JsonObject_ReadInt(jWeapon, "Weight", -1);
268268
WeaponData[CWeapon_DamageMult] = JsonObject_ReadFloat(jWeapon, "DamageMult", 1.0);
269+
WeaponData[CWeapon_DeployTime] = JsonObject_ReadFloat(jWeapon, "DeployTime", -1.0);
269270

270271
new Models[S_CWeapon_Models];
271272
JsonObject_ReadAndPrecacheModel(

amxmodx/scripting/Cwapi/Utils.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ stock GetItemFromWeaponBox(const WeaponBox) {
6666
}
6767

6868
// Установка времени до следующего выстрела
69-
stock SetWeaponNextAttack(ItemId, Float:Rate) {
70-
set_member(ItemId, m_Weapon_flNextPrimaryAttack, Rate);
71-
set_member(ItemId, m_Weapon_flNextSecondaryAttack, Rate);
69+
stock SetWeaponNextAttack(const ItemId, const Float:fTime) {
70+
set_member(get_member(ItemId, m_pPlayer), m_flNextAttack, fTime);
71+
set_member(ItemId, m_Weapon_flNextPrimaryAttack, fTime);
72+
set_member(ItemId, m_Weapon_flNextSecondaryAttack, fTime);
7273
}
7374

7475
stock SetWeaponIdleAnim(const UserId, const ItemId) {

amxmodx/scripting/include/cwapi.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum E_CWeapon_Event {
2222
CWeapon_OnSpawn,
2323
CWeapon_OnSetWeaponBoxModel,
2424
CWeapon_OnAddPlayerItem,
25+
CWeapon_OnDeploy,
2526
}
2627

2728
/**

0 commit comments

Comments
 (0)