<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
  SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
  <func>
    <title>SetPlrView</title>
    <category>Player</category>
    <subcat>View</subcat>
    <version>5.1 OC</version>
    <syntax>
      <rtype>bool</rtype>
      <params>
        <param>
          <type>int</type>
          <name>player</name>
          <desc>Player whose view distance to want to set.</desc>
        </param>
        <param>
          <type>object</type>
          <name>obj</name>
          <desc>Object to which to want to set the view.</desc>
          <optional />
        </param>
        <param>
          <type>bool</type>
          <name>immediate</name>
          <desc>If true, the view of the first open viewport for that player on each machine does not scroll smoothly but is set immediately.</desc>
        </param>
      </params>
    </syntax>
    <desc>Centers a player's view to the specified object. The view will follow this object until the next player command.</desc>
    <examples>
      <example>
        <code>local enemy;
// called every x frames
protected func Timer()
{
	// already found enemy is too far away
	if(enemy &amp;%amp;<funclink>ObjectDistance</funclink>(enemy) &gt; 350)
	{
		enemy = nil;
		<funclink>SetLightRange</funclink>(0);
	}


	// find (new) enemy
	if(!enemy)
	{
		// search for an enemy crew member in a distance of max. 300 pixels, return the closest one
		enemy = <funclink>FindObject</funclink>(<funclink>Find_OCF</funclink>(<funclink>OCF_CrewMember</funclink>),<funclink>Find_Distance</funclink>(300),<funclink>Find_Hostile</funclink>(GetOwner()),<funclink>Sort_Distance</funclink>());
		SetPlrView(<funclink>GetOwner</funclink>(),this);
		<funclink>SetLightRange</funclink>(100);
	}
	
	// so, if there is an enemy close to the tower, sound the alarm
	if (enemy)
	{
		<funclink>Message</funclink>(&quot;!!! ENEMY !!!&quot;);
		<funclink>Sound</funclink>(&quot;Alarm&quot;);
	}

}
				</code>
        <text>Automatic watch tower: if an enemy clonk gets near the tower the player's view will be set to the attacker. Also, a sound is played and a message is popped up while the enemy is in range.</text>
      </example>
    </examples>
    <related>
      <funclink>GetPlrView</funclink>
      <funclink>GetPlrViewMode</funclink>
      <funclink>SetLightRange</funclink>
      <funclink>SetFoW</funclink>
    </related>
  </func>
  <author>PeterW</author><date>2003-04</date>
  <author>Sven2</author><date>2015-12</date>
</funcs>
