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

Problem with "register_touch"


Post New Thread Reply   
 
Thread Tools Display Modes
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-16-2018 , 12:20   Re: Problem with "register_touch"
Reply With Quote #11

PHP Code:
new bool:g_bTouchedTree[MAX_PLAYERS 1];

public 
client_putinserver(id)
{
    
g_bTouchedTree[id] = false;
}

public 
fwd_touch(w_box,other){
    
    if(!
g_bTouchedTree[other])
    {
        
client_print(other,print_chat,"Touched")
        
g_bTouchedTree[other] = true;
    }
     


Last edited by Kushfield; 11-16-2018 at 12:22. Reason: whoops got it completely wrong
Kushfield is offline
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-18-2018 , 05:30   Re: Problem with "register_touch"
Reply With Quote #12

Quote:
Originally Posted by Kushfield View Post
PHP Code:
new bool:g_bTouchedTree[MAX_PLAYERS 1];

public 
client_putinserver(id)
{
    
g_bTouchedTree[id] = false;
}

public 
fwd_touch(w_box,other){
    
    if(!
g_bTouchedTree[other])
    {
        
client_print(other,print_chat,"Touched")
        
g_bTouchedTree[other] = true;
    }
     

I made entity area size bigger, but nothing changes, I don't understand what's wrong. And I made that when round starts, g_bTouchedTree[other] will be false, but it doesn't change too...

PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < cstrike >
#include < engine >
#include < hamsandwich >

new const MODEL[ ] = "models/xmas/firtree.mdl";

new 
g_szConfigFile128 ];

new 
bool:g_bTouchedTree[MAX_PLAYERS 1];

public 
plugin_init( ) {
    
register_plugin"Xmas shit""1.0""xPaw & Juice" );
    
    
register_clcmd"tree_spawn",  "CmdSpawnTree",   ADMIN_MAP );
    
register_clcmd"tree_remove""CmdSpawnRemove"ADMIN_MAP );
    
register_clcmd"say /tree""CmdTreeMenu" );
    
    
register_event"CurWeapon""Weather""be" );
    
register_event("HLTV""event_new_round""a""1=0""2=0"
    
    
register_touch("env_tree","*","fwd_touch")
}

public 
client_putinserver(id)
{
    
g_bTouchedTree[id] = false;
}

public 
fwd_touch(w_box,other){
    
    if(!
g_bTouchedTree[other])
    {
        
client_print(other,print_chat,"Touched")
        
g_bTouchedTree[other] = true;
    }
}  

public 
event_new_round(other)
{
    
g_bTouchedTree[other] = false;
}

ShowTreeMenuid )
{
    new 
menu menu_create("Tree Menu""TreeMenu");
    
    
menu_additemmenu"Create Tree""1"ADMIN_MAP );
    
menu_additemmenu"Delete Tree""2"ADMIN_MAP );
    
menu_additemmenu"Save Menu""3"ADMIN_MAP );
    
    
menu_displayidmenu );
}

ShowSaveMenuid )
{
    new 
menu menu_create"Save Tree Menu""SaveMenu" );
    
    
menu_additemmenu"Load Saved Trees""1"ADMIN_MAP );
    
menu_additemmenu"Delete All Trees""2"ADMIN_MAP );
    
menu_additemmenu"Save All Trees^n""3"ADMIN_MAP );
    
menu_additemmenu"Back""4"ADMIN_MAP );
    
    
menu_displayidmenu );
}

public 
TreeMenuidmenuitem )
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return;
    }
    
    new 
_accessinfo[2], callback;
    
menu_item_getinfo(menuitem_accessinfosizeof(info) - 1__callback);
    
menu_destroy(menu);
    
    switch( 
str_to_num(info) )
    {
        case 
1:
        {
            
client_cmdid"tree_spawn" );
            
ShowTreeMenu(id);
        }
        case 
2:
        {
            
client_cmdid"tree_remove" );
            
ShowTreeMenuid );
        }
        case 
3:
        {
            
ShowSaveMenuid );
        }
    }
}

public 
SaveMenuidmenuitem )
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return;
    }
    
    new 
_accessinfo[2], callback;
    
menu_item_getinfo(menuitem_accessinfosizeof(info) - 1__callback);
    
menu_destroy(menu);
    
    switch( 
str_to_num(info) )
    {
        case 
1:
        {
            
DeleteAllTrees( );
            
LoadTrees( );
            
ShowSaveMenuid );
        }
        case 
2:
        {
            
DeleteAllTrees( );
            
ShowSaveMenuid );
        }
        case 
3:
        {    
            
SaveTrees( );
            
ShowSaveMenuid );
        }
        case 
4:
        {
            
ShowTreeMenuid );
        }
    }
}

public 
DeleteAllTrees( ) {
    new 
iEntity = -1;
    while( (
iEntity engfunc(EngFunc_FindEntityByStringiEntity"classname""env_tree")) )
    {
        
engfunc(EngFunc_RemoveEntityiEntity);
    }
}

public 
LoadTrees( ) {
    new 
iFile fopeng_szConfigFile"rt" );
    
    if( !
iFile )
        return;
    
    new 
Float:vOrigin], x16 ], y16 ], z16 ], szDatasizeof) + sizeof) + sizeof) + ];
    
    while( !
feofiFile ) ) {
        
fgetsiFileszDatacharsmaxszData ) );
        
