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

[L4D2] Possible to hook when a person spawns and is -alive-?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kyu67
New Member
Join Date: Apr 2018
Old 04-29-2018 , 18:05   [L4D2] Possible to hook when a person spawns and is -alive-?
Reply With Quote #1

I am trying to hook an event for a person joining the server, when they are alive and have control over a character. In other words, I don't want anything to happen until the person who joined is not spectating, and is alive (not dead).

"player_spawn" fires when somebody joins, even if they are dead. So I hooked player_spawn and then did a check using GetClientHealth

PHP Code:
public void playerspawn(Event event, const char[] namebool dontBroadcast)
{

int userid GetEventInt(event"userid");
int clientid GetClientOfUserId(userid);

PrintToChatAll("clientID %i (%N) spawned; health %i"clientidclientidGetClientHealth(clientid));

if (
GetClientHealth(clientid) >= 1){
//Should only happen if the person is alive.. Assuming GetClientHealth reports correct values (which it doesn't appear to be doing)
}

With the 3 bots dead, someone joined and the health of their dead character (Coach) was reported as 1 (not 0). Then, they left the game, and "player_spawn" fired again this time saying the dead Coach had 100 health (even though it was still dead). The only time it appeared to work correctly was when the round first began and everyone was alive, it reported everyone (me and the 3 bots) had 100 health.

Can anyone think of a better way to do this since GetClientHealth doesn't appear to be reporting correct values all the time?

Last edited by Kyu67; 04-29-2018 at 18:09.
Kyu67 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 04-29-2018 , 21:21   Re: [L4D2] Possible to hook when a person spawns and is -alive-?
Reply With Quote #2

There is a takeover_bot event or something similar named, view: https://wiki.alliedmods.net/Left_4_dead_2_events

Health maybe 100 even when dead, do IsPlayerAlive(). Or you could create a 0.1 timer to check if alive.

This seems odd, why event spawn dead.
__________________

Last edited by Silvers; 04-29-2018 at 21:23.
Silvers is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 04-30-2018 , 01:06   Re: [L4D2] Possible to hook when a person spawns and is -alive-?
Reply With Quote #3

Why not just use a check for alive human survivors?

PHP Code:
stock bool bHasIdlePlayer(int client)
{
    
int iIdler GetClientOfUserId(GetEntData(clientFindSendPropInfo("SurvivorBot""m_humanSpectatorUserID")));
    if (
iIdler)
    {
        if (
IsClientInGame(iIdler) && !IsFakeClient(iIdler) && (GetClientTeam(iIdler) != 2))
        {
            return 
true;
        }
    }

    return 
false;
}

stock bool bIsHumanSurvivor(int client)
{
    return (
client && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == && IsPlayerAlive(client) && !IsClientInKickQueue(client) && !IsFakeClient(client) && !bHasIdlePlayer(client) && !bIsPlayerIdle(client));
}

stock bool bIsPlayerIdle(int client)
{
    for (
int iPlayer 1iPlayer <= MaxClientsiPlayer++)
    {
        if (!
IsClientInGame(iPlayer) || GetClientTeam(iPlayer) != || !IsFakeClient(iPlayer) || !bHasIdlePlayer(iPlayer))
        {
            continue;
        }

        
int iIdler GetClientOfUserId(GetEntData(iPlayerFindSendPropInfo("SurvivorBot""m_humanSpectatorUserID")));
        if (
iIdler == client)
        {
            return 
true;
        }
    }

    return 
false;

Use it like this inside player_spawn event:
PHP Code:
if (bIsHumanSurvivor(client))
{
    
// code here;

__________________

Last edited by Psyk0tik; 04-30-2018 at 01:08.
Psyk0tik is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 04-30-2018 , 04:58   Re: [L4D2] Possible to hook when a person spawns and is -alive-?
Reply With Quote #4

Player_spawn. Validate the client index and make sure the client is InGame. Check if client is in team 2 or 3 (GetClientTeam) (surv,inf) and validate if player is alive (IsPlayerAlive == true).

You took a complicated move by checking their health.

Last edited by Visual77; 04-30-2018 at 05:00.
Visual77 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 04-30-2018 , 11:05   Re: [L4D2] Possible to hook when a person spawns and is -alive-?
Reply With Quote #5

Use player_activate hook instead
MasterMind420 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 02:31.


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