Raised This Month: $7 Target: $400
 1% 

Get item slot for item in TF2Items_OnGiveNamedItem?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-14-2011 , 13:59   Get item slot for item in TF2Items_OnGiveNamedItem?
Reply With Quote #1

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-14-2011 at 14:00.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-16-2011 , 10:44   Re: Get item slot for item in TF2Items_OnGiveNamedItem?
Reply With Quote #2

(I guess I'll just do it by item indexes until then)
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-16-2011 , 20:21   Re: Get item slot for item in TF2Items_OnGiveNamedItem?
Reply With Quote #3

It wont be supported until the API is redesigned.
__________________
asherkin is offline
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 12-17-2011 , 07:35   Re: Get item slot for item in TF2Items_OnGiveNamedItem?
Reply With Quote #4

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.
__________________
einmal mit profis arbeiten. einmal.

Last edited by Thrawn2; 12-17-2011 at 14:53.
Thrawn2 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:29.


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