Skip to content

Commit

Permalink
Fix 'no custom item' menu handling
Browse files Browse the repository at this point in the history
Closes #3.
  • Loading branch information
nosoop committed Mar 13, 2021
1 parent a667e37 commit cf4fd26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions scripting/cwx.sp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Plugin myinfo = {
name = "[TF2] Custom Weapons X",
author = "nosoop",
description = "Allows server operators to design their own weapons.",
version = "X.0.4",
version = "X.0.5",
url = "https://github.com/nosoop/SM-TFCustomWeaponsX"
}

Expand Down Expand Up @@ -316,6 +316,20 @@ bool SetClientCustomLoadoutItem(int client, const char[] itemuid) {
return false;
}

OnClientCustomLoadoutItemModified(client);
return true;
}

void UnsetClientCustomLoadoutItem(int client, int playerClass, int itemSlot) {
strcopy(g_CurrentLoadout[client][playerClass][itemSlot],
sizeof(g_CurrentLoadout[][][]), "");
g_ItemPersistCookies[playerClass][itemSlot].Set(client, "");
g_CurrentLoadoutEntity[client][playerClass][itemSlot] = INVALID_ENT_REFERENCE;

OnClientCustomLoadoutItemModified(client);
}

void OnClientCustomLoadoutItemModified(int client) {
if (!IsPlayerInRespawnRoom(client)) {
// TODO: notify that the player will get the item when they resup

Expand All @@ -325,7 +339,6 @@ bool SetClientCustomLoadoutItem(int client, const char[] itemuid) {
}
// NOTE: we don't do active reequip on live players, because that's kind of a mess
// return LookupAndEquipItem(client, itemuid);
return true;
}

int LookupAndEquipItem(int client, const char[] itemuid) {
Expand Down
7 changes: 6 additions & 1 deletion scripting/cwx/loadout_radio_menu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ int OnEquipMenuEvent(Menu menu, MenuAction action, int param1, int param2) {
menu.GetItem(position, uid, sizeof(uid));

// TODO: we should be making this a submenu with item description?
SetClientCustomLoadoutItem(client, uid);
if (uid[0]) {
SetClientCustomLoadoutItem(client, uid);
} else {
UnsetClientCustomLoadoutItem(client, g_iPlayerClassInMenu[client],
g_iPlayerSlotInMenu[client]);
}
}

/**
Expand Down

0 comments on commit cf4fd26

Please sign in to comment.