Raised This Month: $51 Target: $400
 12% 

[L4D & L4D2] Emergency Treatment With First Aid Kit And CPR


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Captain Stubin
Member
Join Date: Jun 2017
Old 12-18-2018 , 05:33   [L4D & L4D2] Emergency Treatment With First Aid Kit And CPR
Reply With Quote #1

Hello tell me what you need to fix in the plugin to when you resurrect the player's character pharmacy or artificial respiration appeared the same bot ( player ) and did not appear a new bot ( player ).

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0.0"
#define TICKS 3


new bool:CanRevive[MAXPLAYERS+1];
new 
GhostLight[MAXPLAYERS+1];
new 
Float:DeathTime[MAXPLAYERS+1];
new 
Float:DeathPos[MAXPLAYERS+1][3];


new 
DeadMan[MAXPLAYERS+1];

new 
RevivePlayer[MAXPLAYERS+1] ;
new 
Float:ReviveTime[MAXPLAYERS+1] ;


new 
Handle:timer_handle=INVALID_HANDLE;
 
new 
Handle:l4d_revive_duration INVALID_HANDLE;
new 
Handle:l4d_revive_maxtime INVALID_HANDLE;
new 
Handle:l4d_CPR_maxtime INVALID_HANDLE;
new 
Handle:l4d_CPR_duration INVALID_HANDLE;
new 
Handle:l4d_revive_health INVALID_HANDLE;

new 
Handle:hRoundRespawn INVALID_HANDLE;
new 
Handle:hGameConf INVALID_HANDLE;

new 
revive_duration;
new 
revive_maxtime;
new 
ar_duration;
new 
ar_maxtime;
new 
maxtime;
 
 new 
GameMode;

