AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Name contain (https://forums.alliedmods.net/showthread.php?t=237842)

Buckshot 03-30-2014 14:11

Name contain
 
I want to check if there is players with a similar name as the player i am using the command on.. I want to be able to type for example /ban Chu, if the player i am going to ban's name is "Chuck", but if there are other people on the server which names contains Chu, it will give an error message saying there are too many people with a similar name, and that you should provide more information. I know you are supposed to use "strlen" and a for loop in some way.. But i can't figure out how. So.. Run the command if the part of the name entered is unique and nobody else currently on the server has it, but give an error if someone else has a name which contains for example "Chu" . How do i do this? Thanks.

note:
I do not want to check specific names in the code itself, i want this to work on whatever player you use it on

Just made this quickly, i know it has alot of flaws in it's code and looks bad, and you don't need to fix that for me, i just made this quickly and haven't really cleared it up from junk and i will do that later.. But you get the point. The comment is where i want to check.

PHP Code:

#include < amxmodx >
#include <colorchat>

new const File[ ] = "addons/amxmodx/Reportlog.html"
new const szPREFIX[ ] = "[AMXX]"


public plugin_init( )
{
    
register_plugin"Report Player""1.0""BuckShot" )
    
register_clcmd"say ""PlayerReport" )
}

public 
PlayerReportid )
{
    new 
String192 ], Command10 ]
    
read_argsString191 )
    
remove_quotes(String)
    
strbreakStringCommand9String191 )
    
    if( !
equaliCommand"/report" ) )
    {
        return 
PLUGIN_HANDLED;
    }
    new 
Name32 ], Reason154 ], WriteToFile600 ]

    
strbreakStringNamesizeofName ), Reason153 )
    if( 
strlenName ) == )
    {
        
ColorChatidGREEN"%s^x01 Example Usage:^x04 /Report ^"Michael^" ^"He is using Aimbot^""szPREFIX )
        return 
PLUGIN_HANDLED;
    }
    
    new 
Players32 ], pnumPlayer
    
new num 0;
    
get_playersPlayerspnum )
    for(new 
0pnumi++)
    {
        
num++
        
Player Players]
        new 
szName32 ]
        
get_user_namePlayerszName32 )
        
        if(
containiszName ), Name ) ) // here is where i want to check it.. I wanna check if there are other players with a similar part of the name as in the "Name" variable here, if there's not, continue. Else give an error
        
{
            continue;
        }
        else if( 
pnum == num )
        {
            
ColorChat(idGREEN"This player doesnt exist" )
            return 
PLUGIN_HANDLED;
        }
    }
    
num 0;
    if( 
strlenReason ) < )
    {
        
ColorChatidGREEN"%s^x01 Please supply more information about the player"szPREFIX )
        return 
PLUGIN_HANDLED;
    }
    new 
Authid32 ], Ip32 ]
    
get_user_authidPlayerAuthid31 )
    
get_user_ipPlayerIp311)
    new 
Name232 ], Authid232 ], Ip232 ]
    
get_user_nameidName231 )
    
get_user_authididAuthid231 )
    
get_user_ipidIp2311)
    
    static 
Time21 ], InputTime64 ]
    
get_time("%Y/%m/%d - %H:%M:%S"Time20);
    
    
formatexInputTime63"<font color=^"blue^"><b>Time:</b></font> %s<br>"Time )
    
formatexWriteToFile599"<font color=^"red^"><b>Reported player:</font></b> %s<br><b><font color=^"red^">Reason:</font></b> %s<br><b><font color=^"red^">SteamID:</font></b> %s<br><b><font color=^"red^">IP:</font></b> %s</font><br><font color=^"green^"><b>Player who reported:</font></b> %s<br><b><font color=^"green^">SteamID:</font></b> %s<br><b><font color=^"green^">IP:</b></font> %s<br>_____________________________<br><br>"NameReasonAuthidIpName2Authid2Ip2 )
    
ColorChatidGREEN"%s^x01 Thank you! Your abuse report has been recieved"szPREFIX )
    
    
write_fileFileInputTime, -)
    
write_fileFileWriteToFile, -)
    return 
PLUGIN_HANDLED;



fysiks 03-30-2014 14:44

Re: Name contain
 
cmd_target()

Buckshot 03-30-2014 14:47

Re: Name contain
 
Quote:

Originally Posted by fysiks (Post 2117966)
cmd_target()

That doesn't really tell me anything.. :/ The main problem i'm having is finding a way to loop through players and check if theres anyone which's name contains the value of the Name variable, and if more than 1 player has that part of the name, it's gonna obviously just give an error.. And continue if it's an unique name

YamiKaitou 03-30-2014 15:06

Re: Name contain
 
cmd_target does exactly that

Buckshot 03-31-2014 15:36

Re: Name contain
 
