Jump to content

Photo

Simple Item Script


  • Please log in to reply
16 replies to this topic

#1 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 August 2016 - 05:24 PM

I would like to request an item script which removes the item from the screen after a specified amount of time (D0). Thank you for any assistance. EDIT: If Link can't pick it up that's even better.


Edited by Cukeman, 04 August 2016 - 05:25 PM.


#2 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 04 August 2016 - 05:51 PM

So, you want it to find the screen's item, prevent it from being picked up immediately, wait D0 seconds, then destroy it?

Or find the item, wait D0 seconds, and then prevent it from being picked up?



#3 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 August 2016 - 06:36 PM

The plan is to have an enemy drop an item that disappears after the specified time (D0). I would prefer that Link is never able to pick it up, but if he does I can live with that.

 

EDIT: It's a dummy item- basically it's a way to see a special animation when an enemy dies

 

EDIT2: Oh wait, Item Scripts only run when you pick up an item or press its button, right? Hm.


Edited by Cukeman, 05 August 2016 - 12:09 AM.


#4 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 05 August 2016 - 07:47 AM

Yeah, you'll need a global/FFC script for that.

 

If you like, you could also use a Weapon/Misc sprite for that animation. A dummy item might accomplish the same thing, but a sprite feels more.... right.



#5 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 05 August 2016 - 12:23 PM

Yeah, a sprite would be fine.



#6 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 05 August 2016 - 05:01 PM

How many times is this enemy going to appear? Would you like a global script with a list of enemies to use the animation, or just an FFC script with enemy ID and sprite ID parameters?



#7 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 05 August 2016 - 06:08 PM

This enemy wouldn't appear on very many screens, but there could be a lot of them on one screen.

 

I don't think I have a real preference between Global and FFC... FFC might be easier??



#8 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 05 August 2016 - 06:53 PM

Try this on for size. Place one of these FFCs on each screen per type of enemy with unique death animations.

 

const int LW_DEATHANIM = 31;

const int HP_DEAD = 999; // Enemy HP will be set to this after death animation has been started

ffc script deathAnimations {
    void run(int enemyId, int spriteId) {
        while(true) {
            for(int i = 1; i <= Screen->NumNPCs(); i++) {
                npc enem = Screen->LoadNPC(i);
                if(enem->HP <= 0 && enem->HP > HP_DEAD && enem->Id == enemyId) {
                    lweapon anim = CreateLWeaponAt(LW_DEATHANIM, enem->X, enem->Y);
                    anim->UseSprite(spriteId);
                    anim->CollDetection = false;
                    
                    enem->HP = HP_DEAD;
                }
            }
            
            Waitframe();
        }
    }
}


#9 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 06 August 2016 - 04:10 PM

I changed the "Id"s to "ID" so it would compile:
 

const int LW_DEATHANIM = 31; // For DeathAnimations (FFC)
const int HP_DEAD = 999; // Enemy HP will be set to this after death animation has been started

ffc script DeathAnimations {
    void run(int enemyID, int spriteID) {
        while(true) {
            for(int i = 1; i <= Screen->NumNPCs(); i++) {
                npc enem = Screen->LoadNPC(i);
                if(enem->HP <= 0 && enem->HP > HP_DEAD && enem->ID == enemyID) {
                    lweapon anim = CreateLWeaponAt(LW_DEATHANIM, enem->X, enem->Y);
                    anim->UseSprite(spriteID);
                    anim->CollDetection = false;
                    
                    enem->HP = HP_DEAD;
                }
            }
            
            Waitframe();
        }
    }
}

When I tested it, I didn't see the sprite appear when I killed the enemy. At first I thought it might be because it was an enemy that splits on death, but then it didn't appear on a standard enemy either.



#10 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 06 August 2016 - 09:20 PM

if(enem->HP <= 0 && enem->HP > HP_DEAD && enem->ID == enemyID)
Probably because that condition is never true. HP can't be both less than zero and greater than 999. MoscowModder probably meant to make that number -999.
  • Cukeman likes this

#11 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 06 August 2016 - 11:03 PM

Thanks! The sprite appears now, but it remains onscreen instead of disappearing when the animation is complete



#12 idontknow8

idontknow8

    Senior

  • Members

Posted 06 August 2016 - 11:24 PM

Try this on for size. Place one of these FFCs on each screen per type of enemy with unique death animations.
 

const int LW_DEATHANIM = 31;

const int HP_DEAD = 999; // Enemy HP will be set to this after death animation has been started

ffc script deathAnimations {
    void run(int enemyId, int spriteId, int anim_length, int Invis_Sprite) {
        while(true) {
            for(int i = 1; i <= Screen->NumNPCs(); i++) {
                npc enem = Screen->LoadNPC(i);
                if(enem->HP <= 0 && enem->HP > HP_DEAD && enem->Id == enemyId) {
                    lweapon anim = CreateLWeaponAt(LW_DEATHANIM, enem->X, enem->Y);
                    anim->UseSprite(spriteId);
                    anim->CollDetection = false;
                    
                    enem->HP = HP_DEAD;
                    Waitframes(anim_length);
                    anim->UseSprite(Invis_Sprite);
                }
            }
            
            Waitframe();
        }
    }
}


