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

Solved [L4D2] How to implement starting event?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
desire worker
Junior Member
Join Date: Dec 2018
Location: Umbrella Corporation
Old 12-09-2018 , 10:27   [L4D2] How to implement starting event?
Reply With Quote #1

Hi, I am noob in here and currently making custom plugin.

but don`t know how to implement starting event.

for example

suppose that I wanna get Axe in game starting(I know there is the mod for that kind of thins in this site i.e. ItemGiver. but this is just for study)

first, I have to hook the starting event. went Aliedmod wiki and find start event name.

there was 2 candidates; "round_start_pre_entity" and "round_start_post_nav".

Code:
public OnPluginStart()
{
     HookEvent("round_start_pre_entity", show_me_the_axe);
     HookEvent("round_start_post_nav", show_me_the_axe);
}

public Action:show_me_the_axe(Handle:hEvent, const String:strName[], bool:DontBroadcast)
{
        for (new i = 1; i <= MaxClients; i++)
	{
	        if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == 2)
		{
			FakeClientCommand(i, "give axe");
			GivePlayerItem(i, "weapon_axe");
		}
	}
}
and I also found using OnMapStart() can be alternative way. so I made below

Code:
public  OnMapStart(){
        for (new i = 1; i <= MaxClients; i++)
	{
	        if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == 2)
		{
			FakeClientCommand(i, "give axe");
			GivePlayerItem(i, "weapon_axe");
		}
	}
}
and tested all on left4dead2 singleplayer(in -insecure option)

and both of them never works. nothing happend.

what I have to use for game starting event?

and why aboves are not working

Last edited by desire worker; 12-11-2018 at 08:05.
desire worker is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-09-2018 , 12:32   Re: [left4dead2] How to implement starting event?
Reply With Quote #2

Hi,

try "player_spawn" event and use CreateTimer for at least 1.0 sec. delay.
Note: that spawn event also happen when you open safe rooms or respawn players by admin command.

IsClientConnected(i) && IsClientInGame(i) ------ you don't need IsClientConnected, since IsClientInGame is already include that check.

As about "why not work", that is happen because your client is not in game (or even not connected) at the time when your hook is called. Such connection may happen each time when new map is loaded.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-09-2018 at 12:37.
Dragokas is offline
desire worker
Junior Member
Join Date: Dec 2018
Location: Umbrella Corporation
Old 12-11-2018 , 08:06   Re: [L4D2] How to implement starting event?
Reply With Quote #3

yeah you`re right.

but for one time event. OnMapStart() is better off than dat. thank you
desire worker is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-11-2018 , 09:35   Re: [L4D2] How to implement starting event?
Reply With Quote #4

Of course you could create timer like 10.0 - 20.0 sec after OnMapStart and hope that all players will have time to load (really, some of them could take a much long time to load the map, more than even 20 sec.)

To wait for "On client in game" on map start I'm using own complex solution.
If you need reliable way and you want execute client related command as soon as it become in game you can use my proven solution:

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

float g_fConnectionTimeMin 10.0;
float g_fConnectionTimeMax 60.0;
float g_fConnectionTime[MAXPLAYERS+1];

bool g_InQueueCheckConn[MAXPLAYERS+1];

public 
OnPluginStart()
{
    
HookEvent("round_start",             Event_RoundStart,    EventHookMode_PostNoCopy);
    
HookEvent("round_end",                 Event_RoundEnd,        EventHookMode_PostNoCopy);
    
HookEvent("finale_win",             Event_RoundEnd,        EventHookMode_PostNoCopy);
    
HookEvent("mission_lost",             Event_RoundEnd,        EventHookMode_PostNoCopy);
    
HookEvent("map_transition",         Event_RoundEnd,        EventHookMode_PostNoCopy);
}

public 
Action Event_RoundStart(Event eventchar[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++) {
        if (!
g_InQueueCheckConn[i] && IsClientConnected(i)) {
            
g_InQueueCheckConn[i] = true;
            
CreateTimer(3.0Timer_CheckConnectionGetClientUserId(i), TIMER_FLAG_NO_MAPCHANGE);
        }
    }
}

public 
Action Event_RoundEnd(Event eventchar[] namebool dontBroadcast)
{
    
FreeQueue();
}
public 
void OnMapEnd()
{
    
FreeQueue();
}
void FreeQueue()
{
    for (
int i 1<= MaxClientsi++)
        
g_InQueueCheckConn[i] = false;
}

public 
void OnClientAuthorized(int client, const char[] auth)
{
    if (!
g_InQueueCheckConn[client] && !StrEqual(auth"BOT")) {
        
g_fConnectionTime[client] = g_fConnectionTimeMin;
        
g_InQueueCheckConn[client] = true;
        
CreateTimer(g_fConnectionTimeMinTimer_CheckConnectionGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
    }
}

public 
Action Timer_CheckConnection(Handle timerint UserId)
{
    
int client GetClientOfUserId(UserId);
    if (
client == 0) return Plugin_Stop;
    
    if (
IsClientConnected(client)) {
    
        if (!
IsClientInGame(client) || GetClientTeam(client) == 0)
        {
            if (
g_fConnectionTime[client] <= g_fConnectionTimeMax)
            {
                
g_fConnectionTime[client] += 2.0;
                
CreateTimer(2.0Timer_CheckConnectionUserIdTIMER_FLAG_NO_MAPCHANGE);
            }
        }
        else {
            
OnClientInGame(client);
        }
    }
    return 
Plugin_Continue;
}

void OnClientInGame(int client)
{
    
PrintToChatAll("OnClientInGame: %N"client);
    
g_InQueueCheckConn[client] = false;
    
    
// do the staff you need here

Note: that it filter real clients only, if you need execute command on fake client also, remove !StrEqual(auth, "BOT" check.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-11-2018 at 09:36.
Dragokas 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 09:41.


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