Raised This Month: $ Target: $400
 0% 

[L4D2] "Player has joined the game"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vance
Junior Member
Join Date: Nov 2009
Old 11-30-2009 , 21:41   [L4D2] "Player has joined the game"
Reply With Quote #1

Hi all,

I'm writing up a simple plugin to display the message that a player has connected to the game, as for some reason, Valve removed it in l4d2.

This is what I've got so far:

Code:
#include <sourcemod>
#include <topmenus>
#include <menus>
#include <timers>
 
public Plugin:myinfo =
{
    name = "Player Joined",
    author = "{[FIIK 2.0]}Vance",
    description = "Tells players when a new player has joined.",
    version = "1.0.0.0",
    url = "www.sourcemod.net"
};

public OnPluginStart()
{
    HookEvent("player_connect", pjoin)
}

public Action:pjoin(Handle:event, const String:name[], bool:dontBroadcast)
{
    decl String:name[64];
    GetEventString(event, "name", name, sizeof(name));
    PrintToChatAll("%s has joined the game.",name);
}
However, the problem I'm having is that it includes bots in the check, and it considers everyone as having joined again on a map change.

Is there any way to stop it seeing bots, and make it stop showing on every map change?

Thank you for your help.
Vance is offline
HarbingTarbl
Junior Member
Join Date: Nov 2009
Old 11-30-2009 , 22:23   Re: [L4D2] "Player has joined the game"
Reply With Quote #2

Not sure if it would work, but you could try replacing your event hook with a public OnClientConnected(client) {} function. Then using GetClientName() to get the player name. I think that should at the very least fix the bot problem, but it should also stop it from triggering on map changes.

Last edited by HarbingTarbl; 11-30-2009 at 22:25.
HarbingTarbl is offline
Vance
Junior Member
Join Date: Nov 2009
Old 11-30-2009 , 22:57   Re: [L4D2] "Player has joined the game"
Reply With Quote #3

That worked perfectly. Thanks so much for the speedy, and incredibly helpful reply!
Vance is offline
Bigbuck
Senior Member
Join Date: Jul 2009
Old 11-30-2009 , 23:18   Re: [L4D2] "Player has joined the game"
Reply With Quote #4

A better way would be to use OnClientPutInServer which would let you use IsFakeClient to root out the bots as the client is in the game at that point. What I do is pretty much the same as the tutorial shows.
http://wiki.alliedmods.net/Timers_%2...d_Scripting%29
Bigbuck is offline
pvtschlag
Member
Join Date: Nov 2009
Old 12-01-2009 , 00:41   Re: [L4D2] "Player has joined the game"
Reply With Quote #5

Just a note on PrintToChatAll() and GetClientName(). You no longer need to use GetClientName like below.

Code:
decl String:name[64];
GetClientName(client, name, sizeof(name);
PrintToChatAll("%s joined the game.", name);
You can simply just do this.

Code:
PrintToChatAll("%N joined the game.", client);
Just a tip to make things easier in the future as both work perfectly fine.
pvtschlag is offline
Bigbuck
Senior Member
Join Date: Jul 2009
Old 12-01-2009 , 09:31   Re: [L4D2] "Player has joined the game"
Reply With Quote #6

Thanks for that tip. That will save a few lines .
Bigbuck is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 12-01-2009 , 11:07   Re: [L4D2] "Player has joined the game"
Reply With Quote #7

Any chanse of posting a working script?
Visual77 is offline
DieTeetasse
Senior Member
Join Date: Jul 2009
Old 12-01-2009 , 11:49   Re: [L4D2] "Player has joined the game"
Reply With Quote #8

PHP Code:
#include <sourcemod>

public OnClientPutInServer(client)
{
   if (!
IsFakeClient(client)) PrintToChatAll("%N joined the game."client);

Didn't test it, but this should work.
DieTeetasse is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 12-01-2009 , 11:54   Re: [L4D2] "Player has joined the game"
Reply With Quote #9

Thanks. public OnClientConnected(client) seems to be better to use though since OnClientPutInServer
prints out that the player has joined the game even on mapchange.

Last edited by Visual77; 12-01-2009 at 12:09.
Visual77 is offline
Bigbuck
Senior Member
Join Date: Jul 2009
Old 12-01-2009 , 14:32   Re: [L4D2] "Player has joined the game"
Reply With Quote #10

If you want the player that joined to see the message as well, you will need to use a timer in OnClientPutInServer or a longer timer in OnClientConnected.
Bigbuck 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 22:11.


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