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

Problem with "register_touch"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-15-2018 , 09:52   Problem with "register_touch"
Reply With Quote #1

Hello. I want to do that player who touch christmas tree would see a message, but I did something's wrong happened in my code. Can anyone help me?

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

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

new 
g_szConfigFile128 ];

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_touch("env_tree","*","fwd_touch")
}

public 
fwd_touch(w_box,other){
     
    
client_print(other,print_chat,"Touched")
     
}

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_NOT );
    
entity_set_intiEntityEV_INT_movetypeMOVETYPE_NONE );
    
    
entity_set_sizeiEntityFloat:{ -1.0, -1.0, -1.0 }, Float:{ 1.01.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 );


Last edited by LithuanianJack; 11-15-2018 at 09:53.
LithuanianJack is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-15-2018 , 11:19   Re: Problem with "register_touch"
Reply With Quote #2

You can't touch entities with SOLID_NOT state - they can be passed as if they didn't exist, it's just a visual object.
Kushfield is offline
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-15-2018 , 12:29   Re: Problem with "register_touch"
Reply With Quote #3

Quote:
Originally Posted by Kushfield View Post
You can't touch entities with SOLID_NOT state - they can be passed as if they didn't exist, it's just a visual object.
So what I have to do? How I can make not “visual object”?
LithuanianJack is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-15-2018 , 12:41   Re: Problem with "register_touch"
Reply With Quote #4

Try the other possible values for pev_solid until you reach your goal.
http://www.amxmodx.org/api/hlsdk_con...v-solid-values
I believe SOLID_TRIGGER would still keep it passable but also trigger touch when passed, but I'm not sure if that's what you're looking for.
Kushfield is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-15-2018 , 15:45   Re: Problem with "register_touch"
Reply With Quote #5

Its possible to define touch in a non solid entities with constantly checking if there is a player nearby or inside using entity think or simply just change its solid type to trigger solid
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-15-2018 at 15:51.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-16-2018 , 03:07   Re: Problem with "register_touch"
Reply With Quote #6

Quote:
Originally Posted by Kushfield View Post
Try the other possible values for pev_solid until you reach your goal.
http://www.amxmodx.org/api/hlsdk_con...v-solid-values
I believe SOLID_TRIGGER would still keep it passable but also trigger touch when passed, but I'm not sure if that's what you're looking for.
Quote:
Originally Posted by Natsheh View Post
Its possible to define touch in a non solid entities with constantly checking if there is a player nearby or inside using entity think or simply just change its solid type to trigger solid
I tried SOLID_TRIGGER, but text prints only when player inside the tree (in the center) and text spams chat with 10-15 messages. How to fix it? And I tried SOLID_BBOX, but it is still "transparent", can walk through.
LithuanianJack is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-16-2018 , 06:13   Re: Problem with "register_touch"
Reply With Quote #7

Quote:
Originally Posted by LithuanianJack View Post
I tried SOLID_TRIGGER, but text prints only when player inside the tree (in the center) and text spams chat with 10-15 messages. How to fix it? And I tried SOLID_BBOX, but it is still "transparent", can walk through.
Of course it gets printed multiple times, touch is called as long as you are touching the object, it's not a one time thing.
__________________
HamletEagle is offline
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-16-2018 , 06:18   Re: Problem with "register_touch"
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
Of course it gets printed multiple times, touch is called as long as you are touching the object, it's not a one time thing.
I understand this. How to make one time print?
LithuanianJack is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-16-2018 , 10:24   Re: Problem with "register_touch"
Reply With Quote #9

It gets printed only in the center because thats how big you have set the entity size (entity_set_size( iEntity, Float:{ -1.0, -1.0, -1.0 }, Float:{ 1.0, 1.0, 36.0 } ); )
This means the entity size is 1 unit in each direction from the center (except upwards, which is 36)

If you want to print the text just once, you need to create some variable that stores if players have already got the message or not, then check and set that variable's value in the touch callback. Touch gets called on every frame where the object is touched.
Kushfield is offline
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 11-16-2018 , 12:10   Re: Problem with "register_touch"
Reply With Quote #10

Quote:
Originally Posted by Kushfield View Post
It gets printed only in the center because thats how big you have set the entity size (entity_set_size( iEntity, Float:{ -1.0, -1.0, -1.0 }, Float:{ 1.0, 1.0, 36.0 } ); )
This means the entity size is 1 unit in each direction from the center (except upwards, which is 36)

If you want to print the text just once, you need to create some variable that stores if players have already got the message or not, then check and set that variable's value in the touch callback. Touch gets called on every frame where the object is touched.
Thanks for your explanation, but I can’t do this because I’m beginner. Can you write simple code? I need an example to learn
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 04:13.


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