Raised This Month: $32 Target: $400
 8% 

is user currently touching entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sp@jk
Member
Join Date: May 2010
Location: Serbia
Old 07-29-2011 , 15:49   is user currently touching entity
Reply With Quote #1

so I need some piece of code to check if player or entity is currently touching some other entity

something like this:

is_entity_touching_entity(ent1,ent2)

Sp@jk is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-29-2011 , 15:54   Re: is user currently touching entity
Reply With Quote #2

I don't know another way than to make a huge array and store last touch gametime and then check if it's touched at least 0.1 seconds ago or something....

Why exacly do you need this ? maybe you can do it in a better way.
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-29-2011 , 16:15   Re: is user currently touching entity
Reply With Quote #3

Hook touch for your entities you want to detect touching.
Store last touch get_gametime() in array for players and pev_fuser(1-4) for entities.
Then check if (last touch >= (get_gametime() - 0.1))
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Sp@jk
Member
Join Date: May 2010
Location: Serbia
Old 07-29-2011 , 17:49   Re: is user currently touching entity
Reply With Quote #4

Quote:
Originally Posted by Hunter-Digital View Post
I don't know another way than to make a huge array and store last touch gametime and then check if it's touched at least 0.1 seconds ago or something....

Why exacly do you need this ? maybe you can do it in a better way.
Here's a short description of a plugin that I want to make
Player can press +use and if he's at enemy spawn ( info_player_start and info_player_deathmatch), he can plant flag and get 3 frags

EDIT: I tryed this, but it isn't working
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>

new g_plantedp_mapp_reward 
new g_model[] = "models/flag/srb.mdl" 
new lasttouch[33]

public 
plugin_init()
{
    
register_plugin("Flag Remaked","1.0","Sp@jk"
    
register_event("HLTV","newRound","a","1=0","2=0")
    
register_forward(FM_EmitSound"Sound")
    
register_forward(FM_Touch,"Touch")
    
p_map=register_cvar("amx_flag","0")
    
p_reward=register_cvar("amx_flag_reward","3"
}

public 
plugin_precache()
    
precache_model(g_model)
    
public 
plugin_cfg()
{
    new 
map[32],file[64],cfgdir[128]
    
get_mapname(map,31)
    
get_configsdir(cfgdir,127)
    
formatex(file,63,"%s/flag/%s.cfg",cfgdir,map)
    if(
file_exists(file))
    {
        
server_cmd("exec %s",file)
    }
    if(
get_pcvar_num(p_map)==0)
        
set_fail_state("Flag not allowed on map!")
}

public 
newRound()
{
    
g_planted=0
    
new iEnt engfunc(EngFunc_FindEntityByString,-1"classname","flag")
    while(
iEnt 0
    {
        
engfunc(EngFunc_RemoveEntityiEnt)
        
iEnt engfunc(EngFunc_FindEntityByString,iEnt"classname","flag")
    }
}

public 
Sound(idiChannelszSound[], Float:fVolFloat:fAttniFlagsiPitch )
{
    if(
equal(szSound"common/wpn_denyselect.wav"))
    {
        if(
lasttouch[id] >= (get_gametime() - 0.1) && get_user_weapon(id)==CSW_KNIFE  && g_planted==0)
        {
            new 
Origin[3]
            
get_user_origin(id,Origin)
            new 
flag engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
            
set_pev(flagpev_classname"flag")
            
engfunc(EngFunc_SetModelflagg_model)
            
set_pev(flag,pev_origin,Origin)
            new 
Float:frags
            pev
(idpev_fragsfrags)
            
set_pev(idpev_frags,frags+float(get_pcvar_num(p_reward)))
            
g_planted=1
            
        
}
        return 
FMRES_SUPERCEDE;
    }
    
    return 
FMRES_IGNORED;
}

public 
Touch(ptr,ptd)
{
    if(
pev_valid(ptr))
    {
        static 
classname[32]
        
pev(ptrpev_classnameclassname31)

        if(
equal(classname,"player"))
        {
            static 
classname2[32]
            
pev(ptdpev_classnameclassname231)
            if((
get_user_team(ptr)==1&&equal(classname2,"info_player_start"))||(get_user_team(ptr)==2&&equal(classname2,"info_player_deathmatch")))
                
lasttouch[ptr]==get_gametime()
        }
    }


Last edited by Sp@jk; 07-29-2011 at 18:28.
Sp@jk is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-29-2011 , 18:26   Re: is user currently touching entity
Reply With Quote #5

Then just use find_ent_in_sphere() with a big enough radius when player uses +use.

And AFAIK, point entities (like info_player_*) don't have collision box therefore they don't trigger touch.
__________________
Hunter-Digital is offline
Sp@jk
Member
Join Date: May 2010
Location: Serbia
Old 07-29-2011 , 18:44   Re: is user currently touching entity
Reply With Quote #6

ok, thanks

I will use find_ent_in_sphere to check is there any spawn point near to player
Sp@jk 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 21:27.


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