trimszData );
        
        if( !
szData] )
            continue;
        
        
parseszDatax15y15z15 );
        
        
vOrigin] = str_to_float);
        
vOrigin] = str_to_float);
        
vOrigin] = str_to_float);
        
        
CreateTreevOrigin );
    }
    
    
fcloseiFile );
}

public 
Weatherid ) {
    if( 
is_user_aliveid ) ) 
        
client_cmdid"cl_weather 3" );
}

public 
plugin_precache( ) {
    
precache_modelMODEL );
    
create_entity"env_snow" );
}

public 
plugin_cfg( ) {
    new 
szMapName32 ];
    
get_mapnameszMapName31 );
    
strtolowerszMapName );
    
    
formatexg_szConfigFile127"addons/amxmodx/data/trees" );
    
    if( !
dir_existsg_szConfigFile ) ) {
        
mkdirg_szConfigFile );
        
        
formatg_szConfigFile127"%s/%s.txt"g_szConfigFileszMapName );
        
        return;
    }
    
    
formatg_szConfigFile127"%s/%s.txt"g_szConfigFileszMapName );
    
    if( !
file_existsg_szConfigFile ) )
        return;
    
    
LoadTrees( );

}

public 
CmdSpawnTree( const id, const iLevel, const iCid ) {
    if( !
cmd_accessidiLeveliCid) )
        return 
PLUGIN_HANDLED;
    
    new 
Float:vOrigin];
    
entity_get_vectoridEV_VEC_originvOrigin );
    
    
CreateTreevOrigin )
    
    return 
PLUGIN_HANDLED;
}

public 
CmdSpawnRemove( const id, const iLevel, const iCid ) {
    if( !
cmd_accessidiLeveliCid) )
        return 
PLUGIN_HANDLED;
    
    new 
Float:vOrigin], szClassName10 ], iEntity = -1iDeleted;
    
entity_get_vectoridEV_VEC_originvOrigin );
    
    while( ( 
iEntity find_ent_in_sphereiEntityvOrigin100.0 ) ) > ) {
        
entity_get_stringiEntityEV_SZ_classnameszClassName);
        
        if( 
equalszClassName"env_tree" ) ) {
            
remove_entityiEntity );
            
            
iDeleted++;
        }
    }
    
    if( 
iDeleted )
        
SaveTrees( );
    
    
console_printid"[AMXX] Deleted %i trees.%s"iDeletediDeleted == " You need to stand in tree to remove it" "" );
    
    return 
PLUGIN_HANDLED;
}

public 
CmdTreeMenu(id)
{
    if( !
access(idADMIN_MAP) ) return PLUGIN_HANDLED;
    
ShowTreeMenu(id);
    
    return 
PLUGIN_HANDLED;
}

CreateTree( const Float:vOrigin] ) {
    new 
iEntity create_entity"info_target" );
    
    if( !
iEntity )
        return 
0;
    
    
entity_set_stringiEntityEV_SZ_classname"env_tree" );
    
entity_set_intiEntityEV_INT_solidSOLID_TRIGGER );
    
entity_set_intiEntityEV_INT_movetypeMOVETYPE_NONE );
    
    
entity_set_sizeiEntityFloat:{ -50.0, -50.0, -36.0 }, Float:{ 50.050.036.0 } );
    
entity_set_originiEntityvOrigin );
    
entity_set_modeliEntityMODEL );
    
    
drop_to_flooriEntity );
    
    return 
iEntity;
}

SaveTrees( ) {
    if( 
file_existsg_szConfigFile ) )
        
delete_fileg_szConfigFile );
    
    new 
iFile fopeng_szConfigFile"wt" );
    
    if( !
iFile )
        return;
    
    new 
Float:vOrigin], iEntity;
    
    while( ( 
iEntity find_ent_by_classiEntity"env_tree" ) ) > ) {
        
entity_get_vectoriEntityEV_VEC_originvOrigin );
        
        
fprintfiFile"%f %f %f^n"vOrigin], vOrigin], vOrigin] );
    }
    
    
fcloseiFile );

LithuanianJack is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-18-2018 , 06:49   Re: Problem with "register_touch"
Reply With Quote #13

The HLTV event doesn't get called for each player separately, it gets called only once and there is no player ID passed to the function. This means you need to set the whole array to false at once, arrayset can help you with that.

I don't know about the issue with sizing though, it looks fine to me. Not sure how big your tree model is, but 50 units is still not that much, so if you have a big tree, it might seem like changing from 1 to 50 isn't doing a lot.
Kushfield is offline
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-19-2018 , 01:40   Re: Problem with "register_touch"
Reply With Quote #14

Quote:
Originally Posted by Kushfield View Post
The HLTV event doesn't get called for each player separately, it gets called only once and there is no player ID passed to the function. This means you need to set the whole array to false at once, arrayset can help you with that.

I don't know about the issue with sizing though, it looks fine to me. Not sure how big your tree model is, but 50 units is still not that much, so if you have a big tree, it might seem like changing from 1 to 50 isn't doing a lot.
I still trying to get the desired result. How to make that the tree will not be “transparent”? I tried SOLID_BBOX, but nothing changes
LithuanianJack is offline
Reply


Thread Tools
Display Modes

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 14:24.


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