public 
Plugin:myinfo 
{
    
name "Emergency Treatment With First Aid Kit Revive And CPR",
    
author "Pan Xiaohai & AtomicStryker & Ivailosp & OtterNas3",
    
description "Revive with first aid kit and CPR",
    
version PLUGIN_VERSION,    
}
public 
OnPluginStart()
{
    new 
bool:error=false;
    
hGameConf LoadGameConfigFile("l4drevive");
    if (
hGameConf != INVALID_HANDLE)
    {
        
StartPrepSDKCall(SDKCall_Player);
        
PrepSDKCall_SetFromConf(hGameConfSDKConf_Signature"RoundRespawn");
        
hRoundRespawn EndPrepSDKCall();
        if (
hRoundRespawn == INVALID_HANDLE
        {
            
error=true;
            
SetFailState("L4D_SM_Respawn: RoundRespawn Signature broken");
        }
      }
    else
    {
        
SetFailState("could not find gamedata file at addons/sourcemod/gamedata/l4drevive.txt , you FAILED AT INSTALLING");
        
error=true;
    }
    
    

    
CreateConVar("l4d_revive_version"PLUGIN_VERSION" "FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
 
    
l4d_revive_duration CreateConVar("l4d_revive_duration""10""How long does revive take?"FCVAR_PLUGIN);
    
l4d_revive_health CreateConVar("l4d_revive_health""50""Revive health"FCVAR_PLUGIN);    
    
l4d_revive_maxtime CreateConVar("l4d_revive_maxtime""300""Dead bodys can be revived up to x seconds, 0:disable revive"FCVAR_PLUGIN);
    
l4d_CPR_maxtime CreateConVar("l4d_CPR_maxtime""15""Dead bodys can be CPR within x seconds, 0:disable artificial respiration"FCVAR_PLUGIN);
    
l4d_CPR_duration CreateConVar("l4d_CPR_duration""6""How long does CPR take"FCVAR_PLUGIN);
    
    
AutoExecConfig(true"l4d_revive&cpr_v10");
 
    
Setting();
 
     
    
HookConVarChange(l4d_revive_durationConVarChange);
    
HookConVarChange(l4d_revive_maxtimeConVarChange);
    
HookConVarChange(l4d_CPR_maxtimeConVarChange);
    
HookConVarChange(l4d_CPR_durationConVarChange);
    if(!
error)
    {
        
HookEvent("round_start"RoundStart);
        
HookEvent("round_end"RoundStart);
        
HookEvent("player_death"Event_PlayerDeath);
        
HookEvent("player_spawn"evtPlayerSpawn);
        
HookEvent("player_bot_replace"player_bot_replace );    
        
HookEvent("bot_player_replace"bot_player_replace );    
        
Reset();
    }
}
GameCheck()
{
    
decl String:GameName[16];
    
GetConVarString(FindConVar("mp_gamemode"), GameNamesizeof(GameName));
    
    if (
StrEqual(GameName"survival"false))
        
GameMode 3;
    else if (
StrEqual(GameName"versus"false) || StrEqual(GameName"teamversus"false) || StrEqual(GameName"scavenge"false) || StrEqual(GameName"teamscavenge"false))
        
GameMode 2;
    else if (
StrEqual(GameName"coop"false) || StrEqual(GameName"realism"false))
        
GameMode 1;
    else
    {
        
GameMode 0;
     }
 
}
/*
public OnMapStart()
{
    //PrecacheSound(SOUND_REVIVE, true) ;
}
*/
public ConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    
Setting();
}

Setting()
{
 
    
revive_duration=GetConVarInt(l4d_revive_duration );
    
revive_maxtime=GetConVarInt(l4d_revive_maxtime) ;
    
ar_duration=GetConVarInt(l4d_CPR_duration );
    
ar_maxtime=GetConVarInt(l4d_CPR_maxtime) ;
    
maxtime=ar_maxtime;
    if(
revive_maxtime>maxtime)    maxtime=revive_maxtime;
}
public 
player_bot_replace(Handle:Spawn_Event, const String:Spawn_Name[], bool:Spawn_Broadcast)
{
    new 
client GetClientOfUserId(GetEventInt(Spawn_Event"player"));
    new 
bot GetClientOfUserId(GetEventInt(Spawn_Event"bot"));
    if(
client==&& !IsPlayerAlive(bot))
    {
        for (new 
1<= MaxClientsj++)
        {
            if (!
IsClientInGame(j) && CanRevive[j])
            {
                
client=j;
                break;
            }
        }
    }
    
replace(clientbot);
    
//PrintToChatAll("player_bot_replace %N  place %N", bot, client);
    
}
public 
bot_player_replace(Handle:Spawn_Event, const String:Spawn_Name[], bool:Spawn_Broadcast)
{
    new 
client GetClientOfUserId(GetEventInt(Spawn_Event"player"));
    new 
bot GetClientOfUserId(GetEventInt(Spawn_Event"bot"));
    
replace(botclient);
    
//PrintToChatAll("bot_player_replace %N  place %N", client, bot);
}
replace(client1client2)
{
    if(
CanRevive[client1])
    {
        
CanRevive[client2]=CanRevive[client1];
        
GhostLight[client2]=GhostLight[client1];
        
DeathTime[client2]=DeathTime[client1];
        
DeathPos[client2][0]=DeathPos[client1][0];
        
DeathPos[client2][1]=DeathPos[client1][1];
        
DeathPos[client2][2]=DeathPos[client1][2];
        
ReviveTime[client2]=ReviveTime[client1];
        
        
CanRevive[client1]=false;
        
GhostLight[client1]=0;
        
DeathTime[client1]=0.0;
        if(
timer_handle==INVALID_HANDLE)
        {
            
timer_handle=CreateTimer(1.0/TICKSWatch0TIMER_REPEAT);
        }
    }
}
public 
Action:Event_PlayerDeath(Handle:hEvent, const String:strName[], bool:DontBroadcast)
{
    if(
GameMode==2)return;
    new 
victim GetClientOfUserId(GetEventInt(hEvent"userid"));
    if(
victim<=0)return;
    if(
GetClientTeam(victim)==2)
    {
        
GetClientAbsOrigin(victimDeathPos[victim]);
        
DeathPos[victim][2]+=10.0;
        
CanRevive[victim]=true;
        
DeathTime[victim]=GetGameTime();
        
GhostLight[victim]=AddParticle("weapon_pipebomb_blinking_light"DeathPos[victim]);
        if(
timer_handle==INVALID_HANDLE)
        {
            
timer_handle=CreateTimer(1.0/TICKSWatch0TIMER_REPEAT);
        }
        
RevivePlayer[victim]=0;
        
ReviveTime[victim]=0.0;
        
CreateTimer(3.0hintvictim);
    }
}
public 
Action:hint(Handle:timerany:victim)
{
    if(
IsClientInGame(victim) && !IsPlayerAlive(victim))
    {
        for(new 
i=1i<=MaxClientsi++)
        {
            if (
!= && IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i)  )
            {
                if (
revive_maxtime >= && GetPlayerWeaponSlot(i3) !=-1)
                {
                    
PrintHintText(i"!%N FAINT! Use Medkit to revive within %d secs!\nGet close to his Body (Blinking light)\nSelect Medkit: press Crouch+Use for %d seconds"victimrevive_maxtimerevive_duration);
                }
                if (
ar_maxtime >= && GetPlayerWeaponSlot(i3) ==-1)
                {
                    
PrintHintText(i"!%N FAINT! Perform CPR for him within %d secs!\nGet close to his Body (Blinking light)\nPress Crouch+Use for %d seconds"victimar_maxtimear_duration);
                }    
            }
        }
    }
}
public 
Action:evtPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
//PrintToChatAll("evtPlayerSpawn %N ", client);
    
