AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   TF2Items (https://forums.alliedmods.net/forumdisplay.php?f=146)
-   -   Get item slot for item in TF2Items_OnGiveNamedItem? (https://forums.alliedmods.net/showthread.php?t=174047)

Powerlord 12-14-2011 13:59

Get item slot for item in TF2Items_OnGiveNamedItem?
 
Is it possible to get the item slot that the item is being equipped in during the TF2Items_OnGiveNamedItem callback?

Basically, I'm trying to block hats from being equipped entirely. However, while all hats/misc items are tf_wearable class, not all tf_wearable class items are hats/misc items; Sniper shields and Demoman feet items are as well.

Basically, I'm trying to block items by their class names, so as to future-proof it so I don't have to update item indexes with every TF2 update.

Powerlord 12-16-2011 10:44

Re: Get item slot for item in TF2Items_OnGiveNamedItem?
 
(I guess I'll just do it by item indexes until then)

asherkin 12-16-2011 20:21

Re: Get item slot for item in TF2Items_OnGiveNamedItem?
 
It wont be supported until the API is redesigned.

Thrawn2 12-17-2011 07:35

Re: Get item slot for item in TF2Items_OnGiveNamedItem?
 
PHP Code:

public Handle:GetWeaponSlotMap() {
    new 
Handle:hKvItems CreateKeyValues("");
    if (!
FileToKeyValues(hKvItemsPATH_ITEMS_GAME)) {
        
SetFailState("Could not parse items_game.txt. Something is seriously wrong!");
        return 
INVALID_HANDLE;
    }

    new 
Handle:hSlotMap CreateTrie();

    new 
Handle:hTriePrefab CreateTrie();
    
KvRewind(hKvItems);
    if(
KvJumpToKey(hKvItems"prefabs")) {
        
// There is a prefabs section

        
KvGotoFirstSubKey(hKvItemsfalse);
        do {
            
decl String:sPFName[64];
            
KvGetSectionName(hKvItemssPFNamesizeof(sPFName));

            new 
String:sItemSlot[16];
            
KvGetString(hKvItems"item_slot"sItemSlotsizeof(sItemSlot));

            
SetTrieString(hTriePrefabsPFNamesItemSlot);
        } while (
KvGotoNextKey(hKvItemsfalse));
    }

    new 
String:sDefaultSlot[16] = "melee";
    
KvRewind(hKvItems);
    
KvJumpToKey(hKvItems"items");
    if(
KvJumpToKey(hKvItems"default")) {
        
KvGetString(hKvItems"item_slot"sDefaultSlotsizeof(sDefaultSlot));
    }


    
KvRewind(hKvItems);
    
KvJumpToKey(hKvItems"items");
    
KvGotoFirstSubKey(hKvItemsfalse);

    new 
String:sIndex[8];
    do {
        
KvGetSectionName(hKvItemssIndexsizeof(sIndex));

        
//Skip item with id 'default'
        
if(StrEqual(sIndex"default"))continue;

        
// Initialize with the default slot
        
new String:sItemSlot[16];
        
strcopy(sItemSlotsizeof(sItemSlot), sDefaultSlot);

        
// Overwrite if a prefab is set
        
new String:sPrefab[64];
        
KvGetString(hKvItems"prefab"sPrefabsizeof(sPrefab));
        
GetTrieString(hTriePrefabsPrefabsItemSlotsizeof(sItemSlot));

        
// Overwrite if set directly
        
KvGetString(hKvItems"item_slot"sItemSlotsizeof(sItemSlot), sItemSlot);

        if(
StrEqual(sItemSlot"primary"))SetTrieValue(hSlotMapsIndex0);
        if(
StrEqual(sItemSlot"secondary"))SetTrieValue(hSlotMapsIndex1);
        if(
StrEqual(sItemSlot"melee"))SetTrieValue(hSlotMapsIndex2);
        if(
StrEqual(sItemSlot"pda"))SetTrieValue(hSlotMapsIndex3);
        if(
StrEqual(sItemSlot"pda2"))SetTrieValue(hSlotMapsIndex4);
    } while (
KvGotoNextKey(hKvItemsfalse));

    
CloseHandle(hTriePrefab);
    
CloseHandle(hKvItems);

    return 
hSlotMap;


This creates a trie with item definition index as key and weapon slot as value, using data from the current items_game.txt. Taken from the tNoUnlocksPls plugin.


All times are GMT -4. The time now is 15:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.