- Home /
Character Attributes Question
Hello! So i've made the below script which shows the attributes of a character. What i basically wanna do is to increase the HealthPoints by 10 for every 2 Vitality points so it would be 50 HP for 10 Vitality. Like i did it with the "for" function it is 100 HP. Of course, the other thing i want is about the GUI Button. I want to have the HealthPoints increased by 10 but again for every 2 Vitality Points so it would be for 12 points you get +10 Health and so on. Could you help me a bit? Thanks!
var STRENGTH : int;
var DEXTERITY : int;
var INTELLIGENCE : int;
var VITALITY : int;
var HEALTHPOINTS : int;
function Awake(){
STRENGTH = 12;
DEXTERITY = 9;
INTELLIGENCE = 8;
VITALITY = 10;
}
function Start(){
for(var i : int = 0; i < VITALITY; i++){
HEALTHPOINTS += 10;
}
}
function OnGUI(){
stat1 = "Strength : " + STRENGTH;
stat2 = "Dexterity : " + DEXTERITY;
stat3 = "Intelligence : " + INTELLIGENCE;
stat4 = "Vitality : " + VITALITY;
stat5 = "Health : " + HEALTHPOINTS;
GUI.Box(new Rect(20,20,100,70),stat1 + "\n" + stat2 + "\n" + stat3 + "\n" + stat4);
GUI.Box(new Rect(140,20,100,40),stat5);
if(GUI.Button(new Rect(20,100,40,20),"+")){
VITALITY += 1;
}
}
take vitality div 2, throw away remainder and multiply by 10
Would it be possible to change the code a bit and post it here? :P
I had it a little backwards in the first post anyway, you want to know if vitality has been increased by 2 and only then grant a new point in health is that right? so you want to do something like X % 2 and if the remainder IS zero, then it's gone up by 2
Oh never$$anonymous$$d sir i actually did it. Thanks a lot! But what about the other thing with the button? Hmm..
Answer by HappyMoo · Jan 26, 2014 at 04:40 AM
Hi,
you need to change your design, so the rules can be evaluated every time something changes.
var baseSTR : int;
var baseDEX : int;
var baseINT : int;
var baseVIT : int;
var baseHP : int;
var baseMP : int;
var STRENGTH : int;
var DEXTERITY : int;
var INTELLIGENCE : int;
var VITALITY : int;
var HEALTHPOINTS : int;
var MANAPOINTS : int;
function Awake(){
baseSTR = 12;
baseDEX = 9;
baseINT = 8;
baseVIT = 10;
baseHP = 5;
baseMP = 0;
recalculateStats();
}
function recalculateStats()
{
STRENGTH = baseSTR;
DEXTERITY = baseDEX;
INTELLIGENCE = baseINT;
VITALITY = baseVIT;
..
// check for stats in/decreasers here, e.g.:
//if (WearsRingOfDexPlusTwo) DEXTERITY = DEXTERITY + 2;
..
HEALTHPOINTS = baseHP + 10*(VITALITY/2);
MANAPOINTS = baseMP + 10*(INTELLIGENCE/2);
}
function OnGUI(){
stat1 = "Strength : " + STRENGTH;
stat2 = "Dexterity : " + DEXTERITY;
stat3 = "Intelligence : " + INTELLIGENCE;
stat4 = "Vitality : " + VITALITY;
stat5 = "Health : " + HEALTHPOINTS;
GUI.Box(new Rect(20,20,100,70),stat1 + "\n" + stat2 + "\n" + stat3 + "\n" + stat4);
GUI.Box(new Rect(140,20,100,40),stat5);
if(GUI.Button(new Rect(20,100,40,20),"+")){
baseVIT += 1;
recalculateStats();
}
}
WoW! That's a really nice system you posted there! :O Thanks a lot! I tried that out but for some reason when i press the + button nothing happens...I'm thinking about it right now.
Oh wait, yes... actually pressing a button doesn't fit into the system, because it's not some kind of powerup... just to see that it's working, change the base when you click. I'm changing the code above
Yeah i experimented a bit with it myself and figured it out XD Thanks a lot! Obviously, if i want to do something similar with the rest of the stats, i'll do it like this right? I also have one more question. Would it be possible to make HealthPoints increase randomly? Sometimes 10 or 7 or 9 or whatever. To have a bigger variety and not just be 55,65,75 etc.
Usually you handle something like this in the base values
baseVIT = Random.Range(8,13);
These can also be different depending on race etc...