Raised This Month: $12 Target: $400
 3% 

Help with TravTrie.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-04-2016 , 02:52   Help with TravTrie.
Reply With Quote #1

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

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;
}
__________________
Project: Among Us

Last edited by Craxor; 02-04-2016 at 02:53.
Craxor is offline
Send a message via ICQ to Craxor
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 05-14-2016 , 04:36   Re: Help with TravTrie.
Reply With Quote #2

Bump
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-14-2016 , 09:31   Re: Help with TravTrie.
Reply With Quote #3

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.
__________________

Last edited by HamletEagle; 05-14-2016 at 09:47.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 06-29-2016 , 15:08   Re: Help with TravTrie.
Reply With Quote #4

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
__________________
Project: Among Us

Last edited by Craxor; 06-29-2016 at 15:09.
Craxor is offline
Send a message via ICQ to Craxor
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-29-2016 , 15:37   Re: Help with TravTrie.
Reply With Quote #5

Quote:
Originally Posted by Craxor View Post
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.
SpeeDeeR is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-29-2016 , 15:37   Re: Help with TravTrie.
Reply With Quote #6

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.

Last edited by klippy; 06-29-2016 at 15:38.
klippy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 06-30-2016 , 03:23   Re: Help with TravTrie.
Reply With Quote #7

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

Last edited by Craxor; 06-30-2016 at 03:23.
Craxor is offline
Send a message via ICQ to Craxor
Reply



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


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