Tutorial: How to add new weapon, Thumper

Defender

Member
Had a player today wanting to know how to add a new weapon to the game, told him I would post a simple Tutorial, so here it is.. If I forgot something, please Devs, let me know...

---------------------------------------------------------------------------------------------------------------
Tutorial: Thumper
Game: Legions Overdrive
Author: Defender
Email: jackhemphill66@aol.com
Install Level: Easy
Files to Edit: 5
Last updated Mon Feb 3, 2014 8:34 pm
---------------------------------------------------------------------------------------------------------------

This tutorial makes a simple Thumper weapon, that fires two grenade projectiles each time the gun fires.
The projectiles have high areaImpulse, that knock players around.

To add new weapons, you will need to edit just a few .cs files.
I recommend you download notepad2 or notepad++, both work nicely for me and have line count.


Files To edit:

loadouts.cs
BasePlayer.cs
Sentinel.cs
Raider.cs
Outrider.cs

New file to add:

thumper.cs


File subfolder locations:

server\game\loadouts.cs
server\game\dataBlocks\preload\BasePlayer.cs
server\game\dataBlocks\players\
server\game\dataBlocks\weapons\
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------


Step #1


// ------------------------------------------
// loadouts.cs --- server\game\loadouts.cs
// ------------------------------------------


Go down to line 68, after
$LOWeapon[9] = "GrenadeLauncherHeavy";

Add
$LOWeapon[10] = "Thumper";

change and move RepairGun just below the new Thumper weapon
$LOWeapon[10] = "RepairGun";
To
$LOWeapon[11] = "RepairGun";


This is how it should look like below..


// These are the names of the datablocks
$LOArmor[0] = "OutriderPlayer";
$LOArmor[1] = "RaiderPlayer";
$LOArmor[2] = "SentinelPlayer";

$LOGrenade[0] = "BoostGrenade";
$LOGrenade[1] = "FragGrenade";
$LOGrenade[2] = "EmpGrenade";

$LOWeapon[0] = "Rifle";
$LOWeapon[1] = "Chaingun";
$LOWeapon[2] = "RocketLauncher";
$LOWeapon[3] = "MortarLauncher";
$LOWeapon[4] = "GrenadeLauncher";
$LOWeapon[5] = "Plasma";
$LOWeapon[6] = "Blaster";
$LOWeapon[7] = "SkyboltLauncher";
$LOWeapon[8] = "GrenadeLauncherSpecial";
$LOWeapon[9] = "GrenadeLauncherHeavy";
$LOWeapon[10] = "Thumper"; // Mod <=========================================
$LOWeapon[11] = "RepairGun";



---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

Step #2


// ------------------------------------------
// BasePlayer.cs --- server\game\dataBlocks\preload\BasePlayer.cs
// ------------------------------------------


If you want all players to use the new weapon, just add to BasePlayer.cs
After the GrenadeLauncher, about line 37 in BasePlayer.cs add.....

maxInventory[GrenadeLauncher] = 1;
maxInventory[GrenadeLauncherAmmo] = 16;

// ADD
maxInventory[Thumper] = 1;
maxInventory[ThumperAmmo] = 16;




If you don"t want all players to use the new gun,
Edit Sentinel.cs Raider.cs Outrider.cs in server\game\dataBlocks\players\
Set to 0, for each of the armors you don"t want using the new weapon.

maxInventory[Thumper] = 0;
maxInventory[ThumperAmmo] = 0;



---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

Step #3

// ------------------------------------------
// weapons folder --- server\game\dataBlocks\weapons\
// ------------------------------------------


1# Make a Copy the grenadeLauncher.cs, then past it back in to the weapons folder..
2# Rename the file to Thumper.cs
3# Copy all the code in the next post below, in to the new Thumper.cs, and click save.

Start your game up and host a game, if your new gun is in the game and working everything must have went ok.
 
Last edited:

Defender

