Category: Player
/ View
Since engine version: 1.0 OC
SetPlrView
Description
Centers a player's view to the specified object. The view will follow this object until the next player command.
Syntax
bool SetPlrView(int player, object obj, bool immediate);
Parameters
- player:
- Player whose view distance to want to set.
- obj:
- [opt] Object to which to want to set the view.
- immediate:
- If true, the view of the first open viewport for that player on each machine does not scroll smoothly but is set immediately.
Example
local enemy; // called every x frames protected func Timer() { // already found enemy is too far away if(enemy &%amp;ObjectDistance(enemy) > 350) { enemy = nil; SetLightRange(0); } // find (new) enemy if(!enemy) { // search for an enemy crew member in a distance of max. 300 pixels, return the closest one enemy = FindObject(Find_OCF(OCF_CrewMember),Find_Distance(300),Find_Hostile(GetOwner()),Sort_Distance()); SetPlrView(GetOwner(),this); SetLightRange(100); } // so, if there is an enemy close to the tower, sound the alarm if (enemy) { Message("!!! ENEMY !!!"); Sound("Alarm"); } }
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.