mp cost with keys

danno

Moderator
Staff member
I'm trying to use the same freespecial multiple times (air combo) but using mp cost doesn't seem to work, heres how I have everything set up

player keys
Code:
void main()
{
    int iPlIndex = getlocalvar("player"); //Get calling player
    void vSelf = getplayerproperty(iPlIndex , "entity"); //Get calling entity
    void vAniID = getentityproperty(vSelf,"animationID"); //Get current animation ID
    void vAniPos = getentityproperty(vSelf, "animpos"); //Get current animation frame
    int iDir = getentityproperty(vSelf, "direction");  //Get current facing direction

    void iUp = playerkeys(iPlIndex, 1, "moveup"); // New key status of "Up"
    void iDown = playerkeys(iPlIndex, 1, "movedown"); // New key status of "Down"
    void iLeft = playerkeys(iPlIndex, 1, "moveleft"); // New key status of "Left"
    void iRight = playerkeys(iPlIndex, 1, "moveright"); // New key status of "Right"
    void iJump = playerkeys(iPlIndex, 1, "jump"); //New key status of "Jump"
    void iSpecial = playerkeys(iPlIndex, 1, "Special"); //New key status of "Special"
    void iAttack = playerkeys(iPlIndex, 1, "attack"); //New key status of "Attack"
    void iAttack2 = playerkeys(iPlIndex, 1, "attack2"); // New key of "Attack 2"
    void iAttack3 = playerkeys(iPlIndex, 1, "attack3"); // New key of "Attack 3"
    void iAttack4 = playerkeys(iPlIndex, 1, "attack4"); // New key of "Attack 4"

    void iLeftR = playerkeys(iPlIndex, 2, "moveleft"); // Release status of "Left"
    void iRightR = playerkeys(iPlIndex, 2, "moveright"); // Release status of "Right"
    void iDownR = playerkeys(iPlIndex, 2, "movedown"); //Release status of "Down"
    void iAttackR = playerkeys(iPlIndex, 2, "attack"); //Release status of "Attack"

    void iUpH = playerkeys(iPlIndex, 0, "moveup");
    void iLeftH = playerkeys(iPlIndex, 0, "moveleft");
    void iRightH = playerkeys(iPlIndex, 0, "moveright");

Code:
    if(vAniID == openborconstant("ANI_FREESPECIAL8") ){ //Jumping?
      if(iAttack2){ //ATT2?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL8"));

		}
	}
character freespecial
Code:
com  a2    FREESPECIAL8
Code:
anim  freespecial8
	jumpframe  0  1  0  0
        mponly   1
        mpcost 10
	offset  67  165
        DELAY 6
	frame  Data/chars/spiderman/awe1.png
		bbox  68  67  57  93
	@cmd	shooter2 "webh" 120 57 0 5
	frame  Data/chars/spiderman/awe2.png

video showing mpcost (blue bar under red bar at top of the screen)

https://www.youtube.com/watch?v=7469hFaNOkQ

tried using Illu's @cmd mp cost, the mp drains but the character can still perform the freespecial, also when mp finishes while standing it switches from ground freespecial to air freespecial

https://www.youtube.com/watch?v=8uK3bjnUabc

also tried copying freespecial 8 and changing it to follow x but same results

also tried keyint in anim jump with same results  :(
 
If you use script to perform FREESPECIAL in mid air, mpcost won't prevent you from reperforming that attack even though your MP is 0

IOW you need more script to prevent the animation, like this:
Code:
    void MP = getentityproperty(vSelf,"mp"); 

    if(vAniID == openborconstant("ANI_FREESPECIAL8") ){ //Jumping?
      if(iAttack2 && MP >= 10){ //ATT2 and enough MP?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL8"));
      }
    }

@cmd mp cost, the mp drains but the character can still perform the freespecial

mpcost function only drains MP but it won't stop entity from doing the animation. That's why I usually combine it with other function like this:
Code:
void aniLimit(void Ani, int Frame, int Limit)
{// Change current animation if MP falls below limit
    void self = getlocalvar("self");
    void MP = getentityproperty(self,"mp");    

    if (MP < Limit){
      changeentityproperty(self, "animation", openborconstant(Ani),2);
      updateframe(self, Frame);
    }
}

This is alternate of the modified script above. Main differences are:
1. MP limit in above script is hardcoded in the script while with aniLimit function, you can modify it in animation text
2. In above script, when MP is not enough, the animation is not performed at all. With aniLimit function, animation is still performed but immediately changed to other animation

Choose which method you like  :)
 
I like method 1 best but I must be doing something wrong because I can't get either to work
method 1 in entity's key script

Code:
    
void MP = getentityproperty(vSelf,"mp");

    if(vAniID == openborconstant("ANI_FREESPECIAL8") ){ //Jumping?
      if(iAttack2 && MP >= 10){ //ATT2 and enough MP?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL8"));
      }
    }   
    if(vAniID == openborconstant("ANI_FREESPECIAL8") ){ //Jumping?
      if(iAttack2){ //ATT2?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL8"));
		}
	}

method 2
player entity model

Code:
animationscript data/scripts/script.c
keyscript	data/chars/spiderman/peter.c

script c

Code:
void mpcost( int MCost)
{// Spend some MP
    void self = getlocalvar("self");
    void MPower = getentityproperty(self,"mp"); //get mp
    changeentityproperty(self, "mp", MPower-MCost);//consume mp
}

void aniLimit(void Ani, int Frame, int Limit)
{// Change current animation if MP falls below limit
    void self = getlocalvar("self");
    void MP = getentityproperty(self,"mp");   

    if (MP < Limit){
      changeentityproperty(self, "animation", openborconstant(Ani),2);
      updateframe(self, Frame);
    }
}

players animation data with @cmd mpcost

Code:
anim  freespecial8
	jumpframe  0  1  0  0
        @cmd mpcost  10
        mponly   1
	offset  67  165
        DELAY 6
	frame  Data/chars/spiderman/awe1.png
		bbox  68  67  57  93
	@cmd	shooter2 "webh" 120 57 0 5
	frame  Data/chars/spiderman/awe2.png

I prefer method 1 because using @cmd mpcost causes spiderman to switch freespecials with mp bar finishes like in the video but I can't get either to work  :o

 
About this:
Code:
void MP = getentityproperty(vSelf,"mp");

    if(vAniID == openborconstant("ANI_FREESPECIAL8") ){ //Jumping?
      if(iAttack2 && MP >= 10){ //ATT2 and enough MP?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL8"));
      }
    }   
    if(vAniID == openborconstant("ANI_FREESPECIAL8") ){ //Jumping?
      if(iAttack2){ //ATT2?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL8"));
		}
	}

You have two lines of code doing same thing, one with mp limit and one without. You should remove the last one and use only the first one

using @cmd mpcost causes spiderman to switch freespecials with mp bar finishes like in the video

That's strange cause mpcost function doesn't affect animation at all. OTOH aniLimit can change animation

Be right back

[One hour later]

okay, I'm back

Example of using aniLimit is like this:
Code:
anim  freespecial8
        delay	1
	offset	67  165
	jumpframe  1  1  0  0
	frame	data/chars/spiderman/awe1.png
        delay	6
	@cmd	aniLimit "ANI_FOLLOW2" 0 10
	frame	data/chars/spiderman/awe1.png
	bbox	68  67  57  93
        @cmd	mpcost  10
	@cmd	shooter2 "webh" 120 57 0 5
	frame	data/chars/spiderman/awe2.png

In this example, if spiderman's MP is below 10 when this animation is performed. aniLimit will change it into FOLLOW2

Since you prefer 1st method, try my suggestion above and see if it works :)
 
