Skip to content

Commit 528289c

Browse files
committed
Support wss in CustomWeapon item
1 parent f84b3b1 commit 528289c

1 file changed

Lines changed: 69 additions & 3 deletions

File tree

amxmodx/scripting/ItemsController/DefaultObjects/ItemType/CustomWeapon.inc

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ native __auw__native__auw_give_weapon(iPlayer, const sWeaponName[], const bool:
2929
native weapons_give_user_ultimate(id, uid=-1, buy_name[]="", replace=0, ammo=-1, bpammo=-1);
3030
#endif
3131

32+
#if !defined _wss_included
33+
native wss_give_weapon(const pPlayer, const szWssClassname[], const GiveType:iGiveType = GT_APPEND);
34+
#endif
35+
3236
enum E_ItemType_CustomWeapon_Controller {
3337
ItemType_CustomWeapon_Controller_None,
3438

3539
ItemType_CustomWeapon_Controller_Cwapi,
3640
ItemType_CustomWeapon_Controller_Auw,
3741
ItemType_CustomWeapon_Controller_Uw,
42+
ItemType_CustomWeapon_Controller_Wss,
3843
}
3944

4045
enum E_ItemType_CustomWeapon_GiveType {
@@ -47,7 +52,7 @@ enum E_ItemType_CustomWeapon_GiveType {
4752
static E_ItemType_CustomWeapon_Controller:UsingController = ItemType_CustomWeapon_Controller_None;
4853

4954
// Почему-то через {true, ...} всё кроме первой ячейки ставится в false.
50-
static bool:AvailableControllers[E_ItemType_CustomWeapon_Controller] = {true, true, true, true};
55+
static bool:AvailableControllers[E_ItemType_CustomWeapon_Controller] = {true, true, true, true, true};
5156

5257
bool:DefaultObjects_ItemType_CustomWeapon_NativeFilter(const name[], const trap) {
5358
if (equal(name, "CWAPI_Weapons_Give")) {
@@ -69,6 +74,11 @@ bool:DefaultObjects_ItemType_CustomWeapon_NativeFilter(const name[], const trap)
6974
return true;
7075
}
7176

77+
if (equal(name, "wss_give_weapon")) {
78+
AvailableControllers[ItemType_CustomWeapon_Controller_Wss] = !!trap;
79+
return true;
80+
}
81+
7282
return false;
7383
}
7484

@@ -99,11 +109,28 @@ DefaultObjects_ItemType_CustomWeapon_Register() {
99109

100110
TrieSetCell(p, "GiveType", _:ItemType_CustomWeapon_ReadGiveTypeFromJsonObject(instanceJson, "GiveType"));
101111

112+
new controllerStr[16];
113+
json_object_get_string(instanceJson, "Controller", controllerStr, charsmax(controllerStr));
114+
if (controllerStr[0]) {
115+
TrieSetCell(p, "Controller", _:ItemType_CustomWeapon_ParseController(controllerStr));
116+
}
117+
102118
return IC_RET_READ_SUCCESS;
103119
}
104120

105121
@ItemType_CustomWeapon_OnGive(const playerIndex, const Trie:p) {
106-
if (UsingController == ItemType_CustomWeapon_Controller_None) {
122+
new E_ItemType_CustomWeapon_Controller:actualController = UsingController;
123+
124+
new E_ItemType_CustomWeapon_Controller:specifiedController = E_ItemType_CustomWeapon_Controller:PCGet_Int(p, "Controller", _:ItemType_CustomWeapon_Controller_None);
125+
if (specifiedController != ItemType_CustomWeapon_Controller_None) {
126+
if (AvailableControllers[specifiedController]) {
127+
actualController = specifiedController;
128+
} else {
129+
log_amx("[WARNING] Specified controller is not available. Using auto-detected.");
130+
}
131+
}
132+
133+
if (actualController == ItemType_CustomWeapon_Controller_None) {
107134
log_amx("[ERROR] Custom weapons controller is not set.");
108135
return IC_RET_GIVE_FAIL;
109136
}
@@ -118,13 +145,15 @@ DefaultObjects_ItemType_CustomWeapon_Register() {
118145
new E_ItemType_CustomWeapon_GiveType:giveType = E_ItemType_CustomWeapon_GiveType:PCGet_Int(p, "GiveType", _:ItemType_CustomWeapon_GiveType_Default);
119146

120147
new bool:res = false;
121-
switch (UsingController) {
148+
switch (actualController) {
122149
case ItemType_CustomWeapon_Controller_Cwapi:
123150
res = ItemType_CustomWeapon_GiveViaCwapi(playerIndex, name, giveType);
124151
case ItemType_CustomWeapon_Controller_Auw:
125152
res = ItemType_CustomWeapon_GiveViaAuw(playerIndex, name);
126153
case ItemType_CustomWeapon_Controller_Uw:
127154
res = ItemType_CustomWeapon_GiveViaUw(playerIndex, name, giveType);
155+
case ItemType_CustomWeapon_Controller_Wss:
156+
res = ItemType_CustomWeapon_GiveViaWss(playerIndex, name, giveType);
128157
default:
129158
log_amx("[WARNING] Unknown custom weapons controller.");
130159
}
@@ -195,6 +224,43 @@ static bool:ItemType_CustomWeapon_GiveViaUw(
195224
return true;
196225
}
197226

227+
static bool:ItemType_CustomWeapon_GiveViaWss(
228+
const playerIndex,
229+
const weaponName[],
230+
const E_ItemType_CustomWeapon_GiveType:giveType = ItemType_CustomWeapon_GiveType_Default
231+
) {
232+
new GiveType:gtype;
233+
switch (giveType) {
234+
case ItemType_CustomWeapon_GiveType_Append:
235+
gtype = GT_APPEND;
236+
case ItemType_CustomWeapon_GiveType_Replace:
237+
gtype = GT_REPLACE;
238+
case ItemType_CustomWeapon_GiveType_DropAndReplace:
239+
gtype = GT_DROP_AND_REPLACE;
240+
default:
241+
gtype = GT_APPEND;
242+
}
243+
244+
return wss_give_weapon(playerIndex, weaponName, gtype) > 0;
245+
}
246+
247+
static E_ItemType_CustomWeapon_Controller:ItemType_CustomWeapon_ParseController(const str[]) {
248+
if (equali(str, "WSS")) {
249+
return ItemType_CustomWeapon_Controller_Wss;
250+
}
251+
if (equali(str, "CWAPI")) {
252+
return ItemType_CustomWeapon_Controller_Cwapi;
253+
}
254+
if (equali(str, "AUW")) {
255+
return ItemType_CustomWeapon_Controller_Auw;
256+
}
257+
if (equali(str, "UW")) {
258+
return ItemType_CustomWeapon_Controller_Uw;
259+
}
260+
261+
return ItemType_CustomWeapon_Controller_None;
262+
}
263+
198264
static E_ItemType_CustomWeapon_GiveType:ItemType_CustomWeapon_ReadGiveTypeFromJsonObject(const JSON:Obj, const Key[], const bool:DotNot = false) {
199265
new Str[32];
200266
json_object_get_string(Obj, Key, Str, charsmax(Str), DotNot);

0 commit comments

Comments
 (0)