Member
Code:
//-----------------------------------------------------------------------------
// Fallen Empire: Legions
// Copyright (C) GarageGames.com, Inc.
// Weapon: Thumper
//-----------------------------------------------------------------------------
// Projectile for the Thumper.
datablock LinearProjectileData(ThumperProjectile)
{
  projectileShapeName = "legions/data/shapes/weapons/plasma/plasmaball.dts";
  hasTracer = false;
  tracerWidth = 0.8;
  tracerLength = 5;
  tracerMaterialName = SkyboltTrailMaterial0;
  tracerOffset = 0.0;
  tracerGrowthScale = 0.01;
//motionTrail = plasmaTrail;
//emitter = plasmaTrailEmitter;
  // damage
  directDamage = 7.0;
  radiusDamage = 12.0;
  innerDamageRadius = 2;
  damageRadius = 16;
  areaImpulse = 5200;
  areaImpulseSelf = 4500;   
  scale = "0.50 0.50 0.50";
  damageType = $DamageType::GrenadeLauncherProjectile;
  explosionDamageType = $DamageType::GrenadeLauncherExplosion;
  explosionMidair = "ClusterBombExplosionMidair";
  explosionTerrain = "ClusterBombExplosionTerrain";
  explosionObject = "ClusterBombExplosionObject";
  emitter = ArmedClusterTrailEmitter; // links to particle emitter in effects directory, smoke trail
  // velocity
  Propelled = true;  // can't go slower than muzzle velocity
  MuzzleVelocity = 205;
  forwardVelInheritFactor = 1.0; // was 1.0
  sideVelInheritFactor = 0; //0.25;
  // timing
  armingDelay = 25;
  lifetime = 3000;
  // physics
  mass = 0.05;
  damageMaskRadius = 5.0;
  distortionRadius = 4.0;
  //decalTexture = "ExplosionDecal";
  //decalSize = 5.0;
  deleteOnExplode = true;
  doDistanceFade = true;
  startFadeDistance = 200;
  endFadeDistance = 800;
};
new ScriptObject(ThumperIcon)
{
  class = IconInfo;
  name = Thumper;
  containerIcon = "client/gui/images/hud/weaponIcons/chainGun";
  ammoIcon = "client/gui/images/hud/weaponIcons/chainGunAmmo";
};
new ScriptObject(ThumperReticle)
{
  class = ReticleInfo;
  name = Thumper;
  image = "client/gui/images/hud/reticles/PlasmaReticle01";
  frames = "2 1";
  showOverheatBar = false;
  normalFrame = 0;
  overheatFrame = 0;
};
datablock ItemData(Thumper)
{
  class = Weapon;
  image = ThumperImage;
  iconInfo = ThumperIcon;
  reticleInfo = ThumperReticle;
  longName = "Thumper";
  shortName = "Thump";
Description = "Speed:210  ForwardInheritance:100%  DirectDamage:5  SplashDamage:12  DamageRadius:15m";
};
datablock ItemData(ThumperAmmo)
{
  class = Ammo;
  item = Thumper;
};
// gun image
datablock ShapeBaseImageData(ThumperImage)
{
  canLockOn = false;
  lockAcquisitionTime = 3;
  class = WeaponImage;
  item = Thumper;
  ammo = ThumperAmmo;
  projectile = ThumperProjectile;
  projectileType = LinearProjectile;
  shapeFile = "legions/data/shapes/weapons/plasma/plasmaGun.dts";
  emap = true;
  burstCount = 1;
  burstDelay = 120;
  mountPoint = $WeaponSlot;
  firstPerson = true;
  eyeOffset = "0.65 0.25 -0.45";
  correctMuzzleVector = true;
//overheatTemperature = 225; //45;
  minProjectileSpread = 0; //0.0008;
  maxProjectileSpread = 0; //0.02;
  //usesEnergy = true;
  //minEnergy = 0.0;
  // Check ammo, do appropriate activate animation
  stateName[0] = "PreActivate";
  stateTransitionOnAmmo[0] = "Activate";
  stateTransitionOnNoAmmo[0] = "ActivateNoAmmo";
  stateName[1] = "Activate";
  stateSequence[1] = "activate";
  stateTransitionOnTimeout[1] = "Ready";
  stateTimeoutValue[1] = 0.5;
  stateName[2] = "ActivateNoAmmo";
  stateSequence[2] = "activatenoammo";
  stateTransitionOnTimeout[2] = "NoAmmo";
  stateTimeoutValue[2] = 0.5;
  stateName[3] = "Ready";
  stateScript[3] = "onReady";
  stateWaitForTimeout[3] = false;
  stateSequence[3] = "ready";
  stateTransitionOnTriggerDown[3] = "Fire";
  stateTransitionOnNoAmmo[3] = "NoAmmo";
  stateName[4] = "Fire";
  stateTimeoutValue[4] = 0.3; //was 0.4;
  stateTransitionOnTimeout[4] = "CheckAmmo";
  stateSequence[4] = "fire";
  stateFire[4] = true;
  stateAllowImageChange[4] = false;
  stateFullSound[4] = "";// RocketLauncherFireSound;
  stateScript[4] = "onFire";
  stateName[5] = "CheckAmmo";
  stateTransitionOnAmmo[5] = "Reload";
  stateTransitionOnNoAmmo[5] = "NoAmmoStart";
  stateAllowImageChange[5] = false;
  stateName[6] = "Reload";
  stateScript[6] = "onReload";
  stateSequence[6] = "reload";
  stateSequenceStartPosition[6] = 0.0;
  stateSequenceEndPosition[6] = 0.4;
  stateTransitionOnTimeout[6] = "Reloaded";
  stateTimeoutValue[6] = 0.33; //was 0.7;
  stateAllowImageChange[6] = false;
  stateFullSound[6] = RocketLauncherReloadSound;
  stateName[7] = "Reloaded";
  stateSequence[7] = "reload";
  stateSequenceStartPosition[7] = 0.4;
  stateSequenceEndPosition[7] = 1.0;
  stateTransitionOnTimeout[7] = "Ready";
  stateTimeoutValue[7] = 0.5;
  stateName[8] = "NoAmmoStart";
  stateSequence[8] = "noammostart";
  stateTransitionOnTimeout[8] = "NoAmmo";
  stateTimeoutValue[8] = 2.0;
  stateWaitForTimeout[8] = false;
  stateTransitionOnTriggerDown[8] = "DryFire";
  stateTransitionOnAmmo[8] = "Reload";
  stateName[9] = "NoAmmo";
  stateSequence[9] = "noammo";
  stateTransitionOnTriggerDown[9] = "DryFire";
  stateTransitionOnAmmo[9] = "Reload";
  stateName[10] = "DryFire";
  stateTimeoutValue[10] = 0.4;
  stateWaitForTimeout[10] = true;
  stateTransitionOnTimeout[10] = "CheckAmmo";
  stateSequence[10] = "dryfire";
  stateFullSound[10] = RocketLauncherDryFireSound;
};
function ThumperImage::onFire(%this, %obj, %slot){
%obj.decInventory(%this.ammo,1);
ThumperFire(%this, %obj, %slot);
schedule(150, 0, ThumperFire, %this, %obj, %slot);
}
function ThumperFire(%this, %obj, %slot)
{
  if (!isObject(%obj))
      return;
  if (%obj.getClassName() $= "Player")
      Game.cancelInvincibility(%obj);
  if (%this.overheatTemperature)
      %spreadPercent = %obj.getImageTemperature(%slot) / %this.overheatTemperature;
  else
      %spreadPercent = 0;
  %spread = (%spreadPercent * (%this.maxProjectileSpread-%this.minProjectileSpread)) + %this.minProjectileSpread;
  %spawnCount = (%this.spawnCount < 1) ? 1 : %this.spawnCount;
  for (%i = 0; %i < %spawnCount; %i++){
      %muzzleVector = %obj.getMuzzleVector(%slot);
      if (%spread != 0){
        %rotation = mDegToRad(%spread) * (getRandom()-0.5)
            SPC mDegToRad(%spread) * (getRandom()-0.5)
            SPC mDegToRad(%spread) * (getRandom()-0.5);
        %matrix = MatrixCreateFromEuler(%rotation);
        %muzzleVector = MatrixMulVector(%matrix, %muzzleVector);
      }
  %projectile = %this.projectile;
  %objectVelocity = %obj.getVelocity();
  %muzzleVelocity = %projectile.muzzleVelocity;
  // get forward velocity
  %forwardSpeed = VectorDot(%muzzleVector, %objectVelocity) * %projectile.forwardVelInheritFactor;
  if (%forwardSpeed < 0)
      %forwardSpeed = 0;
  %sideVec = VectorScale(
                    VectorSub(%objectVelocity, VectorScale(%muzzleVector, %forwardSpeed)),
                    %projectile.sideVelInheritFactor);
  %muzzleVelocity = VectorAdd(VectorScale(%muzzleVector, %muzzleVelocity + %forwardSpeed), %sideVec);
  %p = new (%this.projectileType)()
  {
      datablock = %projectile;
      initialVelocity = %muzzleVelocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject = %obj;
      sourcePlayer = %obj.client;
      sourceSlot = %slot;
      playerStats = %obj.stats;
      client = %obj.client;
      stats = %obj.stats.getWeaponStats(%projectile.damageType);
    };
  if(%obj.turType $= ""){
  %obj.stats.getWeaponStats(%projectile.damageType).incrementStat("shotsFired");
  }
  if (%this.projectileType $= GrenadeProjectile)
      %p.setArmed(false);
  %obj.firedProjectile = %p;
  MissionCleanup.add(%p);
  }
  serverPlay3D(GrenadeLauncherFireSound, %obj.getTransform());
}
 

