Setting Armor Max Energy?

Yes, I know how to do this in the datablock.

But I was wondering if I can set the maximum energy of a Specific Player at any time, I am going to use this for my 'Powers Mod'.

What I mean by this is that if there was some function that was like: %obj.setMaxEnergyLevel(blah);

Also in here, I was wondering if Max HP could be changed as well.

Comments

  • You could do this,
    function energy(%obj)
    {         
              %ocp = %obj.client.player;
              %Heat = %ocp.getHeat();
              %Dmg = %ocp.getDamageLevel();
              %Energy = %ocp.getEnergyLevel();
             
              if (%obj.client.player.getArmorSize() $= "Light")
                 {
                  %obj.setArmor("light");
                  %obj.setmaxEnergy(100);//original 60   
                  %obj.setmaxDamage(0.8);//original 0.66
    
              %ocp.setEnergyLevel(%Energy);
              %ocp.setDamageLevel(%Dmg);
              %ocp.setHeat(%Heat);
    
    }
    
    if you put that in a function, say in a pack, when that function is executed by the states it will target that specific player.
  • Wait, what? I don't remember there being a way to set Max Energy and Max Damage on a specific player. I just looked and didn't find a setmaxEnergy in the original code or in the executable.
  • .... wow
    I'm not even going to comment on the above function.

    I'm kind of scared this question even came up. But regardless, a rough way to do this:
    %obj.setEnergyLevel(%obj.getDatablock().maxEnergy);

    I suggest using the Function Library for more useful functions:
    http://www.tribesnext.com/forum/index.php?topic=854.0
  • No, please, tell me what i did wrong. I'm interested in learning what I do wrong, helps me. :P
  • You could do this,
    function energy(%obj)
    {         
              %ocp = %obj.client.player;
              %Heat = %ocp.getHeat();
              %Dmg = %ocp.getDamageLevel();
              %Energy = %ocp.getEnergyLevel();
             
              if (%obj.client.player.getArmorSize() $= "Light")
                 {
                  %obj.setArmor("light");
                  %obj.setmaxEnergy(100);//original 60   
                  %obj.setmaxDamage(0.8);//original 0.66
    
              %ocp.setEnergyLevel(%Energy);
              %ocp.setDamageLevel(%Dmg);
              %ocp.setHeat(%Heat);
    
    }
    
    if you put that in a function, say in a pack, when that function is executed by the states it will target that specific player.

    Well...

    You gave a function that restores a lot more than just energy, the function setMaxEnergy() doesn't exist, you're missing a closing brace, you referenced the same object indirectly (%obj is assumed to be the player, but could be any object, therefore if the object is a StaticShape, this call would fail as the StaticShape has no client member variable), the function is named energy (not maxEnergy or anything that hints at it's actual functionality, and this only works for light armors? Why? You even set the armor as "light", what function could that possibly have?

    A function that would do what he asked for would be:
    function setMaxEnergy(%obj)
    {
         %obj.setEnergyLevel(%obj.getDatablock().maxEnergy);
    }
    
  • Thanks for the comment back. The closing bracket missing was just an accident, but I don't really agree with "setmaxEnergy doesn't exist." In the energy pack there is
    %obj.setRechargeRate(%obj.getRechargeRate() + %data.rechargeRateBoost);
    
    which sets rechargeRate in player.cs to the original + the boost in the pack. So why would you not be able to do setMaxEnergy when its in the datablock as well?
    [code] maxEnergy = 60;
  • I'm amazed at how badly everyone except Red Shifter can read.

    There is no such functionality in the script system as is, but it would be fairly easy to add, if you're clever.
  • I am an exceptional reader, understanding what people can ask is quite a bit more difficult.

    Thought!: Powers Mod Eh? Well why not have the powers be weapons/packs that if you have a variable set by a chat command will choose in an onMount function what happens. Like when the energy pack is mounted it does
    setRechargeRate(%obj.getRechargeRate() + %data.rechargeRateBoost);
    
    why not change that to
    setJetEnergyDrain(%obj.getJetEnergyDrain - %data.newEnergy);//- so that it makes you use less
    
    That makes it so that a specific player with that 'power' uses less energy when jetting, instead of having more energy. And you could edit it, like the chat command could be
    function ccEnergies(%obj, %energy)
    {
           %obj.IHasSomeEnergies = %energy;
    } 
    
    and in the pack
    newEnergy = %obj.IHasSomeEnergies;
    
    So
    %data.newEnergy = %energy;
    
    Something like that I think, probably a wrong way to do it, but I'm out of my mind at this point in time.
  • I'm amazed at how badly everyone except Red Shifter can read.

    There is no such functionality in the script system as is, but it would be fairly easy to add, if you're clever.

    It's funny because it's true. Regardless, I will admit I didn't read the original post very well.
    So why would you not be able to do setMaxEnergy when its in the datablock as well?
    [code] maxEnergy = 60;
  • Yeah, that's the trivially easy way to do it, but it doesn't work well in multiplayer. You can add several sets of armor maximum health/energies by using a set of datablocks and switch between them to adjust player health/energy, but then you're restricted to the datablock set values that you've created.

    But, it's certainly possible to do what Phantom asked, independent of datablock manipulation. I'm just interested to see if he's clever enough to figure out how. I think it can be done in under 40 lines of code.
  • Yay! A challenge!!! Not directly to me, but I'll see if I can do it :D.
  • edited May 2009
    Yeah, that's the trivially easy way to do it, but it doesn't work well in multiplayer. You can add several sets of armor maximum health/energies by using a set of datablocks and switch between them to adjust player health/energy, but then you're restricted to the datablock set values that you've created.

    But, it's certainly possible to do what Phantom asked, independent of datablock manipulation. I'm just interested to see if he's clever enough to figure out how. I think it can be done in under 40 lines of code.

    40 lines, rofl.
    function DoPowersStuff(%client, %type) {
       if(%type $= "") {
          %type = 0;
       }
       if(!isObject(%client.player) || %client.player.getState() $= "dead") {
          return;
       }
       //first spawn of the player
       if(%type == 0) {
          %client.player.getDatablock().maxEnergy = (100 + ($PowerSave::Level[%client.guid] * 4));
          %client.player.setEnergyLevel(%client.player.getDatablock().maxEnergy);
          //
          %client.player.getDatablock().maxDamage = (1.5 + ($PowerSave::Level[%client.guid] / 10));
          %client.player.setDamageLevel(0);
       }
       else {
          %client.player.getDatablock().maxEnergy = (100 + ($PowerSave::Level[%client.guid] * 4));
          %client.player.getDatablock().maxDamage = (1.5 + ($PowerSave::Level[%client.guid] / 10));
       }
       if(%type != 0)
          schedule(200,0,"DoPowersStuff", %client, %type);
    //   echo("POWERS: E Set to "@%client.player.getDatablock().maxEnergy@".");
    }
    

    EDIT:
    Apparently this doesn't quite work.. Energy just resets after a few seconds, or use of it.
    I am an exceptional reader, understanding what people can ask is quite a bit more difficult.

    Thought!: Powers Mod Eh? Well why not have the powers be weapons/packs that if you have a variable set by a chat command will choose in an onMount function what happens. Like when the energy pack is mounted it does
    setRechargeRate(%obj.getRechargeRate() + %data.rechargeRateBoost);
    
    why not change that to
    setJetEnergyDrain(%obj.getJetEnergyDrain - %data.newEnergy);//- so that it makes you use less
    
    That makes it so that a specific player with that 'power' uses less energy when jetting, instead of having more energy. And you could edit it, like the chat command could be
    function ccEnergies(%obj, %energy)
    {
           %obj.IHasSomeEnergies = %energy;
    } 
    
    and in the pack
    newEnergy = %obj.IHasSomeEnergies;
    
    So
    %data.newEnergy = %energy;
    
    Something like that I think, probably a wrong way to do it, but I'm out of my mind at this point in time.

    What happens when I use a weapon that takes up 90 energy (Shadow Bomb Power)?

    It takes 90 energy no matter what, so changing the jet energy drain is pointless to me.
  • Yes, under 40 lines where it can be used universally, without modifying any other scripts in your mod (i.e. weapons, etc.).
  • edited May 2009
    Yes, under 40 lines where it can be used universally, without modifying any other scripts in your mod (i.e. weapons, etc.).

    Doing it without usage of getDatablock() seems hard to do, if not impossible. Maybe I should have a peek at the RPG mod's mana system, because the mana system is pretty much what I am trying to accomplish, only, doing it differently.

    Edit:
    I'm wondering, when I do figure this out, will the energy bar be modified to fit the new energy level, or just reach max (100 for my armor), while the energy continues to rise to the new maximum?

    Edit 2:
    I've rebuilt the RPG mod's Mana system, all credit to the RPG mod if you use this.

    However I wouldn't know why you would want to use it, it still doesn't quite work yet. It properly takes energy as if you had the new max. But it still doesn't set it properly to the new maximum (Goes to 100, and stays there).
    //used in multiple functions
    //Credit to the RPG mod for these.
    function FetchMaxEnergy(%client) {
       %max = (100 + ($PowerSave::Level[%client.guid] * 4));
       return %max;
    }
    
    function DoPowersStuff(%client, %setStat) {
        if(!isObject(%client.player) || %client.player.getState() $= "dead") {
           return;
        }
       	%armor = %client.player.getDataBlock();
        
        if(%setStat $= "")
           %setStat = FetchMaxEnergy(%client);
        
    	%max = %setStat * %armor.maxEnergy;
    	%set = %max / FetchMaxEnergy(%client);
     
        //Can we use this E-Level?
    	if(%set < 0)
    		%set = 0;
    	else if(%set > %armor.maxEnergy)
    		%set = %armor.maxEnergy;
    
    	%client.player.setEnergyLevel(%set);
    }
    
    //remember, powers goes over max energy
    function FetchPowersEnergyLevel(%client) {
       %armor = %client.player.getDataBlock();
    
       %get = %client.player.getEnergyLevel() * FetchMaxEnergy(%client);
       %final = %get / %armor.maxEnergy;
       
       return %final;
    }
    
    function TakeEnergy(%client, %varible) {
       DoPowersStuff(%client, (FetchPowersEnergyLevel(%client) - %varible));
    }
    
  • Why not set the maxEnergy in the dataBlocks for each armor to a large sum like instead of 110 for heavies 250 and just have a couple of functions make the the players energy level never get over a certain amount for that level? Plus you can set it so if that amount = whatever that level has you could use the energy packs setRechargeRate(getRechargeRate() + rechargeRateBoost); but instead use setRechargeRate(getRechargeRate() - %rechargeRate); where %rechargeRate = %obj.datablock().rechargerate;

    Basically large max energies that stop at a level specified place with the recharge rate taken away when its reached.

    :P
  • Still, I like thyth's general concept of staying away from further datablock usage.

    So, I will still work on getting it to work that way.
Sign In or Register to comment.