AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Namechecking, beginner question (https://forums.alliedmods.net/showthread.php?t=276705)

fard 12-26-2015 16:03

Namechecking, beginner question
 
I made my first plugin after reading some wiki, but its not working (but listed at sm plugins list).
It's supposed to write in console if client have specified string in nickname.
What I'm doing wrong?
Code:

#include <sourcemod>
#include <string>

public void OnPluginStart()
{
        PrintToServer("Nick checker enabled!");
}

public onClientConnected(client){
        char clientName[32];
        GetClientName(client, clientName, 32);
        if(StrContains(clientName, "test", false)){
                PrintToServer("%s don't have test", clientName);
        }
        else{
                PrintToServer("%s have test", clientName);
        }
}


bally 12-26-2015 16:09

Re: Namechecking, beginner question
 
StrEquals

Icon315 12-26-2015 16:17

Re: Namechecking, beginner question
 
StrContains() doesn't return true/false, i think i remember it used to, it returns the position in the string where the substring is located or -1 if it didn't find it.
So
Code:

if(StrContains(clientName, "test", false) != -1){
is what you need

fard 12-26-2015 16:20

Re: Namechecking, beginner question
 
I don't want equal strings, just one string need to contain the second one, but I don't have "Nick checker enabled!", "%s don't have test" or "%s have test" at server console.

#edit
@up
ty, im checking it

#edit2
still nothing in console :<

Dr. Greg House 12-26-2015 16:30

Re: Namechecking, beginner question
 
Quote:

Originally Posted by Icon315 (Post 2376571)
StrContains() doesn't return true/false, i think i remember it used to, it returns the position in the string where the substring is located or -1 if it didn't find it.
So
Code:

if(StrContains(clientName, "test", false) != -1){
is what you need

It never did in SP.
I think it is true for some other languages/frameworks though (C#, Java?).

fard 12-26-2015 16:41

Re: Namechecking, beginner question
 
string inc
Code:

/**
 * Tests whether a string is found inside another string.
 *
 * @param str                        String to search in.
 * @param substr                Substring to find inside the original string.
 * @param caseSensitive        If true (default), search is case sensitive.
 *                                                If false, search is case insensitive.
 * @return                                -1 on failure (no match found). Any other value
 *                                                indicates a position in the string where the match starts.
 */
native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);

Quote:

Originally Posted by Dr. Greg House (Post 2376580)
It never did in SP.
I think it is true for some other languages/frameworks though (C#, Java?).

Position is >0 so its probably true in bool anyway :P

but I still have the problem :(
Code:

#include <sourcemod>
#include <string>

public Plugin myinfo =
{
        name = "test",
        author = "test",
        description = "My first plugin ever",
        version = "1.0",
        url = "http://www.sourcemod.net/"
}

public void OnPluginStart()
{
        PrintToServer("Nick checker enabled!");
}

public onClientConnected(client){
        char clientName[32];
        GetClientName(client, clientName, 32);
        if(StrContains(clientName, "test", false) != -1){
                PrintToServer("%s don't have test", clientName);
        }
        else{
                PrintToServer("%s have test", clientName);
        }
}

i dont have any text in console

Miu 12-26-2015 16:46

Re: Namechecking, beginner question
 
OnClientConnected, with a capital O

Icon315 12-26-2015 17:14

Re: Namechecking, beginner question
 
Quote:

Originally Posted by fard (Post 2376587)
Position is >0 so its probably true in bool anyway :P

Actually no, it's >= 0. So if the string starts with the substring then it will return 0 (which it would see as false).

Do you have any text in your error logs?

fard 12-26-2015 17:14

Re: Namechecking, beginner question
 
@Miu

That was so stupid from me, thanks!

Phil25 12-29-2015 03:56

Re: Namechecking, beginner question
 
On a side note, the %N format specifier is all you need most of the time instead of GetClientName().

PHP Code:

PrintToChat(client"Your name is %N"client



All times are GMT -4. The time now is 18:18.

Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.