Raised This Month: $ Target: $400
 0% 

is user currently touching entity


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 03:32.


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