tModLoader Charging function freezes the player's animation. [SOLVED]

JakubDuC

Terrarian
Hello,
Let's cut staight to the chase. I tried coding a charge function with the help of the ExampleResourcePlayer timer, however it either freezes the player's animation and basically makes the player invincible as well. I tried to fix it, however it kept doing the same thing or just threw back 'Object refrence not set to an instance'. (Note: This is only increasing a value that is being shown to the player via text. For a while I thought that it was something to do with the text, because it didn't update, but I don't think that's the case) It's 1.4 by the way.
Here's my code:
public class Charging : ModPlayer
{
public bool IsCharging;
public int ChargeTimer = 0;
public int ChargeRate = 1;
CustomPlayerMod cplm = new CustomPlayerMod();
TheManaUI ui = new TheManaUI();




private void UpdateResource() // Updates mana method
{
if (IsCharging == true)
{
ChargeTimer++;
// Increase it by 60 per second, or 1 per tick.

// A simple timer that goes up to 3 seconds, increases the exampleResourceCurrent by 1 and then resets back to 0.
if (ChargeTimer > 15)
{
cplm.ElementalManaRadiant += 1 * cplm.ChargeMultiuplier;

ChargeTimer = 0;

}
}

}



public override void PostUpdateMiscEffects()
{
UpdateResource();
}


public override void ProcessTriggers(TriggersSet triggersSet)
{

if (KeybindSystem.ChargeKeybind.JustPressed)
{

IsCharging = true;
}
if (KeybindSystem.ChargeKeybind.JustReleased)
{
IsCharging = false;

}
}
}

}
This code should in theory work, but I sort of have a weird history with Update() functions. They never work. Thanks for reading this!
 
Last edited:
Back
Top Bottom