Defender

Member
I prefer to use a dedicated_server.bat to test the game files first, and make sure all your edited files create DSO's..
Make a text file and name it Dedicated_Server.bat, make sure file type is .bat not .text
Copy this code below and past it in to the new Dedicated_Server.bat, file.
Place this new Dedicated_Server.bat, game folder where the Legions.exe, is located..
Click on it to start a dedicated server, check all files you edited, see if dso's are created, if not, you have syntax error,
Look in black server screen or check the game logs folder and read err logs..

Good Luck!!!

Code:
@echo off

REM #######################################################
REM 1/3/13
REM Legions Overdrive dedicated server loader
REM This batch file MUST be run from the game directory
REM #######################################################

for /R %%a IN (*.cs) do IF EXIST "%%a.dso" del "%%a.dso"
for /R %%a IN (*.cs) do IF EXIST "%%a.edso" del "%%a.edso"
for /R %%a IN (*.gui) do IF EXIST "%%a.dso" del "%%a.dso"
for /R %%a IN (*.gui) do IF EXIST "%%a.edso" del "%%a.edso"
for /R %%a IN (*.ts) do IF EXIST "%%a.dso" del "%%a.dso"
for /R %%a IN (*.ts) do IF EXIST "%%a.edso" del "%%a.edso"
start Legions.exe -dedicated -mod-list=ModList_Server.txt -server-config=config.cs
exit
 

