View previous topic :: View next topic |
Author |
Message |
tricia
Joined: 14 Jul 2005 Posts: 7
|
Posted: Fri Aug 05, 2005 2:51 Post subject: Persistent Locations OnClientLeave and OnClientEnter |
|
|
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 |
|
|
Acrodania
Joined: 02 Jan 2005 Posts: 208
|
Posted: Fri Aug 05, 2005 4:29 Post subject: |
|
|
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 |
|
|
tricia
Joined: 14 Jul 2005 Posts: 7
|
Posted: Fri Aug 05, 2005 9:58 Post subject: |
|
|
Awsome!! Thank you very much, i never would have thought of that! hehe
Trish |
|
Back to top |
|
|
Primogenitor
Joined: 08 Jan 2005 Posts: 88
|
Posted: Fri Aug 05, 2005 9:59 Post subject: |
|
|
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 |
|
|
tricia
Joined: 14 Jul 2005 Posts: 7
|
Posted: Fri Aug 05, 2005 14:04 Post subject: |
|
|
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
Trish |
|
Back to top |
|
|
Acrodania
Joined: 02 Jan 2005 Posts: 208
|
Posted: Fri Aug 05, 2005 15:40 Post subject: |
|
|
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 )
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 |
|
|
tricia
Joined: 14 Jul 2005 Posts: 7
|
Posted: Fri Aug 05, 2005 16:17 Post subject: |
|
|
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 |
|
|
Acrodania
Joined: 02 Jan 2005 Posts: 208
|
Posted: Fri Aug 05, 2005 16:55 Post subject: |
|
|
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 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 You could get real ugly and save the hitdice of the entering character and DE-LEVEL the higher level one to match it It all depends on how you wish to handle such things, just tracking is enough for me..... |
|
Back to top |
|
|
katowulf
Joined: 03 Jan 2006 Posts: 3
|
Posted: Tue Jan 03, 2006 3:35 Post subject: |
|
|
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
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 |
|
|
odenien
Joined: 26 Sep 2005 Posts: 37
|
Posted: Thu Jan 05, 2006 14:55 Post subject: |
|
|
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 |
|
|
|
|
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
|