AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   is user currently touching entity (https://forums.alliedmods.net/showthread.php?t=163375)

Sp@jk 07-29-2011 15:49

is user currently touching entity
 
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)

:)

Hunter-Digital 07-29-2011 15:54

Re: is user currently touching entity
 
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.

Exolent[jNr] 07-29-2011 16:15

Re: is user currently touching entity
 
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))

Sp@jk 07-29-2011 17:49

Re: is user currently touching entity
 
Quote:

Originally Posted by Hunter-Digital (Post 1521231)
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()
        }
    }



Hunter-Digital 07-29-2011 18:26

Re: is user currently touching entity
 
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.

Sp@jk 07-29-2011 18:44

Re: is user currently touching entity
 
ok, thanks :)

I will use find_ent_in_sphere to check is there any spawn point near to player :)


All times are GMT -4. The time now is 03:32.

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