• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Weapon adding stats to player

K

Kaji_Ikaraseru

Guest
This is probably an easy fix but I can't figure out how to do it. I have a stats object for my character, and when the weapon sprite is sprite_sword_3 I want it to add stats to the player.
Code:
if instance_exists(obj_player){
    if obj_player.weapon_sprite == spr_sword_3 {
        maxhp += 1;
        maxstamina += 10;
        maxmana += 2;
        attack += 1
    }
}
The problem is that since the sprite is there the whole time I have it equipped, it adds the stats, meaning maxhp will continue increasing by one the whole time. How can I make it so that it only adds once and when I take it off it reduces the stats?
 
A

Aura

Guest
I'd personally use a variable which when set to true increases the stats and is immediately set to false.

Code:
if (can_increase) {
   //Increase stats
   can_increase = false;
}
When you decrease the stats, do the opposite.

Code:
if (!can_increase) {
   //Decrease stats
   can_increase = true;
}
 
K

Kaji_Ikaraseru

Guest
I'd personally use a variable which when set to true increases the stats and is immediately set to false.

Code:
if (can_increase) {
   //Increase stats
   can_increase = false;
}
When you decrease the stats, do the opposite.

Code:
if (!can_increase) {
   //Decrease stats
   can_increase = true;
}
But if I am setting can increase to false after I add stats, and stats decrease when can increase is false, it would just keep looping back and forth?
 
K

Kaji_Ikaraseru

Guest
M

maderthanyou

Guest
var equip = 0
//weapon 3 is equiped
if obj_player.weapon_sprite == spr_sword_3 && equipped == false)
{
maxhp += 1;
maxstamina += 10;
maxmana += 2;
attack += 1
//third wepon
equip = 3
equipped = true
}
///weapon 3 is unequiped
else if ( equipped == false && equip == 3)
{
maxhp -= 1;
maxstamina -= 10;
maxmana -= 2;
attack -= 1

//no wepons
equip = 0
}

think that should do it
 
K

Kaji_Ikaraseru

Guest
t
var equip = 0
//weapon 3 is equiped
if obj_player.weapon_sprite == spr_sword_3 && equipped == false)
{
maxhp += 1;
maxstamina += 10;
maxmana += 2;
attack += 1
//third wepon
equip = 3
equipped = true
}
///weapon 3 is unequiped
else if ( equipped == false && equip == 3)
{
maxhp -= 1;
maxstamina -= 10;
maxmana -= 2;
attack -= 1

//no wepons
equip = 0
}

think that should do it
Thank you! :)
 
K

Kaji_Ikaraseru

Guest
var equip = 0
//weapon 3 is equiped
if obj_player.weapon_sprite == spr_sword_3 && equipped == false)
{
maxhp += 1;
maxstamina += 10;
maxmana += 2;
attack += 1
//third wepon
equip = 3
equipped = true
}
///weapon 3 is unequiped
else if ( equipped == false && equip == 3)
{
maxhp -= 1;
maxstamina -= 10;
maxmana -= 2;
attack -= 1

//no wepons
equip = 0
}

think that should do it
Nvm that didn't really do it, BUT I did find a working code thank to yours. No need for the equip variable.
Code:
if instance_exists(obj_player){
    if obj_player.weapon_sprite == spr_sword_3 && equip == 0 && equipped == false{
        maxhp += 1;
        maxstamina += 10;
        maxmana += 2;
        attack += 1
       
        equipped = true;
       
    }
   
    else if ( obj_player.weapon_sprite != spr_sword_3 && equipped == true){
        maxhp -= 1;
        if hp > maxhp{
            hp = maxhp;
        }
        maxstamina -= 10;
        if stamina > maxstamina{
            stamina = maxstamina;
        }
        maxmana -= 2;
        if mana > maxmana {
            mana = maxmana;
        }
        attack -= 1
       
        equipped = false;
    }
}
Have to check that the sprite isn't equipped.
 

TheouAegis

Member
Why not just simplify everything and set the stats immediately when the sword is equipped and unset the stats when it is unequipped?

Make a set of variables to hold the boosts to each stat. So say you had

STR
MAG
AGI
CON
DEX
SPR
CHA

You'd make duplicate variables to hold the boosts.

STRboost
MAGboost
AGIboost
CONboost
DEXboost
SPRboost
CHAboost

Your formulas would then be stuff like

damage = (STR + STRboost) * 3 - (other.DEF + other.DEFboost) * 2;

When you equip the sword or whatever, you'd add to the -boost variable immediately. You can store all the boosts in an array and just use the array as a look-up table to keep your code clean and simple.
 
Top