if(client<=0)return;
    if(
GetClientTeam(client)==2)//&& !IsPlayerAlive(client))
    
{
        
CanRevive[client]=false;
        
DeathTime[client]=0.0;
        
RevivePlayer[client]=0;
        
ReviveTime[client]=0.0;
        if (
GhostLight[client]!=&& IsValidEntity(GhostLight[client]))
        {
            
RemoveEdict(GhostLight[client]);
        }
        
GhostLight[client]=0;
    }
}
public 
OnClientDisconnect(client)
{
    
//PrintToChatAll("OnClientDisconnect %N", client);
    
if(client<=0)return;
    {
        if(
IsFakeClient(client))
        {
            
CanRevive[client]=false;
            
DeathTime[client]=0.0;
            
RevivePlayer[client]=0;
            
ReviveTime[client]=0.0;
            if (
GhostLight[client]!=&& IsValidEntity(GhostLight[client]))
            {
                
RemoveEdict(GhostLight[client]);
            }
            
GhostLight[client]=0;
        }
    }
}
new 
Float:timE;
new 
Float:pOs[3];
new 
String:weapon[32];
new 
buttons;

public 
Action:Watch(Handle:timerany:client)
{
 
    new 
index=0;
    
timE=GetGameTime();
    for (new 
1<= MaxClientsi++)
    {
        if(
CanRevive[i])
        {
            if(
timE-DeathTime[i]>maxtime)
            {
                
CanRevive[i]=false;
                
DeathTime[i]=0.0;
                
RevivePlayer[i]=0;
                
ReviveTime[i]=0.0;
                if (
GhostLight[i]!=&& IsValidEntity(GhostLight[i]))
                {
                    
RemoveEdict(GhostLight[i]);
                }
                
GhostLight[i]=0;                
            }
            else if(
IsClientInGame(i) && GetClientTeam(i)==&& !IsPlayerAlive(i))
            {
                
DeadMan[index++]=i;
            }
        }
    }
    if(
index>0)
    {
        for (new 
1<= MaxClientsj++)
        {
            if (
IsClientInGame(j) && IsPlayerAlive(j) && GetClientTeam(j)==&& !IsFakeClient(j))
            {
                
buttons GetClientButtons(j);
                if((
buttons IN_DUCK) && (buttons IN_USE))
                {
                    
GetClientWeapon(jweapon32);
                    new 
bool:firstaidkit=false;
                    if (
StrEqual(weapon"weapon_first_aid_kit"))
                    {
                        
firstaidkit=true;
                    }
                    new 
Float:dis=0.0;
                    new 
Float:min=10000.0;
                    new 
find=0;
                    
GetClientAbsOrigin(jpOs);
                    for(new 
i=0i<indexi++)
                    {
                        
dis=GetVectorDistance(pOsDeathPos[DeadMan[i]]);
                        if(
dis<=min)
                        {
                            
min=dis;
                            
find=DeadMan[i];
                        }
                    }
                    if(
find!=&& min<100.0)
                    {
                        if(
RevivePlayer[j]!=find)
                        {
                            
ReviveTime[j]=timE;
                            
//EmitSoundToAll(SOUND_REVIVE, j);
                        
}
                        
RevivePlayer[j]=find;
                        if(
firstaidkit)
                        {
                            if(
timE-DeathTime[find]<revive_maxtime)
                            {
                                
ShowBar(jfindtimE-ReviveTime[j], revive_durationtrue);
                                if(
timE-ReviveTime[j]>=revive_duration)
                                {
                                    if(
Revive(jfindtrue))
                                    {
                                        if (
GhostLight[j]!=&& IsValidEntity(GhostLight[j]))
                                        {
                                            
RemoveEdict(GhostLight[j]);
                                        }
                                        
GhostLight[j]=0;
                                    }
                                    else
                                    {
                                        
RevivePlayer[j]=0;
                                        
ReviveTime[j]=0.0;
                                    }
                                    
//StopSound(j, SNDCHAN_AUTO, SOUND_REVIVE);
                                
}    
                            }
                            else
                            {
                                
PrintCenterText(j"%N already dead"find);
                            }
                        }
                        else
                        {
                            if(
timE-DeathTime[find]<ar_maxtime)
                            {
                                
ShowBar(jfindtimE-ReviveTime[j], ar_durationfalse);
                                if(
timE-ReviveTime[j]>=ar_duration)
                                {
                                    if(
Revive(jfindfalse))
                                    {
                                        if (
GhostLight[j]!=&& IsValidEntity(GhostLight[j]))
                                        {
                                            
RemoveEdict(GhostLight[j]);
                                        }
                                        
GhostLight[j]=0;
                                    }
                                    else
                                    {
                                        
RevivePlayer[j]=0;
                                        
ReviveTime[j]=0.0;
                                    }
                                    
//StopSound(j, SNDCHAN_AUTO, SOUND_REVIVE);
                                
}    
                            }
                            else
                            {
                                
PrintCenterText(j"It is too late, CPR is useless for %N "find);
                            }                            
                        }

                    }
                     
                }
                else
                {
                    
RevivePlayer[j]=0;
                    
ReviveTime[j]=0.0;
                }
            }
        }
    }
    else
    {
        
timer_handle=INVALID_HANDLE;
        return 
Plugin_Stop;
    }
    return 
Plugin_Continue;
}