Method one still doesn't work Bloodbane, I sent you a link to what I'm working on so you can have a look at my obvious mistake
https://www.youtube.com/watch?v=L3zbLhEVyHA
I got method 2 working but still with the weird standing freespecial animation change using @cmd mp cost

I also wanted to ask about diagonal aim using keys, I found this by Damon but I have no idea how to fully implement it and I couldn't find any examples

#define KEY_MOVE_UP      openborconstant("FLAG_MOVEUP")
#define KEY_MOVE_RIGHT      openborconstant("FLAG_MOVERIGHT")

// Get current key press and any keys being held.
    key_hold        = getplayerproperty(player_index, "keys");
    key_press      = getplayerproperty(player_index, "newkeys");

// Holding up and right?
if(key_hold & KEY_MOVE_UP && key_hold & KEY_MOVE_RIGHT)
{
    //....do stuff...
}
 
I've checked the demo and found the problem

But before that, I'm surprised to see this:
Code:
com a2    FREESPECIAL5
com a2    FREESPECIAL6
com  a2    FREESPECIAL7
com  a2    FREESPECIAL8

This is clearly puzzling as it's not clear which freespecial you assign Attack2 to. I assume duplicate lines will be ignored and only last one will be taken but I could be wrong
Anyways, I decided to disable 3 lines leaving only the first one active to ensure which freespecial is performed

I've fixed spidey's keyscript and now it works as intended :)
Here's the fixed part (only the ones related to web shooting):
Code:
  if(vAniID == openborconstant("ANI_JUMP") ){ //Jumping?
      if(iAttack2 && MPower >= 10){ //web shoot?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_freespecial8"));

		}
	}
   

  if(vAniID == openborconstant("ANI_follow12") ){ //Jumping?
      if(iAttack2 && MPower >= 10){ //web shoot?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_freespecial8"));

		}
	}


   if(vAniID == openborconstant("ani_forwardjump") ){ //Jumping?
      if(iAttack2 && MPower >= 10){ //web shoot?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_freespecial8"));

		}
	}

There's also this line above to acquire MPower:
Code:
    int MPower = getentityproperty(vSelf,"mp");

As for spidey's stance after MP is not enough, that's simply because you've declared air web shooting frame in FOLLOW12, animation for MP not enough

I also wanted to ask about diagonal aim using keys,

I know how to implement diagonal shooting. I'll modify spidey's keyscript to show you how
But before that, does spidey have any sprite for shooting diagonally?
If not, I'll just use available sprites for shooting diagonally :)
 
Back
Top Bottom