AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid trie handle provided (0) (https://forums.alliedmods.net/showthread.php?t=281637)

mforce 04-16-2016 08:27

Invalid trie handle provided (0)
 
It happens to all Trie natives. How to solve this problem?

L 04/16/2016 - 14:25:32: Invalid trie handle provided (0)
L 04/16/2016 - 14:25:32: [AMXX] Run time error 10 (plugin "admin_weapon_skins.amxx") (native "TrieKeyExists") - debug not enabled!
L 04/16/2016 - 14:25:32: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).


PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new const PLUGIN[] = "Admin Weapon Skins";
new const 
VERSION[] = "1.0";
new const 
AUTHOR[] = "mforce";


#define ACCESS_FLAG    ADMIN_KICK

new Trie:weaponlist;

const 
m_pPlayer 41
const XO_WEAPON 4

#define get_weapon_owner(%1)        get_pdata_cbase(%1, m_pPlayer, XO_WEAPON)
#define AllocString(%1)             engfunc(EngFunc_AllocString,%1)

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
weaponlist TrieCreate();
}

public 
plugin_precache() {
    new 
sBuffer[256], sFile[64], sData[2][32], pFile;
    
get_localinfo("amxx_configsdir"sFilecharsmax(sFile));
    
format(sFilecharsmax(sFile), "%s/admin_weapon_skins.ini"sFile);
    
pFile fopen(sFile"rt");
    if(
pFile) {     
        while(!
feof(pFile)) {
            
fgets(pFilesBuffercharsmax(sBuffer));
            
trim(sBuffer);
            if(
sBuffer[0] == ';') continue;
            
parse(sBuffersData[0], charsmax(sData[]), sData[1], charsmax(sData[]));

            if((
containi(sData[0], "weapon_") != -1) && (containi(sData[1], ".mdl") != -1) && (!TrieKeyExists(weaponlistsData[0]))) {
                
precache_model(sData[1])
                
RegisterHam(Ham_Item_DeploysData[0], "ItemDeploy_Post"true);
                
TrieSetString(weaponlistsData[0], sData[1])
            }
        }
        
fclose(pFile);
    }
    else 
fprintf(pFile";^"weapon_ak47^" ^"models/adminskins/v_ak47.mdl^"^n");
}

public 
ItemDeploy_Post(Ent) {
    if(
Ent <=0)
        return 
HAM_IGNORED;

    new 
id get_weapon_owner(Ent)
    if((
id 0) && (get_user_flags(id) & ACCESS_FLAG)) {
        new 
szWeapon[32], WeaponPath[32];
        
get_weaponname(EntszWeaponcharsmax(szWeapon));
     
        
TrieGetString(weaponlistszWeaponWeaponPathcharsmax(WeaponPath));
        
set_pev_string(idpev_viewmodel2AllocString(WeaponPath));
    }
    return 
HAM_IGNORED;
}

public 
plugin_end() {
    
TrieDestroy(weaponlist);



Black Rose 04-16-2016 08:32

Re: Invalid trie handle provided (0)
 
plugin_precache() is called before plugin_init().
Move "weaponlist = TrieCreate();" into precache.
Enable debug in the future for better diagnostics.

mforce 04-16-2016 09:24

Re: Invalid trie handle provided (0)
 
Problem solved, thanks :)

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

new const PLUGIN[] = "Admin Weapon Skins";
new const 
VERSION[] = "1.0";
new const 
AUTHOR[] = "mforce";


new 
Trie:weaponlist

#define ACCESS_FLAG    ADMIN_KICK

const m_pPlayer 41
const XO_WEAPON 4

#define get_weapon_owner(%1)        get_pdata_cbase(%1, m_pPlayer, XO_WEAPON)
#define AllocString(%1)             engfunc(EngFunc_AllocString,%1)

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
}

public 
plugin_precache() {
    
weaponlist TrieCreate()
    
    new 
sBuffer[256], sFile[64], sData[2][32], pFile;
 
    
get_localinfo("amxx_configsdir"sFilecharsmax(sFile));
    
format(sFilecharsmax(sFile), "%s/admin_weapon_skins.ini"sFile);
 
    
pFile fopen(sFile"rt");
 
    if(
pFile) {        
        while(!
feof(pFile)) {
            
fgets(pFilesBuffercharsmax(sBuffer));
            
trim(sBuffer);
            if(
sBuffer[0] == ';') continue;
 
            
parse(sBuffersData[0], charsmax(sData[]), sData[1], charsmax(sData[]));

            if((
containi(sData[0], "weapon_") != -1) && (containi(sData[1], ".mdl") != -1) && (!TrieKeyExists(weaponlistsData[0]))) {
                
precache_model(sData[1])
                
RegisterHam(Ham_Item_DeploysData[0], "ItemDeploy_Post"true);
                
TrieSetString(weaponlistsData[0], sData[1])
            }
        }
        
fclose(pFile);
    }
    else 
fprintf(pFile";^"weapon_ak47^" ^"models/adminskins/v_ak47.mdl^"^n");
}

public 
ItemDeploy_Post(Ent) {
    if(
Ent <=0)
        return 
HAM_IGNORED;

    new 
id get_weapon_owner(Ent)
    if((
id 0) && (get_user_flags(id) & ACCESS_FLAG)) {
        new 
szWeapon[32], WeaponPath[32];
        
get_weaponname(cs_get_weapon_id(Ent), szWeaponcharsmax(szWeapon));
        
        
TrieGetString(weaponlistszWeaponWeaponPathcharsmax(WeaponPath));
        
set_pev_string(idpev_viewmodel2AllocString(WeaponPath));
    }
    return 
HAM_IGNORED;
}

public 
plugin_end() {
    
TrieDestroy(weaponlist);




All times are GMT -4. The time now is 18:32.

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