Raised This Month: $ Target: $400
 0% 

[solved][THX] can someone plz look at code using first time Trie


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 12-03-2010 , 20:46   [solved][THX] can someone plz look at code using first time Trie
Reply With Quote #1

Plz someone check if code is correct...
never used Trie befor so i'm not 100% sure about it

thx inadvance
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "ned"

new Trie:g_tRemoveEntities
new const g_iRemoveEntities[][] = {
    
"func_bomb_target""info_bomb_target""hostage_entity""monster_scientist"
    
"func_hostage_rescue""info_hostage_rescue","info_vip_start""func_vip_safetyzone"
    
"func_escapezone","armoury_entity""game_player_equip""player_weaponstrip","info_deathmatch_start" 
}

new 
Trie:g_tdoorSnd
new const g_doorSnd[][] = {
    
"doors/doorstop1.wav",
    
"doors/doorstop2.wav",
    
"doors/doorstop3.wav"
}

new 
Trie:g_tpainSnd
new const g_painSnd[][] = {
    
"player/pl_pain2.wav""player/pl_pain3.wav""player/pl_pain4.wav""player/pl_pain5.wav",
    
"player/pl_pain6.wav""player/pl_pain7.wav""player/bhit_kevlar-1.wav""player/bhit_flesh-1.wav",
    
"player/bhit_flesh-2.wav""player/bhit_flesh-3.wav"
}

new 
Trie:g_twaterSnd
new const g_waterSnd[][] = {
    
"player/pl_swim1.wav""player/pl_swim2.wav",
    
"player/pl_swim3.wav""player/pl_swim4.wav",
    
"player/waterrun.wav"
}

new 
g_kz_doorsoundg_kz_painsoundg_kz_watersound

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_forward(FM_EmitSound"fw_EmitSound")
    
    
g_kz_doorsound register_cvar("kz_doorsound","1")
    
g_kz_painsound register_cvar("kz_painsound","1")
    
g_kz_watersound register_cvar("kz_watersound","1")
    
    
g_tRemoveEntities TrieCreate()
    for(new 
0sizeof(g_iRemoveEntities); i++)
    {
        
TrieSetCell(g_tRemoveEntitiesg_iRemoveEntities[i], i)
    }
    
    
g_tdoorSnd TrieCreate()
    for(new 
0sizeof(g_doorSnd); i++)
    {
        
TrieSetCell(g_tdoorSndg_doorSnd[i], i)
    }
    
    
g_tpainSnd TrieCreate()
    for(new 
0sizeof(g_painSnd); i++)
    {
        
TrieSetCell(g_tpainSndg_painSnd[i], i)
    }
    
    
g_twaterSnd TrieCreate()
    for(new 
0sizeof(g_waterSnd); i++)
    {
        
TrieSetCell(g_twaterSndg_waterSnd[i], i)
    }
}

public 
plugin_precache() 
{
    
register_forward(FM_Spawn"fw_Spawn"0)
}

