logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Persistent Locations OnClientLeave and OnClientEnter

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
tricia



Joined: 14 Jul 2005
Posts: 7

PostPosted: Fri Aug 05, 2005 2:51    Post subject: Persistent Locations OnClientLeave and OnClientEnter Reply with quote

Hi! Another, prolly very basic script for you guys, but i am, as I said, pretty new to all this. Okay, here's what i want to happen in my module. Whenever the player rests or leaves, his location gets stored using SetPersistentLocation, and whenever he logs on again, he will be returned to this location, despite server restarts. I have made the scripts, but I cant figure out whats wrong with them, nothing seems to happen when i enter. If some of you could help, it would be greatly appreciated!

Since the rest and clientleave scripts are basically the same, i'll just drop the leave one.
Rest script
Code:

#include "aps_include"
void main()
{
object oPC =GetLastPCRested();
location lPC = GetLocation(oPC);
string playername = GetPCPlayerName(oPC)+GetName(oPC);

SetPersistentLocation(oPC,playername,lPC);

SendMessageToPC(oPC,"Location saved");
}


OnClientEnter
Code:

#include "aps_include"

void main()
{
object oPC = GetEnteringObject();
string playername = GetPCPlayerName(oPC)+GetName(oPC);
location lPC = GetPersistentLocation(oPC, playername);
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToLocation(lPC));
}


Thanks again!
Trish


Last edited by tricia on Fri Aug 05, 2005 16:17; edited 2 times in total
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Fri Aug 05, 2005 4:29    Post subject: Reply with quote

One thing to remember is that the Module OnEnter() script fires before the
PC is fully in the module. You need to attach the script to the area where the StartLocation is or to a generic trigger surrounding that start location....
Back to top
View user's profile Send private message
tricia



Joined: 14 Jul 2005
Posts: 7

PostPosted: Fri Aug 05, 2005 9:58    Post subject: Reply with quote

Awsome!! Thank you very much, i never would have thought of that! hehe

Trish
Back to top
View user's profile Send private message
Primogenitor



Joined: 08 Jan 2005
Posts: 88

PostPosted: Fri Aug 05, 2005 9:59    Post subject: Reply with quote

Plus the GetPC* set of functions doesnt work in OnClientExit, since the event fires after the player has actually left. So the character is present, but not the remote player.

Also, by using that name structure, if a player has two identically named characters it will go a bit wierd.
Back to top
View user's profile Send private message
tricia



Joined: 14 Jul 2005
Posts: 7

PostPosted: Fri Aug 05, 2005 14:04    Post subject: Reply with quote

hm, okay. I dont think players with the same character names appear much too often, so I dont think its such a big problem. However the OnClientLeave problem is worse. What could I do to save their location when they exit? I'm sure there must be some smart solution, as I've seen this in other PW's.

Thanks again for the help guys Smile

Trish
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Fri Aug 05, 2005 15:40    Post subject: Reply with quote

The load generated by putting this into the database is fairly small so you can run if often (just not TOO often).

Good times to use it:

OnRest

10 seconds after entering an area (OnEnter(oArea)-Give the PC time to clear the transition)

OnLevelUp

Every 10 heartbeats (or other suitable amount; run from the PLAYER'S hearbeat script, NOT the module. You don't want to save 30 players at the same time Razz )

Exact location is not really nessessary, these will get them close without extra work. There are methods to use the OnExit but its clunkier....
Back to top
View user's profile Send private message
tricia



Joined: 14 Jul 2005
Posts: 7

PostPosted: Fri Aug 05, 2005 16:17    Post subject: Reply with quote

yes, the heartbeat sounds like a great idea! How would I save every ten hearbeats? I'm sorry if I have to get it in with teaspoons here, i'm really not that experienced with scripting. If i'm not to put the script in the OnHeartbeat of the module, where do I put it so it is run for players individually?

I'm not sure either how i could make it count the heartbeats, and run the script when it reaches a certain number, but here's my idea...

Code:

void main()
{
object oPC = OBJECT_SELF;
string playername = GetPCPlayerName(oPC)+GetName(oPC);
int iHB = GetLocalInt(oPC,playername);
iHB += 1;
if (iHB == 10)
    {
    ExecuteScript("persist_rest",oPC);
    SetLocalInt(oPC,playername,0);
    return;
    }
SetLocalInt(oPC,playername,iHB);
}


again, tho, where would I have to put this script?
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Fri Aug 05, 2005 16:55    Post subject: Reply with quote

tricia wrote:
yes, the heartbeat sounds like a great idea! How would I save every ten hearbeats? I'm sorry if I have to get it in with teaspoons here, i'm really not that experienced with scripting. If i'm not to put the script in the OnHeartbeat of the module, where do I put it so it is run for players individually?

I'm not sure either how i could make it count the heartbeats, and run the script when it reaches a certain number, but here's my idea...

Code:

void main()
{
object oPC = OBJECT_SELF;
string playername = GetPCPlayerName(oPC)+GetName(oPC);
int iHB = GetLocalInt(oPC,playername);
iHB += 1;
if (iHB == 10)
    {
    ExecuteScript("persist_rest",oPC);
    SetLocalInt(oPC,playername,0);
    return;
    }
SetLocalInt(oPC,playername,iHB);
}


again, tho, where would I have to put this script?


The easiest way to do it is to run a looping DelayCommand on the PC. But idea of the counter is right for a conventional heartbeat script Smile I would recommend a change to that though to account for a potential issue:

if (iHB => 10)

I would recommend a different approach. Put a line similar to this in you module's OnEnter() script.

Code:

DelayCommand(60.0,ExecuteScript("player_hbt",oPC));


The "player_hbt" script would be like this:

Code:

void main()
{
object oPC=OBJECT_SELF;
string playername = GetPCPlayerName(oPC)+GetName(oPC);

location lPC=GetLocation(oPC);
if(GetIsObjectValid(GetArea(oPC)))
       SetPersistentLocation(oPC,playername,lPC);


DelayCommand(60.0,ExecuteScript("player_hbt",oPC));
}


Its good to be sure when you are looking at saving the location that it is VALID before you save it.....

Out of curiosity, is there a specific reason you are parsing the name of the PC into the name of the location? Instead of calling it something like "CurrentLoc" ?

A comment on the above post about cheating. To help prevent cheating, I would recommend saving the PC's current level when they levelup and die. Reason: You can then compare the hitdice of the PC in the database to the hitdice of the entering character. Jump them to a "jail" area if they are more than 2 apart, bypassing the above save script. This will prevent players from having a lower-level character of the same name just so they can prevent dying and XP loss (if you use it) with their higher level character. You can also then flag the database with the oddity and keep a running count of how many times they have tried it Wink You could get real ugly and save the hitdice of the entering character and DE-LEVEL the higher level one to match it Laughing It all depends on how you wish to handle such things, just tracking is enough for me.....
Back to top
View user's profile Send private message
katowulf



Joined: 03 Jan 2006
Posts: 3

PostPosted: Tue Jan 03, 2006 3:35    Post subject: Reply with quote

tricia wrote:
hm, okay. I dont think players with the same character names appear much too often, so I dont think its such a big problem. However the OnClientLeave problem is worse. What could I do to save their location when they exit? I'm sure there must be some smart solution, as I've seen this in other PW's.

Thanks again for the help guys Smile

Trish


The pc object is still available onClientLeave... there are just certain things you can't do. For instance, you can't get the players name, but you can check local variables.

So, if you want to use the clients name onClientExit, then you just put it into a local variable onClientEnter(), then retrieve it there when they exit.

I prefer this approach to heartbeats, since heartbeats incur memory and performance losses.
Back to top
View user's profile Send private message Visit poster's website
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Thu Jan 05, 2006 14:55    Post subject: Reply with quote

A couple of things I did:

- Since you can not do a location in the mod_onEnter, a reset will always put you in the welcome area, I set a variable on the PC, then fire the location script in the area_onEnter event.

- For finding a player data on mod_onExit, I keep a playerID on the player and use that to access all player information from mod_onEnter on. An int is much easier to save then saving the player's name as a local.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group