Author Topic: Teleporting PCs on client enter  (Read 620 times)

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Teleporting PCs on client enter
« on: March 20, 2016, 08:52:32 pm »


               

I want to teleport a PC to a waypoint as soon as it enters the module, but I can't assign any commands to it until the PC actually "materializes" in the area it logs in (either the module's starting area or the spot the PC last logged out in).


 


One solution that would probably work would be to use the area OnEnter event instead of the module-wide OnClientEnter, but this would require me to put an OnEnter script in every area's module event, not to mention modify the OnEnter scripts that some areas already have to include this functionality.


 


I've tried using a loop that continues until GetArea(oPC) returns a valid object and then make the jump, but it didn't work for reasons I haven't investigated further.


 


So, any ideas?



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #1 on: March 20, 2016, 10:00:16 pm »


               

Here is a simple Function to teleport a PC to any valid location you may pass using the lDest variable.



void Transport(object oPC, location lDest)
{
    if (!GetIsObjectValid(oPC))
        return;
    if (!GetIsObjectValid(GetArea(oPC)))
    {
        DelayCommand(1.0, Transport(oPC));
    }
    else if(GetTag(GetArea(oPC)) != "Tag of area desired")
    {
        AssignCommand(oPC, JumpToLocation(lDest));    
    }
}

Because of the AssignCommand,It will jump the player to the location after the algorythm terminate and will reattempt every 1.0 seconds until the PC is in a valid location. You can call this from either the onenter module event or the onenter area event.


 


As to implementation from your areas onenter, but best is to place in your modules onenter event as it is the first event to fire on a pc. You can create an include script something like HCR had.



// inc_on_ae
 
int preEvent()
{
    Transport(oPC, lDest);
    return TRUE;
}
 
void postEvent()
{
    return TRUE;
}

Place an include into the event script you desire affected and place preEvent() as the very first call in your void main  and the postEvent() as the last call. Place any routine you wish to run within those functions and you can affect all event scripts containing the include. If you wish not to affect a certain area, just place a conditional pertaining to the area as a check.

 

I set an area check in the include script example above to make sure the PC is only jumped once. If not exactly what you need, I can modify if I know more about what you need.

 

If you don't want the pc to see anything until they arrive on destination a black out and fade from black can be set up as well.


               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #2 on: March 21, 2016, 12:18:35 am »


               

Why does it have to be in the OnEnter/OnClientEnter? What's wrong with a "holding" area for when a PC accesses the module? Then it is a simple matter to use an OnExit script for this area to teleport them to precisely where you want them to go.


 


TR



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #3 on: March 21, 2016, 02:44:37 am »


               

I use starting area OnEnter as "First Client Enter" event, where I am teleporting them to last position. Its better solution that doing this with delays in normal OnClientEnter trust me.



               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #4 on: March 21, 2016, 06:35:45 am »


               

The thing is, PCs that log out will return to the place they logged out in, so I can't use a starting area OnEnter or OnExit only. I'd need to account for all areas in the module.


I want them to be teleported even if they logged in and logged out.



               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #5 on: March 21, 2016, 06:55:51 pm »


               


 


Here is a simple Function to teleport a PC to any valid location you may pass using the lDest variable.



void Transport(object oPC, location lDest)
{
    if (!GetIsObjectValid(oPC))
        return;
    if (!GetIsObjectValid(GetArea(oPC)))
    {
        DelayCommand(1.0, Transport(oPC));
    }
    else if(GetTag(GetArea(oPC)) != "Tag of area desired")
    {
        AssignCommand(oPC, JumpToLocation(lDest));    
    }
}

Because of the AssignCommand,It will jump the player to the location after the algorythm terminate and will reattempt every 1.0 seconds until the PC is in a valid location. You can call this from either the onenter module event or the onenter area event.


 


As to implementation from your areas onenter, but best is to place in your modules onenter event as it is the first event to fire on a pc. You can create an include script something like HCR had.



// inc_on_ae
 
int preEvent()
{
    Transport(oPC, lDest);
    return TRUE;
}
 
void postEvent()
{
    return TRUE;
}

Place an include into the event script you desire affected and place preEvent() as the very first call in your void main  and the postEvent() as the last call. Place any routine you wish to run within those functions and you can affect all event scripts containing the include. If you wish not to affect a certain area, just place a conditional pertaining to the area as a check.

 

I set an area check in the include script example above to make sure the PC is only jumped once. If not exactly what you need, I can modify if I know more about what you need.

 

If you don't want the pc to see anything until they arrive on destination a black out and fade from black can be set up as well.

 




 


Thanks, that's a good idea. '<img'>


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #6 on: March 21, 2016, 09:37:02 pm »


               

so this is not for recording last PC location and teleporting them to it when they enter the module after reset?



               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #7 on: March 22, 2016, 05:50:06 am »


               


so this is not for recording last PC location and teleporting them to it when they enter the module after reset?




 


Not really - what I needed was teleporting PCs to an area no matter whether they log in for the first time after reset or come back after logging out.


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #8 on: March 22, 2016, 04:20:06 pm »


               

Interesting feature. I might bother you about it for some answers when i catch you in chat.



               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #9 on: March 22, 2016, 07:33:19 pm »


               

Would using nwnx to remove the players turd on exit be an option?  That should reset their location on login to the module start location.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #10 on: March 23, 2016, 12:40:50 am »


               

For those that don't know, the above is not being rude. Bioware employees in their infinite wisdom decided to call a certain data type a turd and is an acronym of "Temporary User Resource Data".


 


TR



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Teleporting PCs on client enter
« Reply #11 on: March 23, 2016, 02:01:36 am »


               

OMG, ROFL, I think we all appreciate the heads up Tarot.


 


Anyway, removing the "turd" would have the player logging back into the default start location as you posted, Failed, unless you actually edited the info using something like moneo, or posibly Leto from within the module, but that is something most likely beyond the experience of most.