Raised This Month: $ Target: $400
 0% 

Get item slot for item in TF2Items_OnGiveNamedItem?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


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 21:15.


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