AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Pushing someone away (https://forums.alliedmods.net/showthread.php?t=85609)

Speed! 02-13-2009 12:33

Pushing someone away
 
Ok i got cords of somewhere, i wanna make that when someone is near that cords, to be pushed away
how should i do?
i have some idea, but its not right at all

Exolent[jNr] 02-13-2009 12:40

Re: Pushing someone away
 
Code:
// minimum radius for player to be pushed away #define PUSH_RADIUS 200.0 // maximum speed for player to be pushed away // (maximum speed will be used if player is closest to the origin, otherwise it is proportional to the player's distance) #define PUSH_SPEED 500.0 PushPlayer(client, const Float:center[3]) {     new Float:origin[3];     pev(client, pev_origin, origin);         new Float:dist = get_distance_f(origin, center);     if( dist > PUSH_RADIUS ) return;         new Float:speed = (1.0 - (dist / PUSH_RADIUS)) * PUSH_SPEED;         new Float:velocity[3];     velocity[0] = origin[0] - center[0];     velocity[1] = origin[1] - center[1];     velocity[2] = origin[2] - center[2];         new Float:length = vector_length(velocity);         velocity[0] = velocity[0] / length * speed;     velocity[1] = velocity[1] / length * speed;     velocity[2] = velocity[2] / length * speed;         new Float:current[3];     pev(client, pev_velocity, current);         current[0] += velocity[0];     current[1] += velocity[1];     current[2] += velocity[2];         set_pev(client, pev_velocity, current); }

Speed! 02-13-2009 12:53

Re: Pushing someone away
 
Quote:

Originally Posted by Exolent[jNr] (Post 760971)
Code:
// minimum radius for player to be pushed away #define PUSH_RADIUS 200.0 // maximum speed for player to be pushed away // (maximum speed will be used if player is closest to the origin, otherwise it is proportional to the player's distance) #define PUSH_SPEED 500.0 PushPlayer(client, const Float:center[3]) {     new Float:origin[3];     pev(client, pev_origin, origin);         new Float:dist = get_distance_f(origin, center);     if( dist > PUSH_RADIUS ) return;         new Float:speed = (1.0 - (dist / PUSH_RADIUS)) * PUSH_SPEED;         new Float:velocity[3];     velocity[0] = origin[0] - center[0];     velocity[1] = origin[1] - center[1];     velocity[2] = origin[2] - center[2];         new Float:length = vector_length(velocity);         velocity[0] = velocity[0] / length * speed;     velocity[1] = velocity[1] / length * speed;     velocity[2] = velocity[2] / length * speed;         new Float:current[3];     pev(client, pev_velocity, current);         current[0] += velocity[0];     current[1] += velocity[1];     current[2] += velocity[2];         set_pev(client, pev_velocity, current); }

:D

Speed! 02-13-2009 13:10

Re: Pushing someone away
 
doesent work for me :S
im using this
PHP Code:

public PushPlayer(const Float:center[3])
{    
    static 
client
    
for (client 1client <= g_maxplayersclient++)
    {
        new 
Float:origin[3];
        
pev(clientpev_originorigin);
        
        new 
Float:dist get_distance_f(origincenter);
        if( 
dist PUSH_RADIUS ) return;
        
        new 
Float:speed = (1.0 - (dist PUSH_RADIUS)) * PUSH_SPEED;
        
        new 
Float:velocity[3];
        
velocity[0] = origin[0] - center[0];
        
velocity[1] = origin[1] - center[1];
        
velocity[2] = origin[2] - center[2];
            
        new 
Float:length vector_length(velocity);
        
        
velocity[0] = velocity[0] / length speed;
        
velocity[1] = velocity[1] / length speed;
        
velocity[2] = velocity[2] / length speed;
            
        new 
Float:current[3];
        
pev(clientpev_velocitycurrent);
        
        
current[0] += velocity[0];
        
current[1] += velocity[1];
        
current[2] += velocity[2];
        
        
set_pev(clientpev_velocitycurrent);
    }



AntiBots 02-13-2009 14:06

Re: Pushing someone away
 
1 Attachment(s)
Look You can use this but you need to add the distance.

Exolent[jNr] 02-13-2009 14:35

Re: Pushing someone away
 
Quote:

Originally Posted by Speed! (Post 760983)
doesent work for me :S

That is because you are doing a "return" instead of a "continue" when a player is too far away:
PHP Code:

        if( dist PUSH_RADIUS ) return; 

PHP Code:

public PushPlayer(const Float:center[3])
{    
    static 
client
    
for (client 1client <= g_maxplayersclient++)
    {
        new 
Float:origin[3];
        
pev(clientpev_originorigin);
        
        new 
Float:dist get_distance_f(origincenter);
        if( 
dist PUSH_RADIUS ) continue;
        
        new 
Float:speed = (1.0 - (dist PUSH_RADIUS)) * PUSH_SPEED;
        
        new 
Float:velocity[3];
        
velocity[0] = origin[0] - center[0];
        
velocity[1] = origin[1] - center[1];
        
velocity[2] = origin[2] - center[2];
            
        new 
Float:length vector_length(velocity);
        
        
velocity[0] = velocity[0] / length speed;
        
velocity[1] = velocity[1] / length speed;
        
velocity[2] = velocity[2] / length speed;
            
        new 
Float:current[3];
        
pev(clientpev_velocitycurrent);
        
        
current[0] += velocity[0];
        
current[1] += velocity[1];
        
current[2] += velocity[2];
        
        
set_pev(clientpev_velocitycurrent);
    }



Speed! 02-13-2009 15:09

Re: Pushing someone away
 
Quote:

Originally Posted by Exolent[jNr] (Post 761026)
That is because you are doing a "return" instead of a "continue" when a player is too far away:
PHP Code:

        if( dist PUSH_RADIUS ) return; 

PHP Code:

public PushPlayer(const Float:center[3])
{    
    static 
client
    
for (client 1client <= g_maxplayersclient++)
    {
        new 
Float:origin[3];
        
pev(clientpev_originorigin);
        
        new 
Float:dist get_distance_f(origincenter);
        if( 
dist PUSH_RADIUS ) continue;
        
        new 
Float:speed = (1.0 - (dist PUSH_RADIUS)) * PUSH_SPEED;
        
        new 
Float:velocity[3];
        
velocity[0] = origin[0] - center[0];
        
velocity[1] = origin[1] - center[1];
        
velocity[2] = origin[2] - center[2];
            
        new 
Float:length vector_length(velocity);
        
        
velocity[0] = velocity[0] / length speed;
        
velocity[1] = velocity[1] / length speed;
        
velocity[2] = velocity[2] / length speed;
            
        new 
Float:current[3];
        
pev(clientpev_velocitycurrent);
        
        
current[0] += velocity[0];
        
current[1] += velocity[1];
        
current[2] += velocity[2];
        
        
set_pev(clientpev_velocitycurrent);
    }



oh what a stupid i am :(
allthough i already solved it in a more fashin way (?)
im using engfunc(EngFunc_FindEntityInSphere
+k to all for helping :)

Speed! 02-13-2009 15:37

Re: Pushing someone away
 
I am getting tag mismatch on the set_task
PHP Code:

public PushPlayer(const Float:center[3])
{    
    
// Collisions
    
static victim
    victim 
= -1
    
new Floatconfigsforshield[4]
    
configsforshield[0] = center[0]
    
configsforshield[1] = center[1]
    
configsforshield[2] = center[2]
    while ((
victim engfunc(EngFunc_FindEntityInSpherevictimcenterNADE_EXPLOSION_RADIUS 100)) != 0)
    {
        if (!
g_zombie[victim])
            return
        new 
Float:origin[3];
        
pev(victimpev_originorigin);
        
        new 
Float:speed =  PUSH_SPEED;
        
        new 
Float:velocity[3];
        
velocity[0] = origin[0] - center[0];
        
velocity[1] = origin[1] - center[1];
        
velocity[2] = origin[2] - center[2];
            
        new 
Float:length vector_length(velocity);
        
        
velocity[0] = velocity[0] / length speed;
        
velocity[1] = velocity[1] / length speed;
        
velocity[2] = velocity[2] / length speed;
            
        new 
Float:current[3];
        
pev(victimpev_velocitycurrent);
        
        
current[0] += velocity[0];
        
current[1] += velocity[1];
        
current[2] += velocity[2];
        
        
set_pev(victimpev_velocitycurrent);
    }
    
set_task(0.2,"PushPlayer2"0,  configsforshield,3"a"25); 
}

public  
PushPlayer2(Floatconfigforshield[4])
{    
    
// Collisions
    
static victim
    victim 
= -1
    
static Floatcenter[4]
    
center[0] = configforshield[0]
    
center[1] = configforshield[1]
    
center[2] = configforshield[2]
    while ((
victim engfunc(EngFunc_FindEntityInSpherevictimcenterNADE_EXPLOSION_RADIUS 100)) != 0)
    {
        if (!
g_zombie[victim])
            return
        new 
Float:origin[3];
        
pev(victimpev_originorigin);
        
        new 
Float:speed =  PUSH_SPEED;
        
        new 
Float:velocity[3];
        
velocity[0] = origin[0] - center[0];
        
velocity[1] = origin[1] - center[1];
        
velocity[2] = origin[2] - center[2];
            
        new 
Float:length vector_length(velocity);
        
        
velocity[0] = velocity[0] / length speed;
        
velocity[1] = velocity[1] / length speed;
        
velocity[2] = velocity[2] / length speed;
            
        new 
Float:current[3];
        
pev(victimpev_velocitycurrent);
        
        
current[0] += velocity[0];
        
current[1] += velocity[1];
        
current[2] += velocity[2];
        
        
set_pev(victimpev_velocitycurrent);
    }



Hawk552 02-13-2009 15:38

Re: Pushing someone away
 
Try this:

PHP Code:

set_task(0.2"PushPlayer2"0_:configsforshield3"a"25); 


Speed! 02-13-2009 15:44

Re: Pushing someone away
 
Quote:

Originally Posted by Hawk552 (Post 761054)
Try this:

PHP Code:

set_task(0.2"PushPlayer2"0_:configsforshield3"a"25); 


:D:D:D


All times are GMT -4. The time now is 16:58.

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