Revive(clientdeadbool:firstaidkit)
{
    if(
firstaidkit)
    {
        
GetClientWeapon(clientweapon32);
        if (
StrEqual(weapon"weapon_first_aid_kit"))
        {
            
SDKCall(hRoundRespawndead);
            
PerformTeleport(clientdead);

            if(
IsPlayerAlive(dead))
            {
                
SetEntityHealth(dead,  GetConVarInt(l4d_revive_health));
                
RemovePlayerItem(clientGetPlayerWeaponSlot(client3));
                
PrintToChatAll("\x03%N \x04used his Medkit to revive\x03 %N\x04!"clientdead);
                return 
true;
            }
        }
    }
    else
    {
        
SDKCall(hRoundRespawndead);
        
PerformTeleport(clientdead);

        if(
IsPlayerAlive(dead))
        {
            new 
propincapcounter FindSendPropInfo("CTerrorPlayer""m_currentReviveCount");
            
SetEntData(deadpropincapcounter21);
                
            new 
Handle:revivehealth FindConVar("pain_pills_health_value");  
             new 
temphpoffset FindSendPropOffs("CTerrorPlayer","m_healthBuffer");
            
SetEntDataFloat(deadtemphpoffsetGetConVarFloat(l4d_revive_health), true);
            
SetEntityHealth(dead1);
            
PrintToChatAll("\x03%N \x04used CPR to revive\x03 %N\x04!"clientdead);
            return 
true;
        }        
    }
    return 
false;
}

