Jump to content

Photo

magic bar

magic bar skyrim

  • Please log in to reply
8 replies to this topic

#1 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 22 February 2015 - 04:57 PM

yo!

I tried to make a magic bar like that one of Skyrim, but I don't know how to inform the script to the magic bar refills 1 block every 2 seconds and 5 seconds after Link stop using the magic weapon.

 

Here is the script and the test file:

global script Slot2
{
    void run(){
        while (true){

            if(Link->MP < Link->MaxMP){

                for(int i = 0; i < Link->MaxMP; i++){
                    Link->MP++;
                    Game->PlaySound(SFX_REFILL);
                }
                Waitframes(300);
            }

            Waitframe();
        }
    }
}

 

https://dl.dropboxus...2/magic bar.rar

 



#2 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 22 February 2015 - 05:05 PM

If you want to have it wait until after using magic, move the Waitframes(300) to above the for() loop.

 

If you want to have it refill gradually, make sure you have a Waitframes() inside the for() loop, not (just) after it.



#3 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 23 February 2015 - 10:38 AM

MoscowModder, it's working now, but I found a weird conflict with another script: a script that creates untouchable enemies (I use it for butterflies, chickens and dogs). So, when the magic bar script is used, while the bar isn't full, the enemies stop being untouchable.

 

Here the updated test file and the script:

https://dl.dropboxus...2/magic bar.rar

global script Slot2
{
    void run(){
        while (true){
        
            Enemies();                                    // Zero Damage Enemies
        
            // ............................................................................    
        
            if(Link->MP < Link->MaxMP){
                Waitframes(120);

                for(int i = 0; i < Link->MaxMP; i++){
                    Waitframes(4);
                    Link->MP++;
                }
            }

            
            
            Waitframe();
        }
    }
}

// .........................................................................................

bool isZeroDamage(npc enemy){
    if(enemy->HP == 32767) return true;
}


void Enemies(){
    npc enemy;

    for(int n=1;n<=Screen->NumNPCs();n++){
    enemy = Screen->LoadNPC(n);

        if(isZeroDamage(enemy)){
        enemy->CollDetection = false;
        }
    }
}

Edited by accela2me, 23 February 2015 - 10:39 AM.


#4 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 23 February 2015 - 10:53 AM

That's because you've got a Waitframes() inside your for() loop. I didn't mention it earlier because I assumed that was your only global script, but that will halt your entire global script whenever you reach it.

 

To fix this, put only a single Waitframe() at the end of your while(true) loop.

 

Then, add a counter to the script that increments while you need to recharge magic, and refills your magic every time counter % 200 == 0.



#5 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 23 February 2015 - 03:26 PM

Nothing. Sorry, dude, I don't know how to write the counter... something like this?

Game->Counter[CR_MAGIC] %200 == 0



#6 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 23 February 2015 - 05:17 PM

No, not a game counter. Your own, arbitrary counter.

counter = (counter + 1) % 120;

Put that in your while loop (needs to be declared as an int first obviously). Then, instead of using Waitframes, you check to see if this counter is 0. This one resets to 0 every 120 frames, but you can use whatever number you like.



#7 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 24 February 2015 - 04:26 PM

Something is still wrong...

 

global script Slot2
{
    void run(){
    
    int counter = 0;
    
        while (true){
        
            Enemies();                                    // Zero Damage Enemies

            counter = (counter + 1) % 120;    
        
            if(Link->MP < Link->MaxMP){
                
                for(int i = 0; i < Link->MaxMP; i++){
                    Link->MP++;
                }
            }            
            
            Waitframe();
        }
    }
}


#8 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 24 February 2015 - 04:47 PM

You're not using the counter for anything. By "check", I meant to explicitly use an if statement to check if it's equal to 0.

if (counter == 0)

That for loop is also still wrong. It will always run for as much max MP as Link has, regardless of how much he's missing. It also all runs in one frame, and I think you wanted the MP refill to be gradual?

global script Slot2
{
    void run(){
    
    int counter = 0;
    int tempMP = Link->MP;
    int magic_cooldown;
    
        while (true){
        
            Enemies();                                    // Zero Damage Enemies

            counter = (counter + 1) % 120;    
        
            if(counter == 0 && magic_cooldown == 0 && Link->MP < Link->MaxMP){
                Link->MP++;
            }            
            
            if (Link->MP < tempMP){
                magic_cooldown = 300;
            }

            if (magic_cooldown > 0){
                magic_cooldown--;
			}
 
			tempMP = Link->MP;
 
			Waitframe();
		}
	}
} 

This will give Link 1 MP every 2 seconds. There's 32 MP per magic container, so unless you've adjusted the MP cost for all the items in your quest similarly you'll want to notch those numbers up. I also added in the cooldown timer you were talking about, which will activate whenever Link uses MP for any reason. If you want to go through the tedium of adding an action script to every magic item, you could make the cooldown timer a global variable and have individualized timers for every item.


Edited by Lejes, 24 February 2015 - 04:52 PM.


#9 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 24 February 2015 - 07:18 PM

Thanks a lot, Lejes! The script is working perfectly now!

 

Here the updated test file:
https://dl.dropboxus...2/magic bar.rar





Also tagged with one or more of these keywords: magic, bar, skyrim

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users