Raised This Month: $128 Target: $400
 32% 

Revive a player in a certain radius


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 05-27-2020 , 00:08   Revive a player in a certain radius
Reply With Quote #1

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()


Last edited by wicho; 05-27-2020 at 00:11.
wicho is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 05-27-2020 , 08:01   Re: Revive a player in a certain radius
Reply With Quote #2

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.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 05-27-2020 , 16:47   Re: Revive a player in a certain radius
Reply With Quote #3

Can you give me an example pls
wicho is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-27-2020 , 20:19   Re: Revive a player in a certain radius
Reply With Quote #4

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 );

__________________

Last edited by Bugsy; 06-04-2020 at 21:55.
Bugsy is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 05-27-2020 , 20:43   Re: Revive a player in a certain radius
Reply With Quote #5

Thanks bugsy, what kind of work would the code need?
wicho is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-27-2020 , 21:10   Re: Revive a player in a certain radius
Reply With Quote #6

I made edits, look above
__________________
Bugsy is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 05-27-2020 , 23:36   Re: Revive a player in a certain radius
Reply With Quote #7

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

Last edited by wicho; 05-27-2020 at 23:39.
wicho is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-27-2020 , 23:41   Re: Revive a player in a certain radius
Reply With Quote #8

Only one at a time, starting with the closest. The chances of them being at an exact distance away is slim.
__________________
Bugsy is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 05-28-2020 , 02:03   Re: Revive a player in a certain radius
Reply With Quote #9

Why not drop the bar, and origin (unless there is a marker); then just trigger it off spectating bots like Global Offensive?
__________________
"It's not the actual programming that's interesting. But it's what you can accomplish with the end results that are important." -Dennis Ritchie
"Mathematics, rightly viewed, possesses not only truth, but supreme beauty a beauty cold and austere, like that of sculpture..." -Bertrand Russell
DJEarthQuake is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-03-2020 , 23:48   Re: Revive a player in a certain radius
Reply With Quote #10

At the moment it works fine thanks, I have a question is it possible to remove the corpse model after reviving the partner?
wicho is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:56.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode