AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Checking player's name? (https://forums.alliedmods.net/showthread.php?t=57971)

Arion 07-16-2007 00:33

Checking player's name?
 
I'm totally newbie on scripting for AMXX and I'm with some difficulty to make a function:

Code:

When player connects <- public client_connect ?
  If (name == "Arion") 
<- strcmp (name, "Arion") ?
    Player sends command ("say \"Arion connecting\"")<- client_cmd (don't know)

I don't know what (id) (on public client_connect(id)) means too :o..



Someone could make this little code so I can study on it?


A little help with get_user_name(id, name, 17) is much appreciated too (Where did you get id? And name is where it will save the result? 17 is the number of letters it will save in the variable?


One day I'll be good :up:

stupok 07-16-2007 01:09

Re: Checking player's name?
 
Here's the code:

Code:

#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "stupok69"

public plugin_init() // This is executed when the plugin starts, typically on a mapchange.
{
        register_plugin(PLUGIN, VERSION, AUTHOR) // This let's AMXX know some information about the plugin.
}

public client_putinserver(id)
// id is a number that identifies a user in your server
// if the maximum number of players in your server is 32, then id can be from 1 to 32
// this function is generally executed after client_connect() and client_authorized()
{
        new name[32]
        // this is an array, the typical way to store strings in AMXX
       
        get_user_name(id, name, 31)
        // this function grabs the name of the client who has caused
        // client_putinserver() to be executed
       
        // id is the client's identifying number, so the function knows
        // which client to get the name of
       
        // 31 is the last slot of the array "name"
        // the function will only get the first 32 characters of the user's name
       
       
        // let's say the client's name is "Gaben the Turtle"
        // in this case, name would look like this:
        //
        // name[0] = 'G'
        // name[1] = 'a'
        // name[2] = 'b'
        // name[3] = 'e'
        // name[4] = 'n'
        // name[5] = ' '
        // name[6] = 't'
        // name[7] = 'h'
        // name[8] = 'e'
        // name[9] = ' '
        // name[10] = 'T'
        // name[11] = 'u'
        // name[12] = 'r'
        // name[13] = 't'
        // name[14] = 'l'
        // name[15] = 'e'
        // name[16] = 0
       
       
        client_print(0, print_chat, "%s is connecting", name)
       
        // this function is used to send text messages to clients
       
        // id is 0 here, which means that no client is specified, so all clients
        // will receive the text message
       
        // print_chat means that the message will look like a chat message
       
        // "%s is connecting" is the message that will be sent
        // %s is used as a placeholder for a string, in this case for the array "name"
       
        // finally, name is put after the message so %s can be replaced with the contents
        // of the array "name"
}

I suggest that you read these:

http://wiki.alliedmods.net/index.php/Pawn_Tutorial

http://wiki.alliedmods.net/index.php...od_X_Scripting

Arion 07-16-2007 13:44

Re: Checking player's name?
 
Thank you stupok69, things are a little more clear now..

But (always have a "but") how to make to execute a command on client of his name is, for example, L0Lo?


Code:

        for (i = 0; i < 32; i++)
            {
                if (name[0] == 'L' &&
                    name[1] == '0' &&
                    name[2] == 'L' &&
                    name[3] == 'o')
           
                    {
                        client_cmd (id, "name Arion")
                    }
            }

This "32" is number of players, which I don't know how to get :o

How to make the "for" to run on every player connected?

:up:


PS: I'd already read these two tutorials but I still have difficulty to understand commands that have lots of arguments
command (id, name, 1, et cetera)

o.O

stupok 07-16-2007 15:18

Re: Checking player's name?
 
The plugin below will check if a player's name is "Lol0". It will only check the player's name when he joins the server or changes his name. If it's "Lol0" then it will change his name to "Arion".

PHP Code:

#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "stupok69"


public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_infochanged(id)
// This is called whenever a client changes an "info"
// the client's name is an "info"

// Store which client caused client_infochanged()
// in the variable id
{
    new 
name[32]
    
    
get_user_info(id"name"name31)
    
// Call this function for client #id
    
    // Get "name" info
    
    // Store the result in the name array
    
    // The last element of name is 31
    
    
if(equal(name"Lol0"))
    
// Compare the contents of name with "Lol0"
    
{
        
client_cmd(id"name Arion")
        
// Call this function for client #id
        
        // Execute this command: "name Arion"
    
}



Arion 07-16-2007 20:28

Re: Checking player's name?
 
Thanks again stupok69 :D

It worked... but If I add a new line of client_cmd:

{
client_cmd(id, "name Arion")
// Call this function for client #id

// Execute this command: "name Arion"

client_cmd(id, "name L0Lo")
}


None of them run.. Why? Even if I make a new If, or a new function :S

(Yes, I want the name to change twice)


And where do I find functions like equal()? Only with experience? :P

I take a look on funcions' part of AMXX website when I see a new function, helps me a little :D

Rolnaaba 07-17-2007 16:50

Re: Checking player's name?
 
Quote:

Originally Posted by Stupok69's plugin
// name[16] = 0

would it be Zero or Null? Or interchangable?
Code:
if(name[16] == 0) {} //could I instead: if(name[16] == ^0) {} //and have the same thing?

stupok 07-17-2007 17:32

Re: Checking player's name?
 
I'm pretty sure it's like this:

Code:

if(name[16] == 0)

if(name[16] == '^0')


Rolnaaba 07-17-2007 17:37

Re: Checking player's name?
 
ahh

Arion 07-18-2007 16:26

Re: Checking player's name?
 
Ok, but how do I execute 2 commands in sequence? :D

(One below the other doesn't work, I tried :P)

Rolnaaba 07-18-2007 18:32

Re: Checking player's name?
 
Code:
client_cmd(id, "comand #1"); client_cmd(id, "comand #2");

or you may need a delay:
Code:
client_cmd(id, "comand #1");   set_task(0.1, "comand2");   public comand2() {      client_cmd(id, "comand #2"); }
something to that effect.


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

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