AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get player touch with different player on death (https://forums.alliedmods.net/showthread.php?t=213355)

FromTheFuture 04-13-2013 18:45

Get player touch with different player on death
 
How to check player touch or not with different player on death?

didoWEE 04-15-2013 11:19

Re: Get player touch with different player on death
 
Hi. I decided to try to make the check.
Here's the code:

PHP Code:

#include <amxmodx>
#include <engine>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("test""1""didoWEE");
    
RegisterHam(Ham_Killed"player""HookKill"1);
}

public 
HookKill(victimkiller)
{
    if(!
is_user_connected(killer)) return HAM_IGNORED;
    if(!
is_user_connected(victim)) return HAM_IGNORED;
    
    new 
Float:VecVictimOrigin[3];
    new 
Float:VecKillerOrigin[3];
    
    
entity_get_vector(victimEV_VEC_originVecVictimOrigin);
    
entity_get_vector(killerEV_VEC_originVecKillerOrigin);
    
    if(
VecVictimOrigin[0] - VecKillerOrigin[0] == 16.0 /* If they touch on X axis */
    
|| VecKillerOrigin[0] - VecVictimOrigin[0] == 16.0 /* If they touch on X axis */
    
|| VecVictimOrigin[1] - VecKillerOrigin[1] == 16.0 /* If they touch on Y axis */
    
|| VecKillerOrigin[1] - VecVictimOrigin[1] == 16.0 /* If they touch on Y axis */
    
|| VecVictimOrigin[2] - VecKillerOrigin[2] == 72.0 /* If they touch on Z axis, no duck*/
    
|| VecKillerOrigin[2] - VecVictimOrigin[2] == 72.0 /* If they touch on Z axis, no duck*/
    
|| VecVictimOrigin[2] - VecKillerOrigin[2] == 54.0 /* If they touch on Z axis, one of them is ducking*/
    
|| VecKillerOrigin[2] - VecVictimOrigin[2] == 54.0 /* If they touch on Z axis, one of them is ducking*/
    
|| VecVictimOrigin[2] - VecKillerOrigin[2] == 36.0 /* If they touch on Z axis, they both are ducking*/
    
|| VecKillerOrigin[2] - VecVictimOrigin[2] == 36.0/* If they touch on Z axis, they both are ducking*/
    
{
        
// do something if they are touching
    
}
    else
    {
        
// do something if they are not touching
    
}
    
    return 
HAM_IGNORED;


BTW, I don't know if it is working ...

FromTheFuture 04-15-2013 11:47

Re: Get player touch with different player on death
 
Quote:

Originally Posted by didoWEE (Post 1933127)
Hi. I decided to try to make the check.
Here's the code:

BTW, I don't know if it is working ...

Thank You, I need it, but I want to check who from my team was touching me and I must do it with cycle, it will be hard to server?
Or better will be if I do this with register_touch forward?

Bos93 04-15-2013 12:03

Re: Get player touch with different player on death
 
didoWEE,Victim cannot be not connected

didoWEE 04-15-2013 12:15

Re: Get player touch with different player on death
 
Quote:

Originally Posted by Bos93 (Post 1933150)
didoWEE,Victim cannot be not connected

Lol ?? And can you tell me why ?

Quote:

Originally Posted by FromTheFuture (Post 1933137)
Or better will be if I do this with register_touch forward?

I think I know how to do it. However first I will try other way. I'll post it leter :)

tonykaram1993 04-15-2013 12:20

Re: Get player touch with different player on death
 
Not connected means not in the server. How can a player (not in the server) and be a victim at the same time?
When you hooked "Ham_Killed" you hooked it to a "player" and not something else, so that check is unnecessary.

hornet 04-15-2013 12:37

Re: Get player touch with different player on death
 
Try this:
Code:
#include <amxmodx> #include <hamsandwich> #include <fakemeta> #define m_iPlayerTeam   114 public plugin_init() {     RegisterHam( Ham_Killed, "player", "CBase_PlayerKilled" ); } public CBase_PlayerKilled( iVictim/*, iAttacker, shouldgib*/ ) {     new Players[ 32 ], i, iEnt = -1;     new Float:flOrigin[ 3 ], szClass[ 32 ];         pev( iVictim, pev_origin, flOrigin );         while( ( iEnt = engfunc( EngFunc_FindEntityInSphere, iEnt, flOrigin, 20.0 ) ) )     {           if( iEnt == iVictim)             continue;                 pev( iEnt, pev_classname, szClass, charsmax( szClass ) );                 if( equal( szClass, "player" ) )         {             if( get_pdata_int( iVictim, m_iPlayerTeam ) == get_pdata_int( iEnt, m_iPlayerTeam ) )             {                 Players[ i ] = iEnt;                 i++;             }         }     }         //Array Players is a list of each team player you were touching when you died }

didoWEE 04-15-2013 12:40

Re: Get player touch with different player on death
 
Quote:

Originally Posted by didoWEE (Post 1933157)
However first I will try other way. I'll post it leter :)

PHP Code:

#include <amxmodx>
#include <engine>
#include <cstrike>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("test""1""didoWEE");
    
RegisterHam(Ham_Killed"player""HookKill"1);
}

public 
HookKill(victimkiller)
{
    if(!
is_user_connected(killer)) return HAM_IGNORED;
    
// if(!is_user_connected(victim)) return HAM_IGNORED;
    // Maybe you are right ...
    
    
new CsTeams:team cs_get_user_team(victim);
    
    new 
Float:VecVictimOrigin[3];
    
entity_get_vector(victimEV_VEC_originVecVictimOrigin);
    
    new 
id = -1;
    
    new 
Float:VecTeammateOrigin[3];
    
    while((
id find_ent_in_sphere(idVecVictimOrigin72.0)) != 0)
    {
        if(
cs_get_user_team(id) != team) continue;
        
        
entity_get_vector(idEV_VEC_originVecTeammateOrigin);
        
        if(
VecVictimOrigin[0] - VecTeammateOrigin[0] == 16.0
        
|| VecTeammateOrigin[0] - VecVictimOrigin[0] == 16.0
        
|| VecVictimOrigin[1] - VecTeammateOrigin[1] == 16.0
        
|| VecTeammateOrigin[1] - VecVictimOrigin[1] == 16.0
        
|| VecVictimOrigin[2] - VecTeammateOrigin[2] == 72.0
        
|| VecTeammateOrigin[2] - VecVictimOrigin[2] == 72.0
        
|| VecVictimOrigin[2] - VecTeammateOrigin[2] == 54.0
        
|| VecTeammateOrigin[2] - VecVictimOrigin[2] == 54.0
        
|| VecVictimOrigin[2] - VecTeammateOrigin[2] == 36.0
        
|| VecTeammateOrigin[2] - VecVictimOrigin[2] == 36.0)
        {
            
// do something if they are touching
        
}
        else
        {
            
// do something if they are not touching
        
}
    }
    return 
HAM_IGNORED;



hornet 04-15-2013 12:54

Re: Get player touch with different player on death
 
Quote:

Originally Posted by didoWEE (Post 1933174)
PHP Code:

#include <amxmodx>
#include <engine>
#include <cstrike>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("test""1""didoWEE");
    
RegisterHam(Ham_Killed"player""HookKill"1);
}

public 
HookKill(victimkiller)
{
    if(!
is_user_connected(killer)) return HAM_IGNORED;
    
// if(!is_user_connected(victim)) return HAM_IGNORED; // Maybe you are right ...
    
    
new CsTeams:team cs_get_user_team(victim);
    
    new 
Float:VecVictimOrigin[3];
    
entity_get_vector(victimEV_VEC_originVecVictimOrigin);
    
    new 
id = -1;
    new 
Float:VecTeammateOrigin[3];
    
    while((
id find_ent_in_sphere(idVecVictimOrigin72.0)) != 0)
    {
        if(
cs_get_user_team(id) != team) continue;
        
        
entity_get_vector(idEV_VEC_originVecTeammateOrigin);
        
        if(
VecVictimOrigin[0] - VecTeammateOrigin[0] == 16.0
        
|| VecTeammateOrigin[0] - VecVictimOrigin[0] == 16.0
        
|| VecVictimOrigin[1] - VecTeammateOrigin[1] == 16.0
        
|| VecTeammateOrigin[1] - VecVictimOrigin[1] == 16.0
        
|| VecVictimOrigin[2] - VecTeammateOrigin[2] == 72.0
        
|| VecTeammateOrigin[2] - VecVictimOrigin[2] == 72.0
        
|| VecVictimOrigin[2] - VecTeammateOrigin[2] == 54.0
        
|| VecTeammateOrigin[2] - VecVictimOrigin[2] == 54.0
        
|| VecVictimOrigin[2] - VecTeammateOrigin[2] == 36.0
        
|| VecTeammateOrigin[2] - VecVictimOrigin[2] == 36.0)
        {
            
// do something if they are touching
        
}
        else
        {
            
// do something if they are not touching
        
}
    }
    
    return 
HAM_IGNORED;



What's to say that your loop won't find an entity that isn't a player?

didoWEE 04-15-2013 12:57

Re: Get player touch with different player on death
 
Quote:

Originally Posted by hornet (Post 1933189)
What's to say that your loop won't find an entity that isn't a player?

Ty :)

PHP Code:

#include <amxmodx>
#include <engine>
#include <cstrike>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("test""1""didoWEE");
    
RegisterHam(Ham_Killed"player""HookKill"1);
}

