AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Revive a player in a certain radius (https://forums.alliedmods.net/showthread.php?t=324779)

wicho 05-26-2020 23:08

Revive a player in a certain radius
 
Hello everyone, I found this plugin that makes a player to revive a teammate by approaching the corpse and holding CTRL + E, a bar will appear and when you complete that bar the player revives where he died, the problem with this is that you have to get close to the exact point where he died and it is very difficult to find the exact point. Someone could make it possible to revive the partner over a certain radio and have a cvar of that (so it would be easier to revive it) please? ... ths in advance

PHP Code:

/* 

    - Credits: 
        # Alucard (Get_origin)
        # Black Rose (Check buttoms)
*/    

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <fun>
#include <cstrike>

#define PLUGIN "CPR Revive"
#define VERSION "1.0"
#define AUTHOR "wiD"

new Float:fOrigin[33][3// Poss of victim
new gCheck[33]
new 
Float:fPoss[33][3// Poss of reviver
new checkid
new g_msgBarTime;
new 
gMessage[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("DeathMsg",                    "event_DeathMsg""a")
    
    
register_forward(FM_CmdStart"OnCmdStart"false)
    
    
g_msgBarTime get_user_msgid"BarTime" );
}

public 
get_origin(id)
{
    new 
Float:fDeath[3]
    
pev(id pev_origin fDeath)
    
    
fOrigin[id][0] = fDeath[0]
    
fOrigin[id][1] = fDeath[1]
    
fOrigin[id][2] = fDeath[2]
    
    return 
PLUGIN_HANDLED
}

public 
event_DeathMsg()
{
    new 
attacker read_data(1
    new 
victim read_data(2
    
    if (!(
is_user_connected(attacker)) || (attacker == victim)) 
        return;
        
    
get_origin(victim)
}

public 
OnCmdStart(iduc_handleseed
{
    
    if (!
is_user_alive(id))
        return;
    
    static 
buttons;
    
buttons get_uc(uc_handleUC_Buttons);
    
    if ((
buttons IN_DUCK) && (buttons IN_USE)) 
    {
        if (!
gCheck[id] && CheckOrigin(id)) 
        {
            
set_task(10.0"RevivePlayer"id)
            
gCheck[id] = true;
            if(!
gMessage[id])
            {
                
startBar(id)
                
gMessage[id] = true
            
}
        }
    }
    else 
    {
        
stopBar(id)
        
remove_task(id);
        
gCheck[id] = false;
        
gMessage[id] = false;
    }
    
    return;
}

public 
CheckOrigin(id)
{
    new 
bool:checking
    
new Float:fPosition[3]
    
pev(id pev_origin fPosition)
    
    
fPoss[id][0] = fPosition[0]
    
fPoss[id][1] = fPosition[1]
    
fPoss[id][2] = fPosition[2]
    
    for(new 
1<= get_maxplayers( ); i++ )
    {
        if((
fOrigin[i][0] == fPoss[id][0]) && (fOrigin[i][1] == fPoss[id][1]) && (fOrigin[i][2] == fPoss[id][2]) && (cs_get_user_team(id) == cs_get_user_team(i)))
        {
            
checking true
            checkid 
i
            
break;
        }
    }
    
    return 
checking;
}
    

public 
RevivePlayer(id)
{
    
ExecuteHamB(Ham_CS_RoundRespawncheckid)
    new 
Float:fSetOrigin[3]
    
fSetOrigin[0] = fPoss[id][0]
    
fSetOrigin[1] = fPoss[id][1]
    
fSetOrigin[2] = fPoss[id][2]
    
set_user_origin(checkidfSetOrigin)
    
client_print(0print_chat"[CPR] User %s respawned target %s"idcheckid)
}

public 
startBar(id)
{
    
message_beginMSG_ONE g_msgBarTime , {0,0,0} , id );
    
write_short10 );
    
message_end();

}
 
public 
stopBar(id)
{
    
message_begin(MSG_ONEg_msgBarTime_id)
    
write_short(0)
    
message_end()



Napoleon_be 05-27-2020 07:01

Re: Revive a player in a certain radius
 
Well, i know that this line is causing you the trouble.

PHP Code:

if((fOrigin[i][0] == fPoss[id][0]) && (fOrigin[i][1] == fPoss[id][1]) && (fOrigin[i][2] == fPoss[id][2]) 

This code is actually telling us, that the reviver needs to be on the EXACT SAME SPOT the victim died, if not, the reviving function will not work.

I would suggest using random_float() for this.

wicho 05-27-2020 15:47

Re: Revive a player in a certain radius
 
Can you give me an example pls

Bugsy 05-27-2020 19:19

Re: Revive a player in a certain radius
 
Not thoroughly tested

Added cvars
Code cleanup
Made a little smarter
  • It finds closest if multiple players are close enough for revive.
  • Stops revive if you move too far away while reviving
CVars:
  • cpr_distance - Maximum distance in units to allow revive
  • cpr_reviveseconds - Seconds to revive someone
PHP Code:

/* 

    - Credits: 
        # Alucard (Get_origin)
        # Black Rose (Check buttoms)
        # bugsy (added functionality, code cleanup, fixes and added cvars)
*/    

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>

new const Version[] = "0.3";

const 
RespawnButtons = ( IN_DUCK IN_USE );

enum CPRData
{
    
Float:CorpseOrigin],
    
ReviverID
}
    
new 
g_rdDataMAX_PLAYERS ][ CPRData ];
new 
g_msgBarTime;
new 
g_pDistance g_gReviveSeconds;

public 
plugin_init() 
{
    
register_plugin"CPR Revive" Version "Alu-rose-sy" );

    
register_event"DeathMsg" "DeathMsg" "a" "1>0" );

    
register_forwardFM_CmdStart "CmdStart" );

    
g_msgBarTime get_user_msgid"BarTime" );
    
    
g_pDistance register_cvar"cpr_distance" "50" );
    