public 
fw_EmitSound(iEntchannel, const sound[]) 
{
    if(
get_pcvar_num(g_kz_doorsound))
    {
        if(
TrieKeyExists(g_tdoorSndsound)) 
            return 
FMRES_SUPERCEDE
    
}
    if(
get_pcvar_num(g_kz_painsound))
    {
        if(
TrieKeyExists(g_tpainSndsound)) 
            return 
FMRES_SUPERCEDE
    
}
    if(
get_pcvar_num(g_kz_watersound))
    {
        if(
TrieKeyExists(g_twaterSndsound)) 
            return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED
}

public 
fw_Spawn(iEnt)
{
    if(!
pev_valid(iEnt))
    {
        return 
FMRES_IGNORED
    
}
    new 
ClassName[32]
    
pev(iEntpev_classnameClassName31)
    
    if(
TrieKeyExists(g_tRemoveEntitiesClassName))
    {
        
engfunc(EngFunc_RemoveEntityiEnt)
        return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED

__________________

Last edited by vato loco [GE-S]; 12-04-2010 at 10:18.
vato loco [GE-S] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-03-2010 , 20:54   Re: can someone plz look at code using first time Trie
Reply With Quote #2

If the code compiles and works, it means the code is correct... Something you should check yourself... I don't mean to be rude, but you have a billion examples of the trie usage and once you understand the header of natives, you should have more confidence and test by yourself.

Anyway, I see nothing wrong.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-04-2010 , 03:53   Re: can someone plz look at code using first time Trie
Reply With Quote #3

const arrays can be declared in pplugin_init to memory is freed after it.
Also, for example i would organize emitsound callback like this, make more sense for me :

PHP Code:
public fw_EmitSound(iEntchannel, const sound[]) 
{
    if(
TrieKeyExists(g_tdoorSndsound))
    {
        if(
get_pcvar_num(g_kz_doorsound))
        {
            return 
FMRES_SUPERCEDE
        
}
    }
    else if(
TrieKeyExists(g_tpainSndsound))
    {
        if(
get_pcvar_num(g_kz_painsound))
        {
            return 
FMRES_SUPERCEDE
        
}
    }
    else if(
TrieKeyExists(g_twaterSndsound))
    {
        if(
get_pcvar_num(g_kz_watersound))
        {
            return 
FMRES_SUPERCEDE
        
}
    }
    else if(
TrieKeyExists(g_tdoorSndsound))
    {
        if(
get_pcvar_num(g_kz_doorsound))
        {
            return 
FMRES_SUPERCEDE
        
}
    }
    return 
FMRES_IGNORED

Last, i don't think water sounds are done with EmitSound, you should check it (try to pass in water, you should hear water sounds whatever the cvar value).


Better than cvars, make a config file in which you put something like remove_doorsounds 1, if 1, fill a Trie called g_trieRemoveSounds with doors sounds names, you could then make only 1 check (trie key exists) in callback.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 12-04-2010 , 03:54   Re: can someone plz look at code using first time Trie
Reply With Quote #4

yes it compiles and work i have test it befor i post it...
but like say i was not 100% sure if i done it correct...
you are right i found some of a billion examples in the forum
other way the code wont exsist

but thx anyway Arkshine for confirm me that code is ok
__________________

Last edited by vato loco [GE-S]; 12-04-2010 at 07:07.
vato loco [GE-S] is offline
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 12-04-2010 , 03:56   Re: can someone plz look at code using first time Trie
Reply With Quote #5

ok thx connor
__________________
vato loco [GE-S] is offline
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 12-04-2010 , 04:58   Re: can someone plz look at code using first time Trie
Reply With Quote #6

any reason why you use 2 times doorsound ???
__________________
vato loco [GE-S] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-04-2010 , 05:55   Re: can someone plz look at code using first time Trie
Reply With Quote #7

No.

Any reason you don't use edit button ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-04-2010 , 10:02   Re: can someone plz look at code using first time Trie
Reply With Quote #8

Show the current code. You may have forgotten to create the trie..
__________________
Arkshine is offline
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 12-04-2010 , 10:04   Re: can someone plz look at code using first time Trie
Reply With Quote #9

this is the code that gives error i have test it befor put the code in in my prokreedz and it's not removing entities thx for helping mate
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "ned"

new Trie:g_tRemoveEntities
new const g_iRemoveEntities[][] = {
    
"func_bomb_target""info_bomb_target""hostage_entity""monster_scientist"
    
"func_hostage_rescue""info_hostage_rescue","info_vip_start""func_vip_safetyzone"
    
"func_escapezone","armoury_entity""game_player_equip""player_weaponstrip","info_deathmatch_start" 
}

new 
Trie:g_tdoorSnd
new const g_doorSnd[][] = {
    
"doors/doorstop1.wav",
    
"doors/doorstop2.wav",
    
"doors/doorstop3.wav"
}

new 
Trie:g_tpainSnd
new const g_painSnd[][] = {
    
"player/pl_pain2.wav""player/pl_pain3.wav""player/pl_pain4.wav""player/pl_pain5.wav",
    
"player/pl_pain6.wav""player/pl_pain7.wav""player/bhit_kevlar-1.wav""player/bhit_flesh-1.wav",
    
"player/bhit_flesh-2.wav""player/bhit_flesh-3.wav"
}

new 
Trie:g_twaterSnd
new const g_waterSnd[][] = {
    
"player/pl_swim1.wav""player/pl_swim2.wav",
    
"player/pl_swim3.wav""player/pl_swim4.wav",
    
"player/waterrun.wav"
}

new 
g_kz_doorsoundg_kz_painsoundg_kz_watersound

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_forward(FM_EmitSound"fw_EmitSound")
    
    
g_kz_doorsound register_cvar("kz_doorsound","1")
    
g_kz_painsound register_cvar("kz_painsound","1")
    
g_kz_watersound register_cvar("kz_watersound","1")
    
    
g_tRemoveEntities TrieCreate()
    for(new 
0sizeof(g_iRemoveEntities); i++)
    {
        
TrieSetCell(g_tRemoveEntitiesg_iRemoveEntities[i], i)
    }
    
    
g_tdoorSnd TrieCreate()
    for(new 
0sizeof(g_doorSnd); i++)
    {
        
TrieSetCell(g_tdoorSndg_doorSnd[i], i)
    }
    
    
g_tpainSnd TrieCreate()
    for(new 
0sizeof(g_painSnd); i++)
    {
        
TrieSetCell(g_tpainSndg_painSnd[i], i)
    }
    
    
g_twaterSnd TrieCreate()
    for(new 
0sizeof(g_waterSnd); i++)
    {
        
TrieSetCell(g_twaterSndg_waterSnd[i], i)
    }
}

public 
plugin_precache() 
{
    
register_forward(FM_Spawn"fw_Spawn"0)
}

public 
fw_EmitSound(iEntchannel, const sound[]) 
{
    if(
get_pcvar_num(g_kz_doorsound))
    {
        if(
TrieKeyExists(g_tdoorSndsound)) 
            return 
FMRES_SUPERCEDE
    
}
    if(
get_pcvar_num(g_kz_painsound))
    {
        if(
TrieKeyExists(g_tpainSndsound)) 
            return 
FMRES_SUPERCEDE
    
}
    if(
get_pcvar_num(g_kz_watersound))
    {
        if(
TrieKeyExists(g_twaterSndsound)) 
            return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED
}

public 
fw_Spawn(iEnt)
{
    if(!
pev_valid(iEnt))
    {
        return 
FMRES_IGNORED
    
}
    new 
ClassName[32]
    
pev(iEntpev_classnameClassName31)
    
    if(
TrieKeyExists(g_tRemoveEntitiesClassName))
    {
        
engfunc(EngFunc_RemoveEntityiEnt)
        return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED

__________________

Last edited by vato loco [GE-S]; 12-04-2010 at 15:38.
vato loco [GE-S] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-04-2010 , 10:06   Re: can someone plz look at code using first time Trie
Reply With Quote #10

Because plugin_precache() is called before plugin_init(), and you create the trie in plugin_init(), it can't work. Move all in plugin_precache.
__________________
Arkshine is offline
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 11:24.


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