public 
HookKill(victimkiller)
{
    if(!
is_user_connected(killer)) return HAM_IGNORED;
    
// if(!is_user_connected(victim)) return HAM_IGNORED;
    // Maybe you are right ...
    
    
new CsTeams:team cs_get_user_team(victim);
    
    new 
Float:VecFlVictimOrigin[3];
    
entity_get_vector(victimEV_VEC_originVecFlVictimOrigin);
    
    new 
id = -1;
    
    new 
Float:VecFlTeammateOrigin[3];
    
    while((
id find_ent_in_sphere(idVecFlVictimOrigin72.0)) != 0)
    {
        
// if(!is_user_connected(id)) continue;
        
if(!is_user_alive(id)) continue; // won't give you errors if is_user_alive checks is_user_connected
        
if(cs_get_user_team(id) != team) continue;
        
        
entity_get_vector(idEV_VEC_originVecFlTeammateOrigin);
        
        if(
VecFlVictimOrigin[0] - VecFlTeammateOrigin[0] == 16.0
        
|| VecFlTeammateOrigin[0] - VecFlVictimOrigin[0] == 16.0
        
|| VecFlVictimOrigin[1] - VecFlTeammateOrigin[1] == 16.0
        
|| VecFlTeammateOrigin[1] - VecFlVictimOrigin[1] == 16.0
        
|| VecFlVictimOrigin[2] - VecFlTeammateOrigin[2] == 72.0
        
|| VecFlTeammateOrigin[2] - VecFlVictimOrigin[2] == 72.0
        
|| VecFlVictimOrigin[2] - VecFlTeammateOrigin[2] == 54.0
        
|| VecFlTeammateOrigin[2] - VecFlVictimOrigin[2] == 54.0
        
|| VecFlVictimOrigin[2] - VecFlTeammateOrigin[2] == 36.0
        
|| VecFlTeammateOrigin[2] - VecFlVictimOrigin[2] == 36.0)
        {
            
// do something if they are touching
        
}
        else
        {
            
// do something if they are not touching
        
}
    }
    return 
HAM_IGNORED;




All times are GMT -4. The time now is 10:55.

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