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

Namechecking, beginner question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fard
AlliedModders Donor
Join Date: Dec 2015
Old 12-26-2015 , 16:03   Namechecking, beginner question
Reply With Quote #1

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);
	}
}

Last edited by fard; 12-26-2015 at 16:05.
fard is offline
bally
Senior Member
Join Date: Aug 2015
Old 12-26-2015 , 16:09   Re: Namechecking, beginner question
Reply With Quote #2

StrEquals
__________________
Perhaps my lack of faith was my undoing,
bally is offline
Icon315
Junior Member
Join Date: Dec 2014
Old 12-26-2015 , 16:17   Re: Namechecking, beginner question
Reply With Quote #3

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

Last edited by Icon315; 12-26-2015 at 16:18.
Icon315 is offline
fard
AlliedModders Donor
Join Date: Dec 2015
Old 12-26-2015 , 16:20   Re: Namechecking, beginner question
Reply With Quote #4

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 :<

Last edited by fard; 12-26-2015 at 16:26.
fard is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-26-2015 , 16:30   Re: Namechecking, beginner question
Reply With Quote #5

Quote:
Originally Posted by Icon315 View Post
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?).
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 12-26-2015 at 16:30.
Dr. Greg House is offline
fard
AlliedModders Donor
Join Date: Dec 2015
Old 12-26-2015 , 16:41   Re: Namechecking, beginner question
Reply With Quote #6

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 View Post
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

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

Last edited by fard; 12-26-2015 at 16:44.
fard is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-26-2015 , 16:46   Re: Namechecking, beginner question
Reply With Quote #7

OnClientConnected, with a capital O
Miu is offline
Icon315
Junior Member
Join Date: Dec 2014
Old 12-26-2015 , 17:14   Re: Namechecking, beginner question
Reply With Quote #8

Quote:
Originally Posted by fard View Post
Position is >0 so its probably true in bool anyway
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?

Last edited by Icon315; 12-26-2015 at 17:15.
Icon315 is offline
fard
AlliedModders Donor
Join Date: Dec 2015
Old 12-26-2015 , 17:14   Re: Namechecking, beginner question
Reply With Quote #9

@Miu

That was so stupid from me, thanks!

Last edited by fard; 12-26-2015 at 17:14.
fard is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 12-29-2015 , 03:56   Re: Namechecking, beginner question
Reply With Quote #10

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
Phil25 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 20:29.


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