AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   block player touch (distance) (https://forums.alliedmods.net/showthread.php?t=158899)

OvidiuS 06-10-2011 18:06

block player touch (distance)
 
is there anyway to block team players touching, like a shield or aura beetwen them?

i already used knockback function (pev(ptd, pev_origin etc...set_pev(ptd, pev_velocity.....)
but that's not it, they can touch, but after touch one of them is knocked back...

chaotix911 06-11-2011 12:34

Re: block player touch (distance)
 
can you post the .sma code? maybe i can help :)

Exolent[jNr] 06-11-2011 16:39

Re: block player touch (distance)
 
Check distance between players in PreThink, and then if players are too close then you can stop both players from moving.

OvidiuS 06-11-2011 22:44

Re: block player touch (distance)
 
i used something like this
PHP Code:

public FwdTouch(ptrptd
{
    if(
pev_valid(ptr) && pev_valid(ptd))
    {
        static 
classname1[32], classname2[32];
        
pev(ptrpev_classnameclassname1sizeof(classname1) - 1);
        
pev(ptdpev_classnameclassname2sizeof(classname2) - 1);
        
        if( 
equali(classname1"player") && equali(classname2"player") )
        {
            new 
CsTeams:ptrTeam cs_get_user_team(ptr)
            new 
CsTeams:ptdTeam cs_get_user_team(ptd)
            if (
ptrTeam == ptdTeam)
            {
                new 
Float:y[2][3]
                
pevptrpev_originy[0] )
                
pevptdpev_originy[1] )
                new 
xg_playerpush get_cvar_num("amx_playerpush"
                for ( 
0;<= 2;x++ ) 
                {
                    
y[1][x] -= y[0][x]
                    
y[1][x] *= g_playerpush
                
}
                
set_pev(ptrpev_velocityy[1])
            }
        }
    }    


Exolent, can i make SOLID entity, like in walkgurad plugin, around player, and block team player touch?
but still i need to allow enemy player walk thru that entity?

Hunter-Digital 06-12-2011 11:21

Re: block player touch (distance)
 
So you want to limit players from getting close to eachother ?

If you like it to be more awesome and feel like something that magnetically/magiacally rejects you, you should set velocity on the player, in the opposite direction.
You'll need to get direction from player to protected player (NOT player's moving direction), and multiply it by the negative direction, clamp it so it doesn't shoot players like bullets nor be too weak.

OvidiuS 06-12-2011 19:50

Re: block player touch (distance)
 
Quote:

Originally Posted by Hunter-Digital (Post 1486422)
So you want to limit players from getting close to eachother ?

If you like it to be more awesome and feel like something that magnetically/magiacally rejects you, you should set velocity on the player, in the opposite direction.
You'll need to get direction from player to protected player (NOT player's moving direction), and multiply it by the negative direction, clamp it so it doesn't shoot players like bullets nor be too weak.

hm, i'm not so great in coding, but i still think, that they will need to touch, if i understand you, you are talking about register touch?
can you give me some example?

Exolent[jNr] 06-12-2011 20:24

Re: block player touch (distance)
 
Try something like this:

Code:
#include < amxmodx > #include < xs > #include < engine > public client_PreThink( iPlayer ) {     if( is_user_alive( iPlayer ) )     {         static iPlayers[ 32 ], iNum;         get_players( iPlayers, iNum, "ae", ( get_user_team( iPlayer ) == 1 ) ? "TERRORIST" : "CT" );                 new Float:vecPlayerOrigin[ 3 ];         entity_get_vector( iPlayer, EV_VEC_origin, vecPlayerOrigin );                 new Float:vecTeammateOrigin[ 3 ];                 static const MINIMUM_DISTANCE = 100.0;         new Float:flDistance;                 for( new i, iTeammate; i < iNum; i++ )         {             iTeammate = iPlayers[ i ];                         entity_get_vector( iTeammate, EV_VEC_origin, vecTeammateOrigin );                         if( ( flDistance = get_distance_f( vecPlayerOrigin, vecTeammateOrigin ) ) < MINIMUM_DISTANCE )             {                 xs_vec_sub( vecTeammateOrigin, vecPlayerOrigin, vecTeammateOrigin );                 xs_vec_normalize( vecTeammateOrigin, vecTeammateOrigin );                 xs_vec_mul_scalar( vecTeammateOrigin, ( MINIMUM_DISTANCE - flDistance ) * 5.0, vecTeammateOrigin );                                 entity_set_vector( iTeammate, EV_VEC_velocity, vecTeammateOrigin );             }         }     } }

Hunter-Digital 06-12-2011 20:40

Re: block player touch (distance)
 
Code:

#include <amxmodx>
#include <engine>
#include <xs>

const Float:AURA_RANGE = 100.0
const Float:AURA_STRENGTH = 10.0

new g_iMaxPlayers

public plugin_init()
    g_iMaxPlayers = get_maxplayers()

public client_putinserver(id)
    set_task(0.1, "player_aura", id)

public client_disconnect(id)
    remove_task(id)

public player_aura(id)
{
    new Float:fPlayerOrigin[3]

    entity_get_vector(id, EV_VEC_origin, fPlayerOrigin)

    for(new i = 1, Float:fDistance, Float:fOrigin[3]; i <= g_iMaxPlayers; i++)
    {
        if(is_user_alive(i))
        {
            entity_get_vector(id, EV_VEC_origin, fOrigin)

            fDistance = get_distance_f(fPlayerOrigin, fOrigin)

            if(fDistance >= AURA_RANGE)
                continue

            /* exolent's math from above post */

            xs_vec_sub(fOrigin, fPlayerOrigin, fOrigin)
            xs_vec_normalize(fOrigin, fOrigin)
            xs_vec_mul_scalar(fOrigin, (fDistance - AURA_RANGE) * -AURA_STRENGTH, fOrigin)

            entity_set_vector(i, EV_VEC_velocity, fOrigin)
        }
    }
}

Untested, math could be wrong xD

OvidiuS 06-13-2011 18:07

Re: block player touch (distance)
 
thank you both for helping, i'll test both plugin :)

OvidiuS 06-14-2011 13:06

Re: block player touch (distance)
 
sorry for double, exolent your plugin spawns player somewhere out of map
i guess that distance is too big, maybe it will work after changing MINIMUM_DISTANCE

Hunter-Digital i didn't have free time to change and try your method, but i will.


All times are GMT -4. The time now is 23:33.

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