Still can't get it working really though.. Having some problems here. What am i doing wrong? I'm only getting "Player not found" message

PHP Code:

#include < amxmodx >
#include < amxmisc >
#include < colorchat >

new const File[ ] = "addons/amxmodx/Reportlog.txt"
new const szPREFIX[ ] = "[AMXX]"


public plugin_init( )
{
    
register_plugin"Report Player""1.0""BuckShot" )
    
register_clcmd"say ""PlayerReport" )
}

public 
PlayerReportid )
{
    new 
String192 ], Command10 ]
    
read_argsString191 )
    
remove_quotes( String )
    
strbreakStringCommand9String191 )
    
    if( !
equaliCommand"/report" ) )
    {
        return;
    }
    new 
Name32 ], Reason154 ]

    
strbreakStringNamesizeofName ), Reason153 )
    if(
strlen(Name) == 0)
    {
        
ColorChatidGREEN"%s^x01 Example Usage:^x04 /Report ^"Michael^" ^"He is using Aimbot^""szPREFIX )
        return;
    }
    
    new 
Player cmd_targetidName )
    
    if( !
Player )
    {
        
ColorChatidGREEN"%s^x01 Player not found"szPREFIX )
        return;
    }
    
    if( 
strlenReason ) < 6)
    {
        
ColorChatidGREEN"%s^x01 Please supply more information about the player"szPREFIX )
        return;
    }
    
    
ColorChatidGREEN"%s^x01 Thank you! Your abuse report has been recieved"szPREFIX )
    new 
szName32 ], szAuthid32 ], szOutput300 ]
    
get_user_namePlayerszName31 )
    
get_user_authidPlayerszAuthid31 )
    
formatexszOutput299"Name: %s^n SteamID: %s^n Reason: %s^n"szNameszAuthidReason )
    
    
write_fileFileszOutput, -)



YamiKaitou 03-31-2014 15:42

Re: Name contain
 
Code:

/* Flags:
*  1 - obey immunity
*  2 - allow yourself
*  4 - must be alive
*  8 - can't be bot */
#define CMDTARGET_OBEY_IMMUNITY (1<<0)
#define CMDTARGET_ALLOW_SELF        (1<<1)
#define CMDTARGET_ONLY_ALIVE        (1<<2)
#define CMDTARGET_NO_BOTS                (1<<3)
stock cmd_target(id,const arg[],flags = CMDTARGET_OBEY_IMMUNITY)

Are you perhaps using it on yourself or using it on someone with immunity?

Buckshot 03-31-2014 15:46

Re: Name contain
 
Quote:

Originally Posted by YamiKaitou (Post 2118450)
Code:

/* Flags:
*  1 - obey immunity
*  2 - allow yourself
*  4 - must be alive
*  8 - can't be bot */
#define CMDTARGET_OBEY_IMMUNITY (1<<0)
#define CMDTARGET_ALLOW_SELF        (1<<1)
#define CMDTARGET_ONLY_ALIVE        (1<<2)
#define CMDTARGET_NO_BOTS                (1<<3)
stock cmd_target(id,const arg[],flags = CMDTARGET_OBEY_IMMUNITY)

Are you perhaps using it on yourself or using it on someone with immunity?

I am trying it out with bots currently. Don't got those people who will come to my server whenever i need them to, and test stuff out with me. The bots haven't been given any immunity either... I find this strange because i can't really see any errors in the code myself, but it doesn't work correctly still.. Usually i find whatever the problem is, even if it is a big code.. I should be able to find it in a code which is as small as this

Black Rose 03-31-2014 15:57

Re: Name contain
 
Code:

] say "/report Rose He sucks"
[AMXX] Thank you! Your abuse report has been recieved
[ --{-@ ] Black Rose :  /report Rose He sucks

Working for me.
All I did was add CMDTARGET_ALLOW_SELF to cmd_target() because I also have nobody to test with.

Maybe you are getting multiple matches, because that would produce the same error.
Say your bots are named Bob1 and Bob2, cmd_target can't pick one if you just write "Bob" and will return 0.

Buckshot 03-31-2014 16:01

Re: Name contain
 
Quote:

Originally Posted by Black Rose (Post 2118471)
Code:

] say "/report Rose He sucks"
[AMXX] Thank you! Your abuse report has been recieved
[ --{-@ ] Black Rose :  /report Rose He sucks

Working for me.
All I did was add CMDTARGET_ALLOW_SELF to cmd_target() because I also have nobody to test with.

Yeah i enabled debugging on it just now, and now it seems to be working.. Don't see why i would have to enable debugging though. A bug in the debug? :D:D But problem is solved now i guess. Thanks again guys. I will probably come back with more random threads some other day with questions, only because i do not have any active pawn coder buddies to ask. :cry: You could add me on steam if you need help with testing by the way.


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

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