Author Topic: Useful function for OnClientEnter event  (Read 317 times)


  • Full Member
  • ***
  • Posts: 234
  • Karma: +0/-0
Useful function for OnClientEnter event
« on: February 08, 2011, 06:28:01 am »

               Many servers are set up so that on entry to the server, the player is automatically jumped to the starting location.  Doing this prevents several potential problems.

The problem is that if the player is already at the start location, the start location will load twice which is a waste of time.  The following function gets around that problem.  Place it before the void main() function in your OnClientEnter script.
// Waits until the player is in a valid area then, if the player is not
// at the starting location, forces the player to jump to it.
void JumpToStart(object oPlayer=OBJECT_SELF);
void JumpToStart(object oPlayer=OBJECT_SELF)
  location lStart = GetStartingLocation();
  if (!GetIsObjectValid(GetArea(oPlayer)))
  if (GetArea(oPlayer)!=GetAreaFromLocation(lStart)
    || GetDistanceBetweenLocations(GetLocation(oPlayer),lStart)>5.0)
In your OnClientEnter event, you need to find the entering player and assign the JumpToStart command to the player.
object oPC=GetEnteringObject();
Strictly speaking, there's no need to specify the PC in the function call since the function uses OBJECT_SELF as the default, which should automatically select the player.