Skip to content

Commit

Permalink
Use tf2wearables functionality in tf2utils
Browse files Browse the repository at this point in the history
This removes one dependency requirement for server operators.
  • Loading branch information
nosoop committed Apr 11, 2021
1 parent 03a1c6c commit 97ecbdb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 209 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ More information is provided in [the project wiki].

The SourceMod plugins / extensions listed below are required for Custom Weapons X to run:

- [TF2 Wearable Tools](https://github.com/nosoop/sourcemod-tf2wearables)
- [Econ Data](https://github.com/nosoop/SM-TFEconData)
- [TF2Attributes](https://github.com/nosoop/tf2attributes)
- Requires the string attributes pre-release! (1.7.0)
- [TF2 Custom Attributes](https://github.com/nosoop/SM-TFCustAttr)
- [TF2Utils](https://github.com/nosoop/SM-TFUtils)
- Requires minimum version 0.11.0.
- [DHooks2](https://github.com/peace-maker/DHooks2)

Additional software recommendations that aren't completely necessary:
Expand Down
2 changes: 1 addition & 1 deletion scripting/cwx.sp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#pragma newdecls required

#include <tf2wearables>
#include <tf_econ_data>
#include <stocksoup/convars>
#include <stocksoup/math>
Expand All @@ -31,6 +30,7 @@ public Plugin myinfo = {
author = "nosoop",
description = "Allows server operators to design their own weapons.",
version = "X.0.6" ... VERSION_SUFFIX,
version = "X.0.7" ... VERSION_SUFFIX,
url = "https://github.com/nosoop/SM-TFCustomWeaponsX"
}

Expand Down
6 changes: 3 additions & 3 deletions scripting/cwx/item_entity.sp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ stock int TF2_CreateItem(int defindex, const char[] itemClass) {
* Removes the given item based on its loadout slot.
*/
bool TF2_RemoveItemByLoadoutSlot(int client, int loadoutSlot) {
int item = TF2_GetPlayerLoadoutSlot(client, loadoutSlot);
int item = TF2Util_GetPlayerLoadoutEntity(client, loadoutSlot);
if (!IsValidEntity(item)) {
return false;
}

if (TF2_IsWearable(item)) {
if (TF2Util_IsEntityWearable(item)) {
TF2_RemoveWearable(client, item);
} else {
TF2_RemoveWeaponSlot(client, TF2Util_GetWeaponSlot(item));
Expand All @@ -51,7 +51,7 @@ void TF2_EquipPlayerEconItem(int client, int item) {
GetEntityClassname(item, weaponClass, sizeof(weaponClass));

if (StrContains(weaponClass, "tf_wearable", false) == 0) {
TF2_EquipPlayerWearable(client, item);
TF2Util_EquipPlayerWearable(client, item);
} else {
EquipPlayerWeapon(client, item);
TF2_ResetWeaponAmmo(item);
Expand Down
34 changes: 34 additions & 0 deletions third_party/vendored/tf2utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ native void TF2Util_GetPlayerShootPosition(int client, float result[3]);
*/
native bool TF2Util_IsEntityWeapon(int entity);

/**
* Returns whether or not the given entity is a wearable.
*
* @error Entity is not valid.
*/
native bool TF2Util_IsEntityWearable(int entity);

/**
* Returns the slot for the given weapon entity.
*
Expand Down Expand Up @@ -93,6 +100,26 @@ native int TF2Util_GetPlayerWearable(int client, int index);
*/
native int TF2Util_GetPlayerWearableCount(int client);

/**
* If `includeWearableWeapons` is true, weapon slots (primary, secondary, melee, utility,
* building, pda, pda2) are also checked for wearable items. Otherwise, non-wearables are
* ignored.
*
* Note that this validates that the player is using a class that can equip the given item; any
* items not applicable to the class are ignored.
*
* @return Entity on the given client occupying the given loadout slot.
*/
native int TF2Util_GetPlayerLoadoutEntity(int client, int loadoutSlot,
bool includeWearableWeapons = true);

/**
* Equips the given wearable entity onto the given client.
*
* @error Client is invalid or entity is not a wearable.
*/
native void TF2Util_EquipPlayerWearable(int client, int wearable);

/**
* Forces an update to the given player's speed.
*
Expand All @@ -119,6 +146,13 @@ native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false);
native bool TF2Util_IsPointInRespawnRoom(const float[3] position,
int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false);

// compile-time compatibility shim for tf2wearables natives
#if defined USE_TF2WEARABLE_FUNCTION_SHIMS
#define TF2_GetPlayerLoadoutSlot TF2Util_GetPlayerLoadoutEntity
#define TF2_EquipPlayerWearable TF2Util_EquipPlayerWearable
#define TF2_IsWearable TF2Util_IsEntityWearable
#endif

public SharedPlugin __pl_tf2utils = {
name = "nosoop_tf2utils",
file = "tf2utils.smx",
Expand Down
204 changes: 0 additions & 204 deletions third_party/vendored/tf2wearables.inc

This file was deleted.

0 comments on commit 97ecbdb

Please sign in to comment.