Defender

Member
Worked for me :D, nice tut
This game makes it so easy to add a new weapon.:)
Tribes2, was a nightmare to add a new weapon, You had to edit about 6-9 files if I remember correctly, and in those you had to add each weapon in several areas and functions.
After modding in about 40 weapons in my War2003 mod, for tribes2, I was an expert at it...



Code:
//--------------------------------------------------------------------------
// Inv Weapon
//--------------------------------------

$InvWeapon[0] = "Blaster";
$NameToInv["Blaster"] = "Blaster";
//
$InvWeapon[1] = "Plasma Rifle";
$NameToInv["Plasma Rifle"] = "Plasma";
//
$InvWeapon[2] = "Chaingun";
$NameToInv["Chaingun"] = "Chaingun";
//
$InvWeapon[3] = "Spinfusor";
$NameToInv["Spinfusor"] = "Disc";
//
$InvWeapon[4] = "Grenade Launcher";
$NameToInv["Grenade Launcher"] = "GrenadeLauncher";
//
$InvWeapon[5] = "Laser Rifle";
$NameToInv["Laser Rifle"] = "SniperRifle";
//
$InvWeapon[6] = "ELF Projector";
$NameToInv["ELF Projector"] = "ELFGun";
//
$InvWeapon[7] = "Fusion Mortar";
$NameToInv["Fusion Mortar"] = "Mortar";
//
$InvWeapon[8] = "Missile Launcher";
$NameToInv["Missile Launcher"] = "MissileLauncher";
//
$InvWeapon[9] = "Shocklance";
$NameToInv["Shocklance"] = "ShockLance";
//
$InvWeapon[10] = "Targeting Laser";
$NameToInv["Targeting Laser"] = "TargetingLaser";
//
$InvWeapon[11] = "Heavy Missle Cannon";
//$NameToInv["Heavy Missle Cannon"] = "mechMaxGun";
//
$InvWeapon[12] = "PC Phaser Rifle";
$NameToInv["PC Phaser Rifle"] = "PCRifle";
//
$InvWeapon[13] = "Mitzi Blast Cannon";
$NameToInv["Mitzi Blast Cannon"] = "MBCannon";
//
$InvWeapon[14] = "Tether Missile Launcher";
$NameToInv["Tether Missile Launcher"] = "RocketLauncher";
//
$InvWeapon[15] = "PBW";
$NameToInv["PBW"] = "PBW";
//
$InvWeapon[16] = "Railgun";
$NameToInv["Railgun"] = "NRailgun";
//
$InvWeapon[17] = "Mech X4 Phaser";
$NameToInv["Mech X4 Phaser"] = "TriPhaserGun";
//
$InvWeapon[18] = "Reaver";
$NameToInv["Reaver"] = "MechReaver";
//
$InvWeapon[19] = "Starburst Cannon";
$NameToInv["Starburst Cannon"] = "Starburst";
//
$InvWeapon[20] = "Mech Rocket Launcher";
$NameToInv["Mech Rocket Launcher"] = "MechRocketGun";
//
$InvWeapon[21] = "Multi PBW";
$NameToInv["Multi PBW"] = "Multifusor";
//
$InvWeapon[22] = "Run!! Cannon";
$NameToInv["Run!! Cannon"]    = "RunGun";
//
$InvWeapon[23] = "Raptor Chaingun";
$NameToInv["Raptor Chaingun"] = "Raptor";
//
$InvWeapon[24] = "Shotgun";
$NameToInv["Shotgun"]    = "Shotgun";
//
$InvWeapon[25] = "Tanker Cannon";
$NameToInv["Tanker Cannon"] = "TCannon";
//
$InvWeapon[26] = "Particle Rifle";
$NameToInv["Particle Rifle"] = "PRailgun";
//
$InvWeapon[27] = "Defenders RunGun";
$NameToInv["Defenders RunGun"] = "mechRunminigun";
//
$InvWeapon[28] = "Warp Gun";
$NameToInv["Warp Gun"]    = "WarpGun";
//
$InvWeapon[29] = "HB_Blaster";
$NameToInv["HB_Blaster"] = "MechHBLAS";
//
$InvWeapon[30] = "Photon Swarmer Cannon";
//$NameToInv["Photon Swarmer Cannon"] = "IonCannon";
//
$InvWeapon[31] = "Nuke Cannon";
if ($War2002::UseNukes)
{
$NameToInv["Nuke Cannon"] = "NukeCannon";
}
//  Mechanized
$InvWeapon[32] = "Plasma Mechanized";
$NameToInv["Plasma Mechanized"] = "TLASgun";

$InvWeapon[33] = "Destroyer Cannon Mechanized";
$NameToInv["Destroyer Cannon Mechanized"] = "DestroyerGun";

$InvWeapon[34] = "Gattling PBW Mechanized";
$NameToInv["Gattling PBW Mechanized"] = "LASERgun";

$InvWeapon[35] = "Chainguns Mechanized";
$NameToInv["Chainguns Mechanized"] = "MechanizedC";

$InvWeapon[36] = "Locking Missle Mechanized";
$NameToInv["Locking Missle Mechanized"] = "MechMissler";
// Tools
$InvWeapon[37] = "Tools- Hack Gun";
$NameToInv["Tools- Hack Gun"] = "HackGun";
//
$InvWeapon[38] = "Tools- Dis Gun";
$NameToInv["Tools- Dis Gun"] = "DisGun";
//
$InvWeapon[39] = "Tools- Repair Gun";
$NameToInv["Tools- Repair Gun"] = "RepairRifle";
//

//
$InvWeapon[40] = "Flame Thrower";
$NameToInv["Flame Thrower"] = "Flamer";
//
 
Top