AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Pawn tutorial help please... (https://forums.alliedmods.net/showthread.php?t=17644)

lanvo 09-05-2005 15:40

Pawn tutorial help please...
 
Code:

public cmd_hp(id, level, cid)
{
    if (!cmd_access(id, level, cid, 3))
        return PLUGIN_HANDLED

    new Arg1[24]
    new Arg2[4]

    //Get the command arguments from the console
    read_argv(1, Arg1, 23)
    read_argv(2, Arg2, 3)

    //Convert the health from a string to a number
    new Health = str_to_num(Arg2)

    //Is the first character the @ symbol?
    if (Arg1[0] == '@')
    {
          new Team = 0
          //Check which team was specified.
          //Note that we start from [1], this is okay
          // it just means the @ isn't included
          if (equali(Arg1[1], "CT"))
          {
              Team = 2
          } else if (equali(Arg1[1], "T")) {
              Team = 1
          }
          new players[32], num
          //This function will fill the players[32] variable
          // with valid player ids.  num will contain the number
          // of players that are valid.
          get_players(players, num)
          new i
          for (i=0; i<num; i++)
          {
              if (!Team)
              {
                    //Set this player's health
                    set_user_health(players[i], Health)
              } else {
                    if (get_user_team(players[i]) == Team)
                    {
                        set_user_health(players[i], Health)
                    }
              }
          }
    } else {
          //finds a player id that matches the partial name given
          //the 1 means that it will not target the player if he
          // has immunity access
          new player = cmd_target(id, Arg1, 1)
        if (!player)
          {
              //this will print a message to the user who tried the command
              //The format for this command is called "format()" style,
              // where the first string formats the message according
              // to any number of following parameters.
              //  %s means a string
              //  %d or %i means an integer
              //  %f means a float
              // so "Hello %s, I am %d years old" will
              //  require a string and integer to follow
              console_print(id, "Sorry, player %s could not be found or targetted!", Arg1)
              return PLUGIN_HANDLED
          } else {
              set_user_health(player, Health)
          }
    }

    return PLUGIN_HANDLED
}

okay i just looked in the DOC tutorial section on amxmodx.org and i don't understand one command...

in the code:

new player = cmd_target(id, Arg1, 1)
if (!player)

what is "!player" means?

why is the "!" mark is infront of player? what function does it gives player?

Hawk552 09-05-2005 16:07

! anything means "not equal to" or "non existant", so if "player" = 0, then !player is true.

Also, if I do this:

Code:
new player = 1 if (player != 0) {      client_print(0,print_chat,"lol internet") }

player != 0 would be true, because player = 1, so it does not equal 0.

However, if I do this:

Code:
new player = 0 if (player != 0) {      client_print(0,print_chat,"lol internet") }

It would not be true, so clients would not have "lol internet" printed on their screens.

Also remember that any variable initiliazed but not given a value is automatically 0, so theoretically this would be the same as the one above:

Code:
new player if (player != 0) {      client_print(0,print_chat,"lol internet") }


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

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