Ammo station code?

Defender

Member
I would like my ammo stations in my mod to work like those in tribes2.
Players can get a new armor, weapon, core, just by using the station.
This code works but some times the player coil skin, electric skin, effects get messed up..
I just can't seem to find the issue in my code below, if there are any Devs, around that understand how this could work, please help...




Code:
// not working right....


function Player::equipLoadout( %this, %loadout )
{
  %client = %this.client;
  %curArmor = %this.getDatablock();
  %curWeapon = %this.getMountedImage(0).item;
  %damagePercent = %this.getDamagePercent();

  Game.awardLifetime(%this); 

  %loadout = %client.selectedLoadout;
  %newDb = (%loadout.dataBlock !$= %curArmor.getName());

  %this.setDatablock(%loadout.dataBlock);
  %this.spawnTime = getSimTime()/1000;
  %this.stats = %this.team.stats.getPlayerStats(%client).getArmorStats(%loadout.dataBlock);

  %name = %client.playerInfo.name;

  if (%newDb){
      %this.pickRandomSkin();
      }

  %this.setDamageLevel(%this.getDataBlock().maxDamage * %damagePercent);
  %this.setEnergyLevel(%this.getDataBlock().maxEnergy);
  %this.setRechargeRate(%this.getDataBlock().rechargeRate);
  %this.setGroundRechargeRate(%this.getDataBlock().groundRechargeRate);

  // make sure these settings are the same as the armor data in players folder, and preload.
  if(%this.dataBlock $= "OutriderPlayer"){
        %this.sethorizResistFactor(0.3);
        %this.sethorizResistSpeed(100);
        %this.setupResistFactor(0.3);
        %this.setupResistSpeed(85);
        %this.setdrag(0.004);
        %this.setmass(75);
        %this.setrunForce(10000);
        %this.setrunSurfaceAngle(50);
        }
    if(%this.dataBlock $= "RaiderPlayer"){
        %this.sethorizResistFactor(0.3);
        %this.sethorizResistSpeed(100);
        %this.setupResistFactor(0.3);
        %this.setupResistSpeed(85);
        %this.setdrag(0.004);
        %this.setmass(95);
        %this.setrunForce(10000);
        %this.setrunSurfaceAngle(50);
        }
    if(%this.dataBlock $= "SentinelPlayer"){
        %this.sethorizResistFactor(0.3);
        %this.sethorizResistSpeed(100);
        %this.setupResistFactor(0.3);
        %this.setupResistSpeed(85);
        %this.setdrag(0.004);
        %this.setmass(180);
        %this.setrunForce(10000);
        %this.setrunSurfaceAngle(50);
        }

  %flags = %this.getInventory(Flag);
  %this.clearLoadout();

  %weaponCount = %loadout.weaponCount;
  %weaponString = "";
  for (%i = 0; %i < %weaponCount; %i++)
  {
      %this.setInventory(%loadout.weapon[%i], 1);
      %weaponString = %weaponString @ ((%i) ? " " : "") @ %loadout.weapon[%i];
  }

  // Fill up the core hud progress bar
  //ores::sendHUDUpdate(%this.client, true);
  %this.inTimeOut = false;
  %this.grenade = %loadout.grenade;
  %this.core = %loadout.core;
  if(isObject(%this.coreData))
      %this.coreData.delete();
 
  %this.coreData = new ScriptObject();
  %this.setCoreIsActivated(false);
  %this.warpCoreDisabledByIOD = false;
  %this.core.onEquip(%this);

/*
  %special = "";
  switch$ (%loadout.core.longname) {
      case "Overdrive":
        %this.setInventory(OverdriveCore, 1);
        %this.mountImage(OverdriveCoreImage, $CoreSlot);
        %this.setSelectedCore($Cores::OverdriveCore);
        if(%this.getDataBlock().maxDamage == 200) // <--- Aaaahahaha! What the hell :D
            %special = "Sentinel";
        commandToClient(%client,'EnableEngyPassive',false);
      case "Regeneration":
        %this.setInventory(RegenerationCore, 1);
        %this.mountImage(RegenerationCoreImage, $CoreSlot);
        %this.setSelectedCore($Cores::RegenerationCore);
        %this.setCoreCooldownTime($Cores::RegenerationCooldownTime);
        commandToClient(%client,'EnableEngyPassive',false);
      case "Warp":
        %this.setInventory(WarpCore, 1);
        %this.mountImage(WarpCoreImage, $CoreSlot);
        %this.setSelectedCore($Cores::WarpCore);
        %this.setWarpCoreTimeAmount($Cores::WarpTimeAmount);
        %this.setCoreCooldownTime($Cores::WarpCooldownTime);
        commandToClient(%client,'EnableEngyPassive',false);
      case "Shield":
        %this.setInventory(ShieldCore, 1);
        %this.setSelectedCore($Cores::ShieldCore);
        %this.mountImage(ShieldCoreImage, $CoreSlot);
        %this.setShieldCoreRadius($Cores::ShieldRadius);
        commandToClient(%client,'EnableEngyPassive',false);
        switch$(%this.getDataBlock().playerClass) {
            case $Player::Outrider:
              %this.setShieldCorePassiveDrain($Cores::ShieldDrainOutrider);
              %this.data["Shield","Power"] = $Cores::ShieldPowerOutrider;
            case $Player::Raider:
              %this.setShieldCorePassiveDrain($Cores::ShieldDrainRaider);
              %this.data["Shield","Power"] = $Cores::ShieldPowerRaider;
            case $Player::Sentinel:
              %this.setShieldCorePassiveDrain($Cores::ShieldDrainSentinel);
              %this.data["Shield","Power"] = $Cores::ShieldPowerSentinel;
      }
      case "Boost":
        %this.setInventory(BoostCore, 1);
        %this.setSelectedCore($Cores::BoostCore);
        %this.setCoreCooldownTime($Cores::BoostCooldownTime);
        %this.mountImage(BoostCoreImage, $CoreSlot);
        commandToClient(%client,'EnableEngyPassive',false);
      case "Dodge":
        %this.setInventory(DodgeCore, 1);
        %this.setSelectedCore($Cores::DodgeCore);
        %this.setCoreCooldownTime($Cores::DodgeCooldownTime);
        %this.mountImage(DodgeCoreImage, $CoreSlot);
        commandToClient(%client,'EnableEngyPassive',false);
        %special = $Cores::DodgeCost;
      case "Engineer":
        %this.setInventory(EngineerCore, 1);
        %this.setSelectedCore($Cores::EngineerCore);
        %this.setCoreCooldownTime(0);
        %this.mountImage(EngineerCoreImage, $CoreSlot);
        commandToClient(%client,'EnableEngyPassive',true);
        updateEngyGUI(%this);
        //Deployables::UpdatePlayerList(%client);
      }
  */
  //commandToClient(%client,'SelectCore',%loadout.core.longname,%special);

  %client.oldCore = %this.client.newCore;
  %client.newCore = %loadout.core.longname;

  if(%this.client.oldCore $= "Engineer" && %this.client.newCore !$= "Engineer")
      Deployables::killOwnedDeployables(%this.client);

  // This is to prevent a spawned player from being able to open up the loadout gui,
  // select the ovdrive core (while using a different core), and then actually be
  // able to use it (since overdrive is activated directy from the client scripts).
/*
  if(%this.core.longname !$= "Overdrive") {
      %this.setOverdriveAllowed(false);
  } else {
      %this.setOverdriveAllowed(true);
  }
*/
  if (%this.hasInventory(%curWeapon))
      %this.use(%curWeapon);
  else
      %this.use(%this.weapon[0]);

  %pack = %loadout.pack;
  if (%pack !$= "")
      %this.setInventory(%pack, 1);
 
  %this.client.setVisibleItems(%loadout.grenade);
  %this.client.setVisibleWeapons(%weaponString);

  %this.setInventory(Flag, %flags);
  %loadout.onEquip(%this);
}
 
