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)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= isplayer() =
 +
'''Function''' (integer). Tells whether a player character of that name exists.
  
 +
isplayer(pname : string) : integer
  
−
<span id="bfisplayer"></span>
+
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.
  
−
'''Function:'''  <i><!--CODE-->integer isplayer( pcname : string ) ;</i><!--ENDCODE-->
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| pname || string || The player's name.
 +
|}
  
−
<!--TERM-->  '''pcname'''
+
== Returns ==
−
<!--DEFINITION-->        the name of the player being checked
+
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.
−
<!--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.
+
== Notes ==
−
This can be used and is used to find out if a player is truly a player that an
+
* 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()]]).
−
Administrator is deleting with out having that player on line.
+
* Give it a plain name. Text a player typed should be checked first: it is used to build a file name.
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
  
−
if (not isplayer(arg))
+
== Example ==
−
        {
+
<pre>
−
        sendtext (arg+" is not a character.&amp;n",self);
+
dilbegin do_whois(arg : string);
−
        quit;
+
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()]]
−
---~---~---~---~---~---~---~---~---
+
* [[Manual:DIL Manual/pc head()|pc head()]]
−
 
+
* [[Manual:DIL Manual/delete player()|delete player()]]
−
</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