AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [solved][THX] can someone plz look at code using first time Trie (https://forums.alliedmods.net/showthread.php?t=144432)

vato loco [GE-S] 12-03-2010 20:46

[solved][THX] can someone plz look at code using first time Trie
 
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



Arkshine 12-03-2010 20:54

Re: can someone plz look at code using first time Trie
 
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.

ConnorMcLeod 12-04-2010 03:53

Re: can someone plz look at code using first time Trie
 
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.

vato loco [GE-S] 12-04-2010 03:54

Re: can someone plz look at code using first time Trie
 
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 :wink:
other way the code wont exsist :wink:

but thx anyway Arkshine for confirm me that code is ok :up::D

vato loco [GE-S] 12-04-2010 03:56

Re: can someone plz look at code using first time Trie
 
ok thx connor :wink:

vato loco [GE-S] 12-04-2010 04:58

Re: can someone plz look at code using first time Trie
 
any reason why you use 2 times doorsound ???

ConnorMcLeod 12-04-2010 05:55

Re: can someone plz look at code using first time Trie
 
No.

Any reason you don't use edit button ?

vato loco [GE-S] 12-04-2010 07:04

Re: can someone plz look at code using first time Trie
 
No :wink:

vato loco [GE-S] 12-04-2010 10:00

Re: can someone plz look at code using first time Trie
 
hmm getting this error...and entities are not removed

Code:

L 12/04/2010 - 15:56:17: Start of error session.
L 12/04/2010 - 15:56:17: Info (map "bhkz_wicked") (file "addons/amxmodx/logs/error_20101204.log")
L 12/04/2010 - 15:56:17: Invalid trie handle provided (0)
L 12/04/2010 - 15:56:17: [AMXX] Displaying debug trace (plugin "test.amxx")
L 12/04/2010 - 15:56:17: [AMXX] Run time error 10: native error (native "TrieKeyExists")
L 12/04/2010 - 15:56:17: [AMXX]    [0] test.sma::fw_Spawn (line 109)

PHP Code:

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



Arkshine 12-04-2010 10:02

Re: can someone plz look at code using first time Trie
 
Show the current code. You may have forgotten to create the trie..


All times are GMT -4. The time now is 11:24.

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