AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect players origins (https://forums.alliedmods.net/showthread.php?t=318524)

raizo11 09-05-2019 07:00

Detect players origins
 
I want to detect if 2 or more players from terrorsits is close to 1 from Ct... Any ideea?

I can't think of other ways

Code:

public client_PreThink()
{
    static X[32], Y[32], XNum, YNum, Float:XOrigin[ 3 ], Float:YOrigin[ 3 ], Float:fDistance

    get_players(X, XNum, "ae", "TERRORIST")
    get_players(Y, YNum, "ae", "CT")

    pev(XNum, pev_origin, XOrigin)
    pev(YNum, pev_origin, YOrigin)

    fDistance = get_distance_f( XOrigin, YOrigin)

    if( fDistance <= 100.0)
    {
        if (XNum == 2 && YNum == 1)
        {
            // something
        }
    }
}


E1_531G 09-05-2019 07:02

Re: Detect players origins
 
XNum and YNum aren't indexes, they hold the amount of players.

Natsheh 09-05-2019 10:40

Re: Detect players origins
 
Don't use client think use a 1.0 loop task or entity think 1.0 sec length for such purpose.

Then use find entity in sphere natives.

Also your "way" doesn't work. As e1531G stated.

raizo11 09-05-2019 18:15

Re: Detect players origins
 
already not working

Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>
 
public plugin_init()
{   
        register_forward(FM_TraceHull,"fm_tracehull",1);
}


public fm_tracehull(Float:start[3],Float:end[3],noMonsters,hull,id,trace)
{
        if(!is_user_connected(id) || !is_user_alive(id))
                return FMRES_IGNORED;
       
        new hit = get_tr2(trace,TR_pHit);

        if(!is_user_alive(hit))
                return FMRES_IGNORED;

        new CsTeams:team = cs_get_user_team(id)

        new Origin[3]
        get_user_origin(id, Origin);
       
        new enemycount=0
       
        new ent = -1
        while((ent = engfunc(EngFunc_FindEntityInSphere, ent, Origin, 150.0)) != 0)
        {
                if(!pev_valid(ent) || !is_user_alive(ent))
                        continue
               
                if (team==cs_get_user_team(ent))
                        continue
               
                enemycount++
               
                if (enemycount>1)
                {
                        set_tr2(trace,TR_flFraction,1.0);
                        client_print(0, print_chat, "[TEST]");
                }
        }

        return FMRES_IGNORED;
}


JocAnis 09-05-2019 18:15

Re: Detect players origins
 
First time seeing client prethink without index...so its serverframe() ? Go with id there and loop

Bugsy 09-05-2019 18:39

Re: Detect players origins
 
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>
 
public plugin_init() 
{     
    
set_task0.1 "FindPlayers" , .flags="b" );
}


public 
FindPlayers()
{
    new 
iPlayers32 ] , iNum iPlayer Float:fOrigin] , iEntity iEnemyCount szName32 ];
    
    
get_playersiPlayers iNum "ae" "CT" );

    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        
peviPlayer pev_origin fOrigin );
        
        
iEntity = -1;
        
iEnemyCount 0;
        
        while( ( 
iEntity engfuncEngFunc_FindEntityInSphere iEntity fOrigin 150.0 ) ) != )
        {
            if ( 
is_user_aliveiEntity ) && ( cs_get_user_teamiEntity ) == CS_TEAM_T ) )
                
iEnemyCount++;
        }
        
        if ( 
iEnemyCount >= )
        {
            
get_user_nameiPlayer szName charsmaxszName ) );
            
client_printprint_chat "%d enemies near %s" iEnemyCount szName );
        }
    }



raizo11 09-05-2019 19:04

Re: Detect players origins
 
Thanks !

edon1337 09-06-2019 06:38

Re: Detect players origins
 
Quote:

Originally Posted by Bugsy (Post 2666020)
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>
 
public plugin_init() 
{     
    
set_task0.1 "FindPlayers" , .flags="b" );
}


public 
FindPlayers()
{
    new 
iPlayers32 ] , iNum iPlayer Float:fOrigin] , iEntity iEnemyCount szName32 ];
    
    
get_playersiPlayers iNum "ae" "CT" );

    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        
peviPlayer pev_origin fOrigin );
        
        
iEntity = -1;
        
iEnemyCount 0;
        
        while( ( 
iEntity engfuncEngFunc_FindEntityInSphere iEntity fOrigin 150.0 ) ) != )
        {
            if ( 
is_user_aliveiEntity ) && ( cs_get_user_teamiEntity ) == CS_TEAM_T ) )
                
iEnemyCount++;
        }
        
        if ( 
iEnemyCount >= )
        {
            
get_user_nameiPlayer szName charsmaxszName ) );
            
client_printprint_chat "%d enemies near %s" iEnemyCount szName );
        }
    }



The variables could be created globally to avoid creating every 10th of a second.

JocAnis 09-06-2019 22:27

Re: Detect players origins
 
- was drunk enough to ask whoops-


All times are GMT -4. The time now is 17:19.

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