g_gReviveSeconds register_cvar"cpr_reviveseconds" "10" );
}

public 
DeathMsg()
{
    new 
iVictim read_data);
    
peviVictim pev_origin g_rdDataiVictim ][ CorpseOrigin ] );
}

public 
CmdStartid uc_handle seed 
{
    if ( !
is_user_aliveid ) )
        return;
    
    static 
iRespawnID bool:bRespawningMAX_PLAYERS ] , bBarStartedMAX_PLAYERS ] , Float:fOrigin];

    if ( ( 
get_ucuc_handle UC_Buttons ) & RespawnButtons ) == RespawnButtons 
    {
        if ( !
bRespawningid ] )
        {
            if ( ( 
iRespawnID CheckOriginid ) ) ) 
            {
                
g_rdDataiRespawnID ][ ReviverID ] = id;
                
set_pevid pev_iuser2 iRespawnID );
                
set_taskget_pcvar_floatg_gReviveSeconds ) , "RevivePlayer" iRespawnID );
                
bRespawningid ] = true;
                
                if ( !
bBarStartedid ] )
                {
                    
StartBarid );
                    
bBarStartedid ] = true;
                }
            }
        }
        else
        {
            
pevid pev_origin fOrigin );
            
iRespawnID pevid pev_iuser2 );
            
            if ( 
get_distance_f_xfOrigin g_rdDataiRespawnID ][ CorpseOrigin ] ) > get_pcvar_floatg_pDistance ) )
            {
                
remove_taskiRespawnID );
                
StopBarid );
                
bRespawningid ] = false;
                
bBarStartedid ] = false;
                
                if ( !
is_user_aliveiRespawnID  )
                    
client_printid print_chat "* You moved too far away from player to revive" );

                
set_pevid pev_iuser2 );
            }
        }
    }
    else if ( 
bRespawningid ] )
    {
        
StopBarid );
        
remove_taskiRespawnID );
        
bRespawningid ] = false;
        
bBarStartedid ] = false;
    }
    
    return;
}

public 
CheckOriginid )
{
    new 
iPlayers32 ] , iNum Float:fOrigin] , Float:fDistanceThreshold Float:fDistance iNearestPlayer iPlayer Float:fNearestDistance;
    
    
pevid pev_origin fOrigin );
    
get_playersiPlayers iNum "be" cs_get_user_teamid ) == CS_TEAM_T "TERRORIST" "CT" );
    
fDistanceThreshold get_pcvar_floatg_pDistance );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        
fDistance get_distance_f_xfOrigin g_rdDataiPlayer ][ CorpseOrigin ] );
        
        if ( !
fNearestDistance || ( fNearestDistance && ( fDistance fNearestDistance ) ) ) 
        {
            
fNearestDistance fDistance;
            
iNearestPlayer iPlayer;
        }
    }
    
    return ( 
fNearestDistance <= fDistanceThreshold ) ? iNearestPlayer 0;
}
    
public 
RevivePlayerid )
{
    new 
szRespawnName33 ] , szRespawnerName33 ];
    
get_user_nameid szRespawnName charsmaxszRespawnName ) );
    
get_user_nameg_rdDataid ][ ReviverID ] , szRespawnerName charsmaxszRespawnerName ) );
    
    
ExecuteHamBHam_CS_RoundRespawn id );
    
set_pevid pev_origin g_rdDataid ][ CorpseOrigin ] );
    
client_printprint_chat "[CPR] User %s respawned target %s" szRespawnerName szRespawnName );
}

public 
StartBarid )
{
    
message_beginMSG_ONE g_msgBarTime , {0,0,0} , id );
    
write_shortget_pcvar_numg_gReviveSeconds ) );
    
message_end();
}
 
public 
StopBarid )
{
    
message_beginMSG_ONE g_msgBarTime _id );
    
write_short);
    
message_end();
}

//Workaround due to AMX-X compile error using array from enumerator in get_distance_f()
Float:get_distance_f_xFloat:fOrigin1[] , Float:fOrigin2[] )
{
    new 
Float:f1] , Float:f2[3];
    
f1[0] = fOrigin1[0];
    
f1[1] = fOrigin1[1];
    
f1[2] = fOrigin1[2];
    
f2[0] = fOrigin2[0];
    
f2[1] = fOrigin2[1];
    
f2[2] = fOrigin2[2];
    
    return 
get_distance_ff1 f2 );



wicho 05-27-2020 19:43

Re: Revive a player in a certain radius
 
Thanks bugsy, what kind of work would the code need?

Bugsy 05-27-2020 20:10

Re: Revive a player in a certain radius
 
I made edits, look above

wicho 05-27-2020 22:36

Re: Revive a player in a certain radius
 
ok thanks i will test it later but i have a question if there are two or more corpses in the same radio it will revive everyone? oh they would be revive one by one

Bugsy 05-27-2020 22:41

Re: Revive a player in a certain radius
 
Only one at a time, starting with the closest. The chances of them being at an exact distance away is slim.

DJEarthQuake 05-28-2020 01:03

Re: Revive a player in a certain radius
 
Why not drop the bar, and origin (unless there is a marker); then just trigger it off spectating bots like Global Offensive?

wicho 06-03-2020 22:48

Re: Revive a player in a certain radius
 
At the moment it works fine thanks, I have a question is it possible to remove the corpse model after reviving the partner?


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

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