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

Solved Fire a event that fire everytime survivor left the saferoom


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
strikeraot
Senior Member
Join Date: Dec 2018
Location: Viet Nam
Old 02-03-2022 , 21:03   Fire a event that fire everytime survivor left the saferoom
Reply With Quote #1

Hi, i hook this event "player_left_start_area", but it seems just fired once, if the survivors lose that round, this event does not fired anymore, how to make this can run everytime the survivor left the saferoom?
Code:
public OnPluginStart()
{
    HookEvent("player_left_start_area", PlayerLeftStartArea);
}

public Action:PlayerLeftStartArea(Handle:event, const String:name[], bool:dontBroadcast)
{
	new String:strItemName[32];
	strItemName = "weapon_first_aid_kit";
    giveStartItem(strItemName);
}

giveStartItem(const String:strItemName[32])
{
    new startingItem;
    new Float:clientOrigin[3];

    for (new i = 1; i <= MaxClients; i++) {
        if (IsClientInGame(i) && GetClientTeam(i) == 2) {
            startingItem = CreateEntityByName(strItemName);
            GetClientAbsOrigin(i, clientOrigin);
            TeleportEntity(startingItem, clientOrigin, NULL_VECTOR, NULL_VECTOR);
            DispatchSpawn(startingItem);
            EquipPlayerWeapon(i, startingItem);
        }
    }
}

Last edited by strikeraot; 02-04-2022 at 00:07.
strikeraot is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 02-03-2022 , 23:54   Re: Fire a event that fire everytime survivor left the saferoom
Reply With Quote #2

Better use timer to check if any survivor has left safe area.
Need Left 4 DHooks Direct

PHP Code:
#include <left4dhooks>
#include <sourcemod>

public void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
}

public 
void Event_RoundStart(Event event, const char[] namebool dontBroadcast
{
    
CreateTimer(1.0Timer_PlayerLeftStart_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_PlayerLeftStart(Handle Timer)
{
    if (
L4D_HasAnySurvivorLeftSafeArea())
    {
        
// do your things here


        
return Plugin_Stop;
    }
    return 
Plugin_Continue;

__________________

Last edited by HarryPotter; 02-03-2022 at 23:55.
HarryPotter is offline
strikeraot
Senior Member
Join Date: Dec 2018
Location: Viet Nam
Old 02-04-2022 , 00:06   Re: Fire a event that fire everytime survivor left the saferoom
Reply With Quote #3

Quote:
Originally Posted by HarryPotter View Post
Better use timer to check if any survivor has left safe area.
Need Left 4 DHooks Direct

PHP Code:
#include <left4dhooks>
#include <sourcemod>

public void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
}

public 
void Event_RoundStart(Event event, const char[] namebool dontBroadcast
{
    
CreateTimer(1.0Timer_PlayerLeftStart_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_PlayerLeftStart(Handle Timer)
{
    if (
L4D_HasAnySurvivorLeftSafeArea())
    {
        
// do your things here


        
return Plugin_Stop;
    }
    return 
Plugin_Continue;

thank you
strikeraot is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 02-04-2022 , 09:21   Re: Fire a event that fire everytime survivor left the saferoom
Reply With Quote #4

Left4DHooks uses these events to check status:
PHP Code:
player_left_checkpoint
player_entered_checkpoint 
This is used for the "L4D_IsInFirstCheckpoint" and "L4D_IsInLastCheckpoint" natives but they do some additional checks with regard to flow distance which may not actually suit all maps. For example if a map has the end saferoom close to the start saferoom this check would fail to be correct.

I guess you could use these events instead of "player_left_start_area" since I know they fire when someone enters/leaves. But the native "L4D_HasAnySurvivorLeftSafeArea" would also work and probably better.

I believe this events also trigger for Special Infected so if using them you would have to check if Survivor.

Edit: I've been informed it's: "player_left_safe_area" - New game event "player_left_safe_area", called every time the first survivor leaves the start area regardless of map number, restarts, etc.
__________________

Last edited by Silvers; 02-04-2022 at 12:05.
Silvers is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 02-04-2022 , 15:29   Re: Fire a event that fire everytime survivor left the saferoom
Reply With Quote #5

You can use m_hasAnySurvivorLeftSafeArea netprop from terror_player_manager entity too.

I don't know if it is 100% but I never had issues using that.

PHP Code:
/**
 * Returns whether any survivor have left the safe area.
 *
 * @return              True if any survivor have left safe area, false otherwise.
 */
static int g_iEntTerrorPlayerManager = -1;
bool HasAnySurvivorLeftSafeArea()
{
    
int entity EntRefToEntIndex(g_iEntTerrorPlayerManager);

    if (
entity == -1)
        
entity FindEntityByClassname(-1"terror_player_manager");

    if (
entity == -1)
    {
        
g_iEntTerrorPlayerManager = -1;
        return 
false;
    }

    
g_iEntTerrorPlayerManager EntIndexToEntRef(entity);

    return (
GetEntProp(entityProp_Send"m_hasAnySurvivorLeftSafeArea") == 1);

__________________

Last edited by Marttt; 02-04-2022 at 15:30.
Marttt 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 01:24.


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