Jump to content
Sign in to follow this  
axter

Saving A Players Location

Recommended Posts

Not hard, but convenient.

[CODE]/**
* Location saving
*/
private WorldTile savedLocation;[/CODE]

[CODE]/**
* Saves a location.
* [MENTION=75098]Para[/MENTION]m trash - save the location, or make it null.
*/
public void saveLocation(boolean trash) {
if (trash)
savedLocation = null;
else if (!trash)
if (controlerManager.getControler() != null) {
return;
}
savedLocation = new WorldTile(getX(), getY(), getPlane());
}[/CODE]

[CODE]/**
* Returns the players saved location.
*
* @return - savedLocatiom
*/
public WorldTile getSavedLocation() {
return savedLocation;
}[/CODE]

[CODE]/**
* Teleports a player to their saved location
*
* [MENTION=75098]Para[/MENTION]m delayTime
* - Time in which the player must be teleported
* [MENTION=75098]Para[/MENTION]m event
* - what you want to player to preform before the delay time
* runs out
* [MENTION=75098]Para[/MENTION]m timeEvent
* - true if you want the event to run when the delaytime is
* peaked
*/
public void sendToSavedLocation(final int delayTime, final Runnable event,
final boolean timeEvent) {
if (savedLocation == null) {
return;
}
if (delayTime < 1) {
try {
lock();
setNextWorldTile(savedLocation);
event.run();
unlock();
} catch (NullPointerException e) {
unlock();
}
}
else if (delayTime > 0) {
try {
lock();
event.run();
WorldTasksManager.schedule(new WorldTask() {
int delay;

[MENTION=15855]Over[/MENTION]ride
public void run() {
if (delay == delayTime)
unlock();
setNextWorldTile(savedLocation);
unlock();
stop();
delay++;
}
}, 0, 1);
} catch (NullPointerException e) {
unlock();
}
}
}[/CODE]

I included a runnable event in there if you want to run something before or while the teleport takes place. enjoy. Edited by axter

Share this post


Link to post
Share on other sites
What is the use of this?

I see this saves a WorldTile instance, but what for?

Share this post


Link to post
Share on other sites
[quote name='own4g3']What is the use of this?

I see this saves a WorldTile instance, but what for?[/QUOTE]

Teleport crystals. ;)

Share this post


Link to post
Share on other sites
Or, tele'ing someone back to their location after a random event or sumtin ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

×