UE3 - UT3 [Armor] Doesn't count up when walking over a 2nd time

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

DannyMeister

UT3 Jailbreak Coder
Dec 11, 2002
1,275
1
38
40
Bolivar, Missouri
If you want to cap the armor at some value like 100, then you'll have to add a little code to deal with that. Hint: Min() could help you in AddShieldStrength(). Just think about the logic and math of it, and I'm sure you can come up with a solution!
 

Melvin

Next Gen
May 22, 2006
34
0
0
The Netherlands
Well, i'm very new to scripting.
So i really don't know where or what i need to look for to make that last thing work.
I tried looking at this site and at Unreal Wiki, but it did not find what i'm looking for.
 

DannyMeister

UT3 Jailbreak Coder
Dec 11, 2002
1,275
1
38
40
Bolivar, Missouri
The stock epic armor only needs one variable to keep track of... the ShieldAmount. This is how much is awarded, and it is the max. Your armor needs to keep track of two things, the ShieldAmount that is added each time, and a maximum amount to stop at. Declare something along the lines of var float MaxShieldAmount; at the top of your class, and set its value to 100 or whatever you like in the defaultproperties.

Now you have both pieces of information you need in the two functions you have overriden. Let's start with AddShieldStrength(). Right now you have it assigning the pawn's current armor plus ShieldAmount. That's fine when they don't have a lot of armor, but what about when they have 99 and they pick up 5 more... how much should you assign? Your MaxShieldAmount is 100, and your current armor + 5 is 104. You want the smaller one, 100. That is where the Min() function comes in handy. Min(100, 104) would return 100. So now your statement would look like:
Code:
P.ThighpadArmor = Min(MaxShieldAmount, P.ThighpadArmor + ShieldAmount);

Now think about CanUseShield(). It is supposed to return 0 if you can't pick it up, or some number greater than 0 that lets bots know how much armor they can gain by picking it up. So your job is to figure out how much more armor the player will be awarded... let's use the previous example of 99 armor. In this case we want the player to be awarded only 1 point of armor. You get that by subtracting 100-99, or in other words, MaxShieldAmount-P.ThighpadArmor. You can't always use that equation though, because if you currently had only 50 armor, that would give you 100-50 = 50 armor. You only need to use this subtraction when they are within 5 points of 100, (5=ShieldAmount). Any other time, you want to just return the full ShieldAmount. So one way could could accomplish this is with an if-statement like this:

Code:
function int CanUseShield(UTPawn P)
{
	if (MaxShieldAmount-P.ThighpadArmor < ShieldAmount)
	{
		return MaxShieldAmount-P.ThighpadArmor;
	}
	else
	{ 
		return ShieldAmount;
	}
}

I don't know what experience you have with if and else statements, but hopefully this makes sense and you have learned something :)