Difference between revisions of "Manual:DIL Manual/isplayer()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfisplayer"></span>
+
= isplayer() =
 +
'''Function''' (integer). Tells whether a player character of that name exists.
  
−
  '''Function:'''  <i><!--CODE-->integer isplayer( pcname : string ) ;</i><!--ENDCODE-->
+
  isplayer(pname : string) : integer
  
−
<!--TERM--> '''pcname'''
+
Checks whether a saved player of that name exists, whether the player is in the game or not. Case doesn't matter. It looks for the player's file in the player directory (<code>plydir</code> in <code>server.cfg</code>), so a player made a moment ago counts once the character has been saved.
−
<!--DEFINITION-->         the name of the player being checked
 
−
<!--TERM--> '''Return'''
 
−
<!--DEFINITION-->         Returns an integer TRUE if pcname is a player FALSE if not
 
  
−
This function is used to find out if a string you pass to it is a player or not.
+
== Parameters ==
−
This can be used and is used to find out if a player is truly a player that an
+
{| class="wikitable"
−
Administrator is deleting with out having that player on line.
+
! Name !! Type !! Meaning
−
'''Example:'''
+
|-
−
<i><!--CODE-->
+
| pname || string || The player's name.
−
---~---~---~---~---~---~---~---~---
+
|}
  
−
if (not isplayer(arg))
+
== Returns ==
−
---~---~---~---~---~---~---~---~---
+
TRUE when the player exists, FALSE when not. An empty string gives FALSE (and the line "Empty string in find_player_id." in the log). A string variable that has never been given a value makes the call fail.
  
−
</i><!--ENDCODE-->
+
== Notes ==
 +
* It says nothing about whether the player is online; for that, look for the player in the game (see [[Manual:DIL Manual/pc head()|pc_head()]]).
 +
* Give it a plain name. Text a player typed should be checked first: it is used to build a file name.
  
 +
== Example ==
 +
<pre>
 +
dilbegin do_whois(arg : string);
 +
var
 +
  pname : string;
 +
code
 +
{
 +
  pname := getword(arg);
 +
  if (pname == "")
 +
  {
 +
      sendtext("Whose name?<br/>", self);
 +
      quit;
 +
  }
 +
  if (not isplayer(pname))
 +
      sendtext("There is no player called " + pname + ".<br/>", self);
 +
  else
 +
      sendtext(pname + " is a player of this realm.<br/>", self);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
A command that tells whether a name belongs to a player, as the postman in mail.zon checks an address.
  
−
 
+
== See also ==
−
---~---~---~---~---~---~---~---~---
+
* [[Manual:DIL Manual/findunit()|findunit()]]
−
<span id="bfisplayer"></span>
+
* [[Manual:DIL Manual/pc head()|pc head()]]
−
 
+
* [[Manual:DIL Manual/delete player()|delete player()]]
−
'''Function:'''  <i><!--CODE-->integer isplayer( pcname : string ) ;</i><!--ENDCODE-->
 
−
 
 
−
<!--TERM-->  '''pcname'''
 
−
<!--DEFINITION-->        the name of the player being checked
 
−
<!--TERM-->  '''Return'''
 
−
<!--DEFINITION-->        Returns an integer TRUE if pcname is a player FALSE if not
 
−
 
 
−
This function is used to find out if a string you pass to it is a player or not.
 
−
This can be used and is used to find out if a player is truly a player that an
 
−
Administrator is deleting with out having that player on line.
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
if (not isplayer(arg))
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
 
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:17, 14 November 2026

isplayer()

Function (integer). Tells whether a player character of that name exists.

isplayer(pname : string) : integer

Checks whether a saved player of that name exists, whether the player is in the game or not. Case doesn't matter. It looks for the player's file in the player directory (plydir in server.cfg), so a player made a moment ago counts once the character has been saved.

Parameters

Name Type Meaning
pname string The player's name.

Returns

TRUE when the player exists, FALSE when not. An empty string gives FALSE (and the line "Empty string in find_player_id." in the log). A string variable that has never been given a value makes the call fail.

Notes

  • It says nothing about whether the player is online; for that, look for the player in the game (see pc_head()).
  • Give it a plain name. Text a player typed should be checked first: it is used to build a file name.

Example

dilbegin do_whois(arg : string);
var
   pname : string;
code
{
   pname := getword(arg);
   if (pname == "")
   {
      sendtext("Whose name?<br/>", self);
      quit;
   }
   if (not isplayer(pname))
      sendtext("There is no player called " + pname + ".<br/>", self);
   else
      sendtext(pname + " is a player of this realm.<br/>", self);
   quit;
}
dilend

A command that tells whether a name belongs to a player, as the postman in mail.zon checks an address.

See also