Try this. What I've done is added a couple new arguments: anim_length and Invis_Sprite. anim_length should be the total time it takes the death animation Sprite to animate (one cycle before becoming invisible). This is basically A. Frames x A. Speed. Invis_Sprite should be set to a Sprite that has a completely transparent tile (which you may have to make a new Sprite for it & note the Sprite ID number.

What should happen is the script waits so many frames for the initial anim Sprite to finish animating and then shifts that Sprite to the new invisible one (perminently).

#13 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 07 August 2016 - 12:07 AM

Try this. What I've done is added a couple new arguments: anim_length and Invis_Sprite. anim_length should be the total time it takes the death animation Sprite to animate (one cycle before becoming invisible). This is basically A. Frames x A. Speed. Invis_Sprite should be set to a Sprite that has a completely transparent tile (which you may have to make a new Sprite for it & note the Sprite ID number.
What should happen is the script waits so many frames for the initial anim Sprite to finish animating and then shifts that Sprite to the new invisible one (perminently).

That'll have the same problem. Change HP_DEAD to HP_SILENT.

Is there more than one item that you'll be using as a fake drop? I don't comprehend the intended application of this, but it would also be possible to make the enemy drop the item via a dropset, then use an ffc to change its HitXOffset. That way, it'll vanish as a normal drop would.

Edited by ZoriaRPG, 07 August 2016 - 12:11 AM.


#14 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 07 August 2016 - 12:33 AM

Try this. What I've done is added a couple new arguments: anim_length and Invis_Sprite. anim_length should be the total time it takes the death animation Sprite to animate (one cycle before becoming invisible). This is basically A. Frames x A. Speed. Invis_Sprite should be set to a Sprite that has a completely transparent tile (which you may have to make a new Sprite for it & note the Sprite ID number.

What should happen is the script waits so many frames for the initial anim Sprite to finish animating and then shifts that Sprite to the new invisible one (perminently).

 

 

 

Thanks a lot, that worked! :) (I just had to change Id to ID again):

const int LW_DEATHANIM = 31; // For DeathAnimsTemp (FFC)
const int HP_DEAD = -999; // Enemy HP will be set to this after death animation has been started

ffc script DeathAnimsTemp {
    void run(int enemyID, int spriteID, int anim_length, int Invis_Sprite) {
        while(true) {
            for(int i = 1; i <= Screen->NumNPCs(); i++) {
                npc enem = Screen->LoadNPC(i);
                if(enem->HP <= 0 && enem->HP > HP_DEAD && enem->ID == enemyID) {
                    lweapon anim = CreateLWeaponAt(LW_DEATHANIM, enem->X, enem->Y);
                    anim->UseSprite(spriteID);
                    anim->CollDetection = false;
                    
                    enem->HP = HP_DEAD;
                    Waitframes(anim_length);
                    anim->UseSprite(Invis_Sprite);
                }
            }
            
            Waitframe();
        }
    }
}

That'll have the same problem. Change HP_DEAD to HP_SILENT.

Is there more than one item that you'll be using as a fake drop? I don't comprehend the intended application of this, but it would also be possible to make the enemy drop the item via a dropset, then use an ffc to change its HitXOffset. That way, it'll vanish as a normal drop would.

 

It's just a way to have an additional animated effect when certain enemies die.

 

   There's only one detail I forgot about. When I said there was only one enemy I wanted to apply this to, well... this is a multi-phase enemy, so technically it's more than one.

   Could this be edited so that, instead of one enemy specified in the argument, there is a list of enemies in the code itself?

   Sorry.

 

   One thing I noticed (which is interesting, but shouldn't be a problem to me) the sprite doesn't show up if the enemy is in the top row of the screen.


Edited by Cukeman, 07 August 2016 - 01:09 AM.


#15 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 16 August 2016 - 06:14 PM

Just how many phases are there? If you wanted, you could just create multiple instances of this FFC script, one for each phase. Otherwise..

 

const int LW_DEATHANIM = 31; // For deathAnimations (FFC)
const int HP_DEAD = -999; // Enemy HP will be set to this after death animation has been started
 
ffc script deathAnimationsList {
    void run(int spriteID, int anim_length, int Invis_Sprite) {
    
        // Put IDs here
        int ids[] = {1, 2, 3};
        int numIds = 3;
    
        while(true) {
            for(int i = 1; i <= Screen->NumNPCs(); i++) {
                npc enem = Screen->LoadNPC(i);
                for(int j = 0; j < numIds; j++) {
                    if(enem->HP <= 0 && enem->HP > HP_DEAD && enem->ID == ids[j]) {
                        lweapon anim = CreateLWeaponAt(LW_DEATHANIM, enem->X, enem->Y);
                        anim->UseSprite(spriteID);
                        anim->CollDetection = false;
                        
                        enem->HP = HP_DEAD;
                        Waitframes(anim_length);
                        anim->UseSprite(Invis_Sprite);
                    }
                }
            }
            
            Waitframe();
        }
    }
}

 

(Building off of idontknow's edit)


  • Cukeman likes this


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users