How to make Teleporting and Jumping Units

This is one of the more advanced tutorials I have written, as it requires the use several more INI files than usual, and I don’t explain every little detail because you can learn this stuff from previous tutorials.

Concept:  The basic concept is that you want a unit to go from one place to another, without actually going in-between and dealing with all those cliffs and water and enemies.  So instead of having the unit go there, you make the unit shoot at the location you want it to go, have the bullet spawn a new unit, and once the new unit is created, have the old one die.  So what the end user see is his unit being told to target a location and then instantly teleporting to that location.

The way I have devised it is you have your basic unit, which you should know how to code.  The unit needs two special things however, a teleporting weapon and a corresponding CommandSet.  Lets start by using a normal weapon and adding to this unit as it’s secondary or tertiary weapon.  It needs a tag below it that designates when this weapon can be fired automatically.  So you need this:      
Code:
AutoChooseSources    = SECONDARY NONE
This is will prevent your unit from ‘accidentally’ firing the teleportation weapon whenever it sees an enemy.  Now, since the weapon is never automatically fired, you must make it explicit when it fires, so you’ll need a command button for this.  I like to think of modding as being derivates of things already working, so for the next example I will show you similar code that is already in the game.  This is jarmen kell’s weapon to snipe vehicle pilots.

Code:
CommandButton Command_GLAInfantryJarmenKellSnipeVehicleAttack
  Command                 = FIRE_WEAPON
  WeaponSlot              = SECONDARY
  Options                 = OK_FOR_MULTI_SELECT NEED_TARGET_ENEMY_OBJECT CONTEXTMODE_COMMAND
  Upgrade                 = None
  TextLabel               = CONTROLBAR:SniperAttack
  ButtonImage             = SSSniperAttack
  CursorName              = SnipeVehicle
  InvalidCursorName       = GenericInvalid
  ButtonBorderType        = ACTION ; Identifier for the User as to what kind of button this is
  DescriptLabel           = CONTROLBAR:ToolTipGLAFireJarmenKellVehicleSnipe
  UnitSpecificSound       = JarmenKellVoiceModeSnipe
End


This button cause Jarmen Kell to his secondary weapon when an enemy target is chosen, which is almost exactly like we want it, with the exception that instead of targeting an enemy unit, we would rather a location.  So in your own command button for this, substitute “NEED_TARGET_ENEMY_OBJECT” with “NEED_TARGET_POS”.  Add the button to your unit’s commandset and you should be good to test some stuff ingame.
At this point you will notice how your unit functions.  When you select him, hit his button, and target a location, he will fire his special weapon at the location, but never fire the weapon automatically at anything.  This might be useful for other things as there are several units who use this logic.
*You should also give your unit a fire pitch in it’s turret, or fake turret as in order to fire everywhere it needs to fire at an arc*
The next thing to do is actual code the teleportation weapon.  Generally speaking, you want your unit to be able to go anywhere on the map from anywhere, so it should have an extremely long range and the weapon speed should be very fast.  Your weapon absolutely must have a projectile object, however you might not want this to be seen ingame, so you could possibly make an invisible one.  Now this weapon has two parts.  1) Spawns the new unit 2) while the other parts kills the original unit.  Lets talk about Spawning the unit first.  There is a tag related to your projectile called “  ProjectileDetonationOCL =“.  This tag ties and OCL to your projectile so that when it hits, it will spawn a copy of your unit (so add the tag and make a corresponding OCL).  Your unit now is basically a self replicating machine that can spawn units anywhere!  However, we want a teleported, so in order to complete the desired effect, we need to kill off the initial unit.  So we need to use something else to kill off the unit for us.  There is another OCL that spawns things at the location of the unit, called FireOCL.  This is very useful because it allows us the create an object at the location of the unit that will kill the unit and itself.  The way I did it was the created object has a very short lifespan and has a death weapon, which has a small area of effect, and does high damage, thus killing the unit almost instantly.  So there you go, everything should be all set.

This is the weapon that most of the work for me btw
Code:
Weapon ChronoTankShiftGun
  PrimaryDamage = 1.0            
  PrimaryDamageRadius = 0.0
  AttackRange = 9999.0
  DamageType = EXPLOSION          ; ignored for projectile weapons
  DeathType = EXPLODED
  WeaponSpeed = 750               ; ignored for projectile weapons
  FireOCL = OCL_ChronoTankDeleter (This is the one I made)
  ProjectileObject = GC_Chem_StingerMissile (This is the one I made)
  DelayBetweenShots = 0
  ClipSize = 1
  ClipReloadTime = 60000
  AutoReloadsClip = Yes
  FireSound = StingerMissileWeapon
  ProjectileDetonationOCL = OCL_CreateChronoTank (This is the one I made)
  AntiAirborneVehicle = No
  AntiAirborneInfantry = No
  AntiGround = Yes
  ProjectileCollidesWith = NONE
End


Lets talk about jumpers.  Jumpers basically use the same logic as the above with the exception that you should probably limit their range and their projectile should be the model itself and not invisible.  Also, this they are jumping on things, it would make sense if it did a little damage, especially to infantry.