Last edited:

Defender

Member
Basically, player skins on the back end and trails some times get messed up..
Try it out, replace your function Player::equipLoadout, in server\game\player.cs

I have been messing with trying to get the ammo station to function like ones in tribes2, or tribes, ever since I started modding legions. I had them working like tribes early on, but had a player ghosting bug, then a later update changed the whole function.

I dislike the current system, needing to respawn to change weapons, armors, cores, kinda blows. I already made simple code along time ago to make ammo station triggers team only if within a small radius of a teams flag stand and basically the main base area if the search distance is set to 100 or a little bit larger..
 
Last edited by a moderator:

WildFire

Warrior of Linux
I think greaper wrote some code with loadouts and ammo stations once upon a time... But that was before the skin selection system implementation.
 

Dabbleh

Legions Developer
Basically, player skins on the back end and trails some times get messed up..
Try it out, replace your function Player::equipLoadout, in server\game\player.cs

I have been messing with trying to get the ammo station to function like ones tribes2, or tribes, ever since I started modding legions. I had them working like tribes early on, but had a player ghosting bug, then a later update changed the whole function.

I dislike the current system, needing to respawn to change weapons, armors, cores, kinda blows. I already made simple code along time ago to make ammo station triggers team only if within a small radius of a teams flag stand and basically the main base area if the search distance is set to 100 or a little bit larger..
Ahaa, I would imagine there is some very inflexible coding around re-spawning to do with resetting a lot of stuff. (at a guess)
 

RockeyRex

Legions Developer
Code:
$Host::AmmoChangeLoadout = 1;

And comment out (or remove) the following from the original server/game/player.cs
Code:
  if (%this.loadout $= %loadout)
  {
      %this.refillAmmo();
      return;
  }

And do nothing else.
 

Defender

Member
I remember trying that before, and just tested this again, still the ammo station just reloads ammo, no new items or armors are purchased.
 

Defender

Member
No its not assigned in the map or any place, I just made the changes to Player::equipLoadout, was thinking this would make all ammo stations in the game, give players new loadouts when selected, including armors.
 

RockeyRex

Legions Developer
You wish that all ammo stations change loadouts for everyone no matter what the team? Well... sure... Not sure why you'd like that mess but...

server/game/weapons.cs change the following function to this.
Code:
function AmmoRefillStationTrigger::onEnterTrigger( %this, %trigger, %obj )
{
  if (%obj.getClassName() $= "Player")
  {
      if ($Host::AmmoChangeLoadout)
        %obj.equipLoadout();
      else
        %obj.refillAmmo();

      ServerPlay3D(PlayerReloadSound, %obj.getTransform());
  }
}

This in addition to the stuff earlier.
 

Fixious

Test Lead
  • Combo-boost to enemy base as Outrider
  • Visit ammo station
  • Switch to Sentinel

IWv2afK.png
 

Defender

Member
No, I am going to have the ammo stations team only, in the trigger code, I will do a team flagstand search, then set the triggers team to that flags team.
Did this for my team only inventory stations in my old mod..


This is my older code for that.
To use, the flagstand datablock will need a class name added...


Code:
datablock StaticShapeData(FlagGoal)
{
  shapeFile = "legions/data/shapes/props/flag/cappointbase.dts";

  doDistanceFade = true;
  startFadeDistance = 400;
  endFadeDistance = 400;

  useTeamSkin = true;
  skinMaterial0 = "CapPointDiffuseSkin";
  //===========================================================================
  // Classic Mod ///////////////////////////////////////////////////////////
  //===========================================================================
  // added by Defender
  dynamicType = $TypeMasks::ItemObjectType;
  classname = FlagGoal;
};

datablock StaticShapeData(FlagGoalClamps)
{
  shapeFile = "legions/data/shapes/props/flag/cappointclamps.dts";

  doDistanceFade = true;
  startFadeDistance = 400;
  endFadeDistance = 400;

  useTeamSkin = true;
  skinMaterial0 = "CapPointDiffuseSkin";
  //===========================================================================
  // Classic Mod ///////////////////////////////////////////////////////////
  //===========================================================================
  // added by Defender
  dynamicType = $TypeMasks::ItemObjectType;
  classname = FlagGoal;
};




Code:
function AmmoRefillStationTrigger::onEnterTrigger( %this, %trigger, %obj )  
{
  if (%obj.getClassName() $= "Player")
  {
  $NoFlagInRange = true;
  %flagDistance = 400;
  %position = %trigger.getTransform();
  InitContainerRadiusSearch(%position, %flagDistance, $TypeMasks::ItemObjectType);
  while( (%targetObject = containerSearchNext()) != 0 ){
  if( %targetObject.getDataBlock().classname $= "FlagGoal" ){  // added to commonObjects.cs
  %trigger.teamIndex = %targetObject.teamIndex;
  $NoFlagInRange = false;
  }else{
  $NoFlagInRange = true;
  }
  }
  %obj.teamIndex = %obj.client.teamIndex;
  %client = %obj.client;
  if (%obj.getClassName() $= "Player")
  if (%obj.teamIndex == %trigger.teamIndex){
  bottomPrintClient(%client, '\c0Inventory refill complete.');
  //%obj.equipLoadout();
  %obj.refillAmmo();
  ServerPlay3D(PlayerReloadSound, %obj.getTransform());
  }
  else if($NoFlagInRange) //out of flag range, let everyone use it.
  {
  %obj.refillAmmo();
  bottomPrintClient(%client, '\c0Ammo refill complete.');
  ServerPlay3D(PlayerReloadSound, %obj.getTransform());
  }else{
  bottomPrintClient(%client, '\c0Access Denied -- Wrong team.');
  }
  }
}
 
Last edited:

Defender

Member
You wish that all ammo stations change loadouts for everyone no matter what the team? Well... sure... Not sure why you'd like that mess but...

server/game/weapons.cs change the following function to this.
Code:
function AmmoRefillStationTrigger::onEnterTrigger( %this, %trigger, %obj )
{
  if (%obj.getClassName() $= "Player")
  {
      if ($Host::AmmoChangeLoadout)
        %obj.equipLoadout();
      else
        %obj.refillAmmo();

      ServerPlay3D(PlayerReloadSound, %obj.getTransform());
  }
}

This in addition to the stuff earlier.



I just tested this, the player coil skin, electric skin, effects get messed up..
Same problem I had in my function posted at the top of this topic.
Also if i switch from light armor to heavy, the heavy will seem to use mass setting for the light, lol... I will post some pictures in the morning...

To fix that i had to add this to my first function in this topic..
This is ripped from the dodge core...

Code:
// make sure these settings are the same as the armor data in players folder, and preload.
  if(%this.dataBlock $= "OutriderPlayer"){
        %this.sethorizResistFactor(0.3);
        %this.sethorizResistSpeed(100);
        %this.setupResistFactor(0.3);
        %this.setupResistSpeed(85);
        %this.setdrag(0.004);
        %this.setmass(75);
        %this.setrunForce(10000);
        %this.setrunSurfaceAngle(50);
        }
    if(%this.dataBlock $= "RaiderPlayer"){
        %this.sethorizResistFactor(0.3);
        %this.sethorizResistSpeed(100);
        %this.setupResistFactor(0.3);
        %this.setupResistSpeed(85);
        %this.setdrag(0.004);
        %this.setmass(95);
        %this.setrunForce(10000);
        %this.setrunSurfaceAngle(50);
        }
    if(%this.dataBlock $= "SentinelPlayer"){
        %this.sethorizResistFactor(0.3);
        %this.sethorizResistSpeed(100);
        %this.setupResistFactor(0.3);
        %this.setupResistSpeed(85);
        %this.setdrag(0.004);
        %this.setmass(180);
        %this.setrunForce(10000);
        %this.setrunSurfaceAngle(50);
        }

  %flags = %this.getInventory(Flag);
  %this.clearLoadout();

  %weaponCount = %loadout.weaponCount;
  %weaponString = "";
  for (%i = 0; %i < %weaponCount; %i++)
  {
      %this.setInventory(%loadout.weapon[%i], 1);
      %weaponString = %weaponString @ ((%i) ? " " : "") @ %loadout.weapon[%i];
  }
 
Last edited:

RockeyRex

Legions Developer
I just tested this, the player coil skin, electric skin, effects get messed up..
Same problem I had in my function posted at the top of this topic.
Not happening to me on a clean install. It's something you do somewhere else then.


Anyways as of the physics issue... Yeah that's there.
 

Defender

Member
Thanks for testing that.
Guess its my Scaling onAdd, thats doing it..
Besides that, I just did a clean install too..

Code:
function SentinelPlayer::onAdd(%data, %obj)
{
Parent::onAdd(%data, %obj);
// width  // thickness // hight
%scale = "1.50 1.50 1.50";
%obj.setScale(%scale);
}
 

Defender

Member
My scaling of the armors, was not the issue, removed it permanently, besides that nothing else should effect it..
On player respawn the coil skin, electric skin, effects issue is not there.
Only after using the Player::equipLoadout, with the basic changes you suggested..
No big deal, I kinda like the yellow looking blank skins on the back, not a big trade off for having tribes like inventorys;)
 
Top