Creating a Teleporter
From Multiverse
| MARS |
| Mob Server |
| Object Manager |
| Combat Server |
|
Abilities and Combat Plugin • Combat Statistics • Extending the MARS Combat System • Group System • Trainer Plug-in • Professions • Experience System |
| Tutorials |
| Other Examples |
|
Triggering an Action with a Mouseclick • Scheduled Execution • Working with Sound • Creating a Teleporter |
A teleporter consists of two points: an origin and a destination point. When you move your avatar over the origin point, you are automatically and instantaneously transported to the destination point. The two points can be anywhere in a world.
Contents |
Procedure
Follow this general procedure to add a teleporter to your world. For an example, see Multiverse Fantasy World.
Add markers
First, using World Editor, add two markers to your world for the origin and destination points. In the example below, the marker at the origin point is called "origin_marker" and the marker at the destination point is called "dest_marker".
Generally, you will also want to place something that will be visible "in world" on or near the markers, such as a particle effect, a platform onto which avatars can move, or the like. Otherwise, the teleport point will be invisible.
Create teleporter template
Then, create a template for a teleporter in your world's templates.py script:
tmpl = Template("Teleporter")
tmpl.put(WorldManagerClient.NAMESPACE,
WorldManagerClient.TEMPL_DISPLAY_CONTEXT,
DisplayContext("tiny_cube.mesh"))
tmpl.put(WorldManagerClient.NAMESPACE,
WorldManagerClient.TEMPL_OBJECT_TYPE,
ObjectTypes.mob)
tmpl.put(WorldManagerClient.NAMESPACE,
WorldManagerClient.TEMPL_NAME,
"")
ObjectManagerClient.registerTemplate(tmpl)
Add teleporter code and attach to markers
Then, add the following code to your world's instance_load.py file:
tele1Loc = instance.getMarker("origin_marker").getPoint()
tele1Dest = instance.getMarker("dest_marker").getPoint()
spawnData = SpawnData()
spawnData.setFactoryName("Tele1Factory")
spawnData.setInstanceOid(Long(instanceOid))
spawnData.setLoc(tele1Loc)
spawnData.setNumSpawns(1)
spawnData.setSpawnRadius(0)
spawnData.setRespawnTime(1000)
spawnData.setCorpseDespawnTime(0)
MobManagerClient.createSpawnGenerator(spawnData)
Where "origin_marker" is the name of the origin marker, and "dest_marker" is the name of the destination marker.
Create spawn generator for teleporter
Add the following code to your world's mobserver.py file:
class Tele1Factory (ObjectFactory):
def makeObject(self, spawnData, instanceOid, loc):
# this binds the object
obj = ObjectFactory.makeObject(self, spawnData, instanceOid, loc)
tele1Dest = InstanceClient.getMarkerPoint(instanceOid, "dest_marker")
# add behavior
behav = TeleporterBehavior()
behav.setRadius(4000)
behav.setDestination(tele1Dest)
obj.addBehavior(behav)
return obj
ObjectFactory.register("Tele1Factory", Tele1Factory("Teleporter"))
Now, start your servers, and when you move over the tele1-origin marker, you will be instantly transported to the tele1-dest marker.
Notice the line
behav = TeleporterBehavior()
that uses the multiverse.mars.behaviors.TeleporterBehavior class.
Making a two-way teleporter
To make the teleporter two-way, add two more markers: "tele2-origin" near "tele1-dest" and "tele2-dest" near "tele1-origin". Then, add this code to mobserver.py.
behav.setRadius() is less than the distance between the two markers.
tele2Loc = instance.getMarker("tele2-origin").getPoint()
tele2Dest = instance.getMarker("tele2-dest").getPoint()
class Tele2Factory (ObjectFactory):
def makeObject(self, loc):
# this binds the object
obj = ObjectFactory.makeObject(self, loc)
# add behavior
behav = TeleporterBehavior()
behav.setRadius(2000)
behav.setDestination(tele2Dest)
obj.addBehavior(behav)
return obj
tele2Factory = Tele2Factory("Teleporter")
tele2SpawnGen = SpawnGenerator("teleporter")
tele2SpawnGen.setObjectFactory(tele2Factory)
tele2SpawnGen.setLoc(tele2Loc)
tele2SpawnGen.setNumSpawns(1)
tele2SpawnGen.setSpawnRadius(0)
tele2SpawnGen.setRespawnTime(1000)
tele2SpawnGen.setCorpseDespawnTime(0)
tele2SpawnGen.activate()