PerformTeleport(clientdead)
{
    new 
Float:pOs2[3];
    
GetClientAbsOrigin(clientpOs2);
    
TeleportEntity(deadpOs2NULL_VECTORNULL_VECTOR);
}

public 
RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
Reset();
}

stock CheatCommand(clientString:command[], String:parameter1[], String:parameter2[])
{
    new 
userflags GetUserFlagBits(client);
    
SetUserFlagBits(clientADMFLAG_ROOT);
    new 
flags GetCommandFlags(command);
    
SetCommandFlags(commandflags & ~FCVAR_CHEAT);
    
FakeClientCommand(client"%s %s %s"commandparameter1parameter2);
    
SetCommandFlags(commandflags);
    
SetUserFlagBits(clientuserflags);
}
Reset()
{
    for (new 
0MAXPLAYERS+1x++)
    {
        
CanRevive[x]=false;
        
GhostLight[x]=0;
        
DeathTime[x]=0.0;
        
RevivePlayer[x]=0;
        
ReviveTime[x]=0.0;
    }
}
new 
String:Gauge1[2] = "-";
new 
String:Gauge2[2] = "-";
new 
String:Gauge3[2] = "#";
ShowBar(clientdeadFloat:posmaxbool:firstaidkit
{
    new 
ij;
    new 
String:ChargeBar[101];
    
Format(ChargeBarsizeof(ChargeBar), "");

    new 
Float:GaugeNum pos/max*100;
    if(
GaugeNum 100.0)
        
GaugeNum 100.0;
    if(
GaugeNum<0.0)
        
GaugeNum 0.0;
    
     for(
i=0i<100i++)
        
ChargeBar[i] = Gauge1[0];
    new 
p=RoundFloatGaugeNum);
    if(
p>=&& p<100)ChargeBar[p] = Gauge3[0];
    
    if(
firstaidkit)    PrintCenterText(client"Using First Aid Kit to Revive %N  %3.0f %\n<< %s >>"deadGaugeNumChargeBar);
    else            
PrintCenterText(client"Performing CPR to Revive %N  %3.0f %\n<< %s >>"deadGaugeNumChargeBar);
}
public 
AddParticleString:s_Effect[100], Float:f_Origin[3])
{
    
decl i_Particle;
    
    
i_Particle CreateEntityByName("info_particle_system");
    
    if (
IsValidEdict(i_Particle))
    {
        
TeleportEntity(i_Particlef_OriginNULL_VECTORNULL_VECTOR);
        
DispatchKeyValue(i_Particle"effect_name"s_Effect);
        
DispatchSpawn(i_Particle);
        
ActivateEntity(i_Particle);
        
AcceptEntityInput(i_Particle"Start");
        
//CreateTimer(5.0, KillParticle, i_Particle); 
    
}
    return 
i_Particle;
}
public 
Action:KillParticle(Handle:timerany:i_Particle)
{
    if (
IsValidEntity(i_Particle))
    {
        
RemoveEdict(i_Particle);
    }

Captain Stubin is offline
Reply



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 20:26.


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