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

Solved If username doesn't look like this then...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 07-28-2017 , 17:53   If username doesn't look like this then...
Reply With Quote #1

I'm stuck on something here..

I'm making a plugin for my server where VIP's automatically gets a ✪ before their name.
I realized it needs to be on a repeatable timer that checks whether or not they actually got their names changed by the plugin.

So I made this:
PHP Code:
public void SetName(int client) {
    if(
CheckCommandAccess(client""ADMFLAG_RESERVATIONtrue)) {
        
char orig_name[MAX_NAME_LENGTH];
        
char newName[MAX_NAME_LENGTH];
        
        
GetClientName(clientorig_namesizeof(orig_name));
        
Format(newNamesizeof(newName), "✪ %s"orig_name);
        
        if(!
StrEqual(orig_namenewName)) {
            
SetClientName(clientnewName);
        }
    }

And with the latter if-statement I thought it wouldn't change the names if they already had the star in their name. That didn't work, it just repeats each one second that the timer is set to and gives one more star each second.

How can I change it so it only applies the newName variable if they don't have a star before?
Is it possible to check if a variable contains a character?

EDIT
Found that string.inc had StrContains(), so I did this:
PHP Code:
public void SetName(int client) {
    if(
CheckCommandAccess(client""ADMFLAG_RESERVATIONtrue)) {
        
char curName[MAX_NAME_LENGTH];
        
char newName[MAX_NAME_LENGTH];
        
        
GetClientName(clientcurNamesizeof(curName));
        
Format(newNamesizeof(newName), "✪ %s"curName);
        
        if(!
StrContains(curName"✪"false)) {
            
SetClientName(clientnewName);
        }
    }

But that never actually seems to update the name..
__________________

Last edited by condolent; 07-28-2017 at 18:18.
condolent is offline
stephen473
Senior Member
Join Date: Jan 2017
Location: somewhere on earth
Old 07-28-2017 , 18:02   Re: If username doesn't look like this then...
Reply With Quote #2

Have you tried StrContains ?
__________________
Also known as Hardy`.

Feel free to contact me if you have a private plugin request!

My Steam Profile | Discord: Hardy`#3792
stephen473 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 07-28-2017 , 18:02   Re: If username doesn't look like this then...
Reply With Quote #3

Quote:
Originally Posted by stephen473 View Post
Have you tried StrContains ?
Updated the OP the second before your answer xd
__________________
condolent is offline
stephen473
Senior Member
Join Date: Jan 2017
Location: somewhere on earth
Old 07-28-2017 , 18:06   Re: If username doesn't look like this then...
Reply With Quote #4

I can fix it maybe tomorrow
__________________
Also known as Hardy`.

Feel free to contact me if you have a private plugin request!

My Steam Profile | Discord: Hardy`#3792

Last edited by stephen473; 07-28-2017 at 18:08. Reason: Edited
stephen473 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 07-28-2017 , 18:07   Re: If username doesn't look like this then...
Reply With Quote #5

Quote:
Originally Posted by stephen473 View Post
So the problem solved?
Nah, it never actually changes the name now! I added the code with StrContains() in the main post
__________________
condolent is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 07-28-2017 , 18:09   Re: If username doesn't look like this then...
Reply With Quote #6

I'm stupid, realized that StrContains never returns true or false... xD

PHP Code:
if(StrContains(curName"✪"false) != -1) {
    
GetClientName(clientcurNamesizeof(curName));
    
Format(newNamesizeof(newName), "✪ %s"curName);
    
    
SetClientName(clientnewName);

Still doesn't work tho :/
__________________

Last edited by condolent; 07-28-2017 at 18:10.
condolent is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 07-28-2017 , 18:11   Re: If username doesn't look like this then...
Reply With Quote #7

StrContains isn't a bool, you should do something like this
PHP Code:
StrContains (...) == 0// is the first character
StrContains (...) != 1//it contains it in any position 
Edit: I think I'm total wrong, !... Is ok
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 07-28-2017 at 18:14.
Papero is offline
stephen473
Senior Member
Join Date: Jan 2017
Location: somewhere on earth
Old 07-28-2017 , 18:13   Re: If username doesn't look like this then...
Reply With Quote #8

https://forums.alliedmods.net/showthread.php?t=186346

You can take some help from this plugin
__________________
Also known as Hardy`.

Feel free to contact me if you have a private plugin request!

My Steam Profile | Discord: Hardy`#3792
stephen473 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 07-28-2017 , 18:13   Re: If username doesn't look like this then...
Reply With Quote #9

Quote:
Originally Posted by Papero View Post
StrContains isn't a bool, you should do something like this
PHP Code:
StrContains (...) == 0// is the first character
StrContains (...) != 1//it contains it in any position 
I see, then this should work am I right?
PHP Code:
if(StrContains(curName"✪"false) == -1) {
            
GetClientName(clientcurNamesizeof(curName));
            
Format(newNamesizeof(newName), "✪ %s"curName);
            
            
SetClientName(clientnewName);
        } 
But that still repeats and adds a new one.

EDIT
Obviously put the GetClientName in the wrong place after trying to sort the method out lol..

This is what I ended up with:
PHP Code:
public void SetName(int client) {
    if(
CheckCommandAccess(client""ADMFLAG_RESERVATIONtrue)) {
        
char curName[MAX_NAME_LENGTH];
        
char newName[MAX_NAME_LENGTH];
        
        
GetClientName(clientcurNamesizeof(curName));
        
        if(
StrContains(curName"✪"false) == -1) {
            
Format(newNamesizeof(newName), "✪ %s"curName);
            
            
SetClientName(clientnewName);
        }
    }

And it finally works!

Thanks for all the help
__________________

Last edited by condolent; 07-28-2017 at 18:15.
condolent is offline
stephen473
Senior Member
Join Date: Jan 2017
Location: somewhere on earth
Old 07-28-2017 , 18:17   Re: If username doesn't look like this then...
Reply With Quote #10

You're welcome
__________________
Also known as Hardy`.

Feel free to contact me if you have a private plugin request!

My Steam Profile | Discord: Hardy`#3792
stephen473 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 13:06.


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