diff --git a/scripts/commands/teleport.py b/scripts/commands/teleport.py new file mode 100644 index 00000000..b4134f32 --- /dev/null +++ b/scripts/commands/teleport.py @@ -0,0 +1,46 @@ +import sys +from engine.resources.scene import Point3D + +def setup(): + return + +def run(core, actor, target, commandString): + playerObject = actor.getSlottedObject('ghost') + + if not playerObject: + return + + commandArgs = commandString.split(' ') + arg4 = None + if len(commandArgs) > 0: + arg1 = commandArgs[0] + if len(commandArgs) > 1: + arg2 = commandArgs[1] + if len(commandArgs) > 2: + arg3 = commandArgs[2] + if len(commandArgs) > 3: + arg4 = commandArgs[3] + + if arg1 and arg2 and arg3 and arg4 is not None: + try: + actor.sendSystemMessage('Teleporting...', 0) + position = Point3D(float(arg1), float(arg2), float(arg3)) + core.simulationService.transferToPlanet(actor, core.terrainService.getPlanetByName(arg4), position, actor.getOrientation(), None) + except: + actor.sendSystemMessage('Invalid Syntax. Syntax is: /teleport [] ', 0) + return + return + + elif arg1 and arg2 and arg3: + try: + actor.sendSystemMessage('Teleporting...', 0) + position = Point3D(float(arg1), 0, float(arg2)) + core.simulationService.transferToPlanet(actor, core.terrainService.getPlanetByName(arg3), position, actor.getOrientation(), None) + except: + actor.sendSystemMessage('Invalid Syntax. Syntax is: /teleport [] ', 0) + return + + else: + actor.sendSystemMessage('Invalid Syntax. Syntax is: /teleport [] ', 0) + return + return \ No newline at end of file diff --git a/scripts/commands/teleporttarget.py b/scripts/commands/teleporttarget.py index f497fe25..c736047e 100644 --- a/scripts/commands/teleporttarget.py +++ b/scripts/commands/teleporttarget.py @@ -5,25 +5,18 @@ def setup(): return def run(core, actor, target, commandString): - + playerObject = actor.getSlottedObject('ghost') if not playerObject: return - commandArgs = commandString.split(' ') - if len(commandArgs) > 0: - arg1 = commandArgs[0] - if len(commandArgs) > 1: - arg2 = commandArgs[1] - if len(commandArgs) > 2: - arg3 = commandArgs[2] - if len(commandArgs) > 3: - arg4 = commandArgs[3] - - if arg1 and arg2 and arg3 and arg4 target: - position = Point3D(float(arg2), float(arg3), float(arg4)) - core.simulationService.transferToPlanet(target, core.terrainService.getPlanetByName(arg1), position, actor.getOrientation(), None) - + if target and target.getSlottedObject('ghost') is not None: + actor.sendSystemMessage('Teleporting ' + target.getCustomName() + ' to you...', 0) + core.simulationService.teleport(target, actor.getPosition(), actor.getOrientation(), 0) + return + else: + actor.sendSystemMessage('Invalid Syntax. Syntax is: /teleporttarget ', 0) + return return diff --git a/scripts/commands/teleportto.py b/scripts/commands/teleportto.py new file mode 100644 index 00000000..b16b7d64 --- /dev/null +++ b/scripts/commands/teleportto.py @@ -0,0 +1,30 @@ +import sys +from engine.resources.scene import Point3D + +def setup(): + return + +def run(core, actor, target, commandString): + + playerObject = actor.getSlottedObject('ghost') + + if not playerObject: + return + + if target is None: + target = core.objectService.getObjectByFirstName(commandString) + + if target and target.getSlottedObject('ghost') is not None: + actor.sendSystemMessage('Teleporting you to ' + target.getCustomName() + '...', 0) + if target.getPlanetId() == actor.getPlanetId(): + core.simulationService.teleport(actor, target.getPosition(), target.getOrientation(), target.getParentId()) + else: + if target.getParentId() == 0: + core.simulationService.transferToPlanet(actor, core.terrainService.getPlanetById(target.getPlanetId()), target.getPosition(), target.getOrientation(), None) + else: + core.simulationService.transferToPlanet(actor, core.terrainService.getPlanetById(target.getPlanetId()), target.getPosition(), target.getOrientation(), core.objectService.getObject(target.getParentId())) + return + else: + actor.sendSystemMessage('Invalid Syntax. Syntax is: /teleportto ', 0) + return + return diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index 3939b461..dd1c6171 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -1150,6 +1150,14 @@ public class SimulationService implements INetworkDispatch { public void teleport(SWGObject obj, Point3D position, Quaternion orientation, long cellId) { + if (obj.getPosition().getDistance2D(position) > 150) { + if (cellId != 0) + transferToPlanet(obj, obj.getPlanet(), position, orientation, core.objectService.getObject(cellId)); + else + transferToPlanet(obj, obj.getPlanet(), position, orientation, null); + return; + } + if(cellId == 0) { if(position.x >= -8192 && position.x <= 8192 && position.z >= -8192 && position.z <= 8192) { obj.setMovementCounter(obj.getMovementCounter() + 1); @@ -1165,6 +1173,8 @@ public class SimulationService implements INetworkDispatch { obj.setPosition(position); obj.setOrientation(orientation); + + // Shouldn't the parent be set? } }