AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with TravTrie. (https://forums.alliedmods.net/showthread.php?t=278597)

Craxor 02-04-2016 02:52

Help with TravTrie.
 
I'm realy confusing at using celltravtrie library, i have some questions:

- In my code i use TrieKeyExists native to check if exist an Key exist on the g_tBlock var, but i create g_tBlock using TravTrie, is giving me an warning with Tag Mismach, but working compile and working scan if key exist. I should let how is it or exist anoter native who replace that for TravTrie library?

- How to use Iterator to save key in trie when map changed? That's realy confuse for me.

* I realy wanna learn how to use TravTrie, seems realy useful and i wanna use on future, thanks :D

Here's the code:

Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <celltravtrie>

new const PLUGIN[]        = "Pick Up Manager",
        VERSION[]        = "0.2",
          AUTHOR[]        = "Craxor";

new TravTrie:g_tBlock;
new giTypeCvar;

public plugin_init( )
{
        register_plugin
        (
                .plugin_name = PLUGIN,
                .version    = VERSION,
                .author      = AUTHOR
        )

        g_tBlock = TravTrieCreate( );

        register_forward( FM_Touch, "WeaponTouchFwd" );

        register_concmd( "amx_pum_addkey" ,"addkey", ADMIN_BAN, " < Weapon key-name to block > ");
        register_concmd( "amx_pum_remkey" ,"remkey", ADMIN_BAN, " < Weapon key-name to block > ");

        giTypeCvar = register_cvar("pum_type", "1" );
}

public addkey( id, level, cid )
{
        if( !cmd_access( id, level, cid, 2 ) )
                return PLUGIN_HANDLED;

        new Arg1[16];
        read_argv( 1, Arg1, charsmax( Arg1 ) );

        new adder[64];
        formatex( adder, charsmax( adder ), "models/w_%s.mdl", Arg1 );

        TravTrieSetCell( g_tBlock, adder, 1 );
        return PLUGIN_HANDLED;
}

public remkey( id, level, cid )
{
        if( !cmd_access( id, level, cid, 2 ) )
                return PLUGIN_HANDLED;

        new Arg1[16];
        read_argv( 1, Arg1, charsmax( Arg1 ) );

        new adder[64];
        formatex( adder, charsmax( adder ), "models/w_%s.mdl", Arg1 );

        TravTrieDeleteKey( g_tBlock, adder );
        return PLUGIN_HANDLED;
}
 
public WeaponTouchFwd( Entity, Id )
{
        if ( !pev_valid( Entity ) || !pev_valid( Id ) || !is_user_alive( Id ) )
                return FMRES_IGNORED;

        new Model[32];
        pev(Entity, pev_model, Model, charsmax( Model ) );

        new iCvarValue = get_pcvar_num( giTypeCvar );

        if( TrieKeyExists( g_tBlock, Model ) )
        {
                switch( iCvarValue )
                {
                        case 1: engfunc( EngFunc_RemoveEntity, Entity );
                        case 2: return FMRES_SUPERCEDE;
                        default: return FMRES_IGNORED;
                }
        }
        return FMRES_IGNORED;
}


Craxor 05-14-2016 04:36

Re: Help with TravTrie.
 
Bump :D

HamletEagle 05-14-2016 09:31

Re: Help with TravTrie.
 
You should just tag it:
PHP Code:

TrieKeyExistsTrie:g_tBlockModel 

Or if you want it like a stock:
PHP Code:

stock bool:TravTrieKeyExists(TravTrie:HandleTravTrie, const Key[])
{
    return 
TrieKeyExists(Trie:HandleTravTrie,key)


Also, given your code, you don't need TravTries, just use normal tries. You would use TravTrie when you want to iterate over all keys(see an example in Entities Resources Replacement). Also consider to replace FM_Touch with Ham_Touch/register_touch, depending on your needs. FM_Touch is bad because you get all kind of touch between entities, while with ham/engine you can filter by classname inside module and it's better.
Also, doing pev_valid(id) is dumb.

Quote:

- How to use Iterator to save key in trie when map changed? That's realy confuse for me.
What? Trie is deleted on map change, if you want to save stuffs between maps you need files/vault/sql.

Craxor 06-29-2016 15:08

Re: Help with TravTrie.
 
About tries ... Maybe i'm wrong but only TRIES are deleted on map change, that's why i'm using TravTrie for saving tries on map change( i know how to work with normal tries, i've problems only with TravTries ).


But i don't test yet your code ... after test i come back with an answer, anyway, thanks for making time to answer :)

SpeeDeeR 06-29-2016 15:37

Re: Help with TravTrie.
 
Quote:

Originally Posted by Craxor (Post 2431962)
About tries ... Maybe i'm wrong but only TRIES are deleted on map change, that's why i'm using TravTrie for saving tries on map change

You are indeed, wrong.

klippy 06-29-2016 15:37

Re: Help with TravTrie.
 
TravTries get released at mapchange too. TravTries are just a hack, they are just a data structure having both CellArrays and CellTries under the hood.

Craxor 06-30-2016 03:23

Re: Help with TravTrie.
 
ok, thanks guys, i will use vaults for saving data on map change as hamlet(and addonzz) said.


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

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