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

Solved Simple message on user connect help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FuZ!on
Senior Member
Join Date: Aug 2007
Old 10-05-2019 , 09:49   Simple message on user connect help
Reply With Quote #1

Hi,

It's been way too long and I'm looking to get back into the AlliedModders community. Always did some stuff with AMXx and never SourceMod so this is all new to me.

I started off with a small plugin by following a tutorial I found online that will trigger a message when a user connects to the server that displays the client's name and steam ID. The tutorial is a bit outdated and uses the GetClientAuthString method.

Here is the original code:

PHP Code:
#include <sourcemod>

public Plugin:myinfo = {
    
name "Tutorial",
    
author "FuZ!oN",
    
description "Display connect message",
    
url ""
};

public 
OnClientPutInServer(client)
{
    new 
String:name[32], String:authid[32];
    
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientauthidsizeof(authid));
    
    
PrintToChatAll("\x01[SM] \x04%s\x01 (\x05%s\x01) has joined."nameauthid);

Compiles with a warning about the GetClientAuthString which is understandable but still works. Only thing is, it doesn't appear to display a message for myself when I join the server, only bots: https://i.imgur.com/I7D8PhM.png

I did some research and changed my code around to this:

PHP Code:
#include <sourcemod>

public Plugin:myinfo = {
    
name "Tutorial",
    
author "Tim",
    
description "This is a simple tutorial",
    
url ""
};

public 
OnClientPutInServer(client)
{
    
char authid[32], name[64];
    
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthId(clientAuthId_Steam2authidsizeof(authid));
    
    
PrintToChatAll("\x01[SM] \x04%s\x01 (\x05%s\x01) has joined."nameauthid);

Compiles without warnings or errors but still have the same result as above.

Any help would be greatly appreciated so I can continue on my way

EDIT:

I just thought that maybe I'm too late to see the message because it's displayed before I spawn? I haven't been able to test it yet with another friend.

Last edited by FuZ!on; 10-05-2019 at 13:13.
FuZ!on is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-05-2019 , 10:20   Re: Simple message on user connect help
Reply With Quote #2

PHP Code:

#include <sourcemod>

public void OnClientPostAdminCheck(int client)
{
    if (!
IsFakeClient(client)) // skip bots
    
{
        
CreateTimer(5.0Timer_ConnectMessageGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
    }
}

public 
Action Timer_ConnectMessage(Handle timerany data)
{
    
int client GetClientOfUserId(view_as<int>(data));

    if (
client)
    {
        
char authid[65];
        if (
GetClientAuthId(clientAuthId_Steam2authidsizeof(authid))) // if has valid steam id
        
{
            
PrintToChatAll("\x01[SM] \x04%N\x01 (\x05%s\x01) has joined."clientauthid);
        }
        else
        {
            
// maybe show the message wihout his steamid ???
        
}
    }

__________________

Last edited by Ilusion9; 10-05-2019 at 10:22.
Ilusion9 is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 10-05-2019 , 12:18   Re: Simple message on user connect help
Reply With Quote #3

Hello!

I've done here a try, see if it works.
PHP Code:
#include <sourcemod>

public Plugin myinfo = {
    
name "Tutorial",
    
author "Tim",
    
version "1.0"
    
description "This is a simple tutorial",
    
url ""
};

public 
void OnClientPutInServer(int client)
{
    if(!
IsFakeClient(client) && client == 1)
    {
           
char steam[32];
           
GetClientAuthId(clientAuthId_Steam2steamsizeof(steam));
           
           
PrintToChatAll("[SM] \x04%N \x01(\05 %s \x01) has joined"clientsteam);
       }

If you need any help click down bellow and contact me on steam, It apears that I am offline, but it's just to avoid spamming!

Here is some stuff that can help u

All the colors suported! with X code:
Code:
default (white): \x01
darkred: \x02
purple: \x03
green: \x04
lightgreen: \x05
lime: \x06
red: \x07
grey: \x08
yellow: \x09
gold: \x10
Best regards and hope I could help,

SpirT.
__________________
SpirT is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-05-2019 , 12:21   Re: Simple message on user connect help
Reply With Quote #4

Quote:
Originally Posted by SpirT View Post
PHP Code:
public void OnClientPutInServer(int client)
{
    if(!
IsFakeClient(client) && client == 1)
    {
           
char steam[32];
           
GetClientAuthId(clientAuthId_Steam2steamsizeof(steam));
           
           
PrintToChatAll("[SM] \x04%N \x01(\05 %s \x01) has joined"clientsteam);
       }

You should check why OnClientPutInServer is bad for what he's asking (clients might not have steamids in this event and it's triggered too early).
Why are you checking if the client is 1?
You should check if the steamid is valid (if getclientauthid returns true)
__________________

Last edited by Ilusion9; 10-05-2019 at 12:22.
Ilusion9 is offline
FuZ!on
Senior Member
Join Date: Aug 2007
Old 10-05-2019 , 13:13   Re: Simple message on user connect help
Reply With Quote #5

Thank you both. SpirT, your code does not compile however Ilusion's compiles and works.

What I'm getting out of this is that I'm following an outdated tutorial that I should stop and find a new one.
FuZ!on is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 10-06-2019 , 05:57   Re: Simple message on user connect help
Reply With Quote #6

Quote:
Originally Posted by FuZ!on View Post
Thank you both. SpirT, your code does not compile however Ilusion's compiles and works.

What I'm getting out of this is that I'm following an outdated tutorial that I should stop and find a new one.
Weird, I compiled it with SPEdit compiler, and it worked with no problem. Btw, if Illusion works, nice! Any help you need just ask us. Add me and then if a problem appears, just call me ;)

Best Regards and good luck on your SourcePawn plugins,

SpirT.
__________________
SpirT 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 21:14.


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