Jump to content

Photo

Anti-Fairy Enemy Request / Fix


  • Please log in to reply
7 replies to this topic

#1 Tabletpillow

Tabletpillow

    Hi

  • Members
  • Real Name:Xavier
  • Location:Oregon

Posted 04 November 2017 - 04:31 PM

The enemy that only moves diagonally and bumps on solid objects.

I have the Autoghost code (I got it from the forums) It works, but not in rooms that have corner edges. The Anti-Fairy enemy gets stuck on them.

 

If you can fix it, or have a better anti-fairy script, please tell me. Thanks in advance!

ffc script AntiFairy
{
void run(int enemyID)
{
npc ghost = Ghost_InitAutoGhost(this, enemyID);
 
if (Rand(1, 2) == 1)
{
Ghost_Vx = ghost->Step * 0.01;
}
else
{
Ghost_Vx = -1 * ghost->Step * 0.01;
}
 
if (Rand(1, 2) == 1)
{
Ghost_Vy = ghost->Step * 0.01;
}
else
{
Ghost_Vy = -1 * ghost->Step * 0.01;
}
 
while (true)
{
// Change X velocity when bouncing on vertical surface.
if (Screen->isSolid(Ghost_X - 2, Ghost_Y + 8) || Ghost_X - 2 <= 0)
{
Ghost_Vx = ghost->Step * 0.01;
}
if (Screen->isSolid(Ghost_X + 18, Ghost_Y + 8) || Ghost_X + 18 >= 255)
{
Ghost_Vx = -1 * ghost->Step * 0.01;
}
 
// Change Y velocity when bouncing on horizontal surface.
if (Screen->isSolid(Ghost_X + 8, Ghost_Y - 2) || Ghost_Y -2 <= 0)
{
Ghost_Vy = ghost->Step * 0.01;
}
if (Screen->isSolid(Ghost_X + 8, Ghost_Y + 18) || Ghost_Y + 18 >= 175)
{
Ghost_Vy = -1 * ghost->Step * 0.01;
}
 
Ghost_Waitframe(this, ghost, true, true);
}
}
}

Edited by a30502355, 04 November 2017 - 04:32 PM.


#2 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 04 November 2017 - 09:11 PM

I made one of these. I was sure it was in the database, but it doesn't seem to be.
 
// import "std.zh"
// import "string.zh"
// import "ghost.zh"

// npc->Attributes[] indices
const int WB_ATTR_TILE_WIDTH = 2;
const int WB_ATTR_TILE_HEIGHT = 3;
const int WB_ATTR_IGNORE_WATER = 4;
const int WB_ATTR_IGNORE_PITS = 5;

ffc script WallBouncer
{
    void run(int enemyID)
    {
        npc ghost;
        int flags;
        int angle;
        float step;
        float xStep;
        float yStep;
        
        // Initialize
        ghost=Ghost_InitAutoGhost(this, enemyID, GHF_NO_FALL);
        Ghost_TileWidth=Ghost_GetAttribute(ghost, WB_ATTR_TILE_WIDTH, 1, 1, 4);
        Ghost_TileHeight=Ghost_GetAttribute(ghost, WB_ATTR_TILE_HEIGHT, 1, 1, 4);
        Ghost_SpawnAnimationPuff(this, ghost);
        
        // Set flags
        flags=GHF_STUN|GHF_CLOCK;
        if(ghost->Attributes[WB_ATTR_IGNORE_WATER]>0)
            flags|=GHF_IGNORE_WATER;
        if(ghost->Attributes[WB_ATTR_IGNORE_PITS]>0)
            flags|=GHF_IGNORE_PITS;
        Ghost_SetFlags(flags);
        
        // Get initial movement
        angle=45+90*Rand(4);
        step=ghost->Step/100;
        ghost->Step=0; // In case it's a walker
        
        xStep=step*Cos(angle);
        yStep=step*Sin(angle);
        
        while(true)
        {
            // Bounce
            if(xStep<0)
            {
                if(!Ghost_CanMove(DIR_LEFT, -xStep, 3))
                   xStep*=-1;
            }
            else
            {
                if(!Ghost_CanMove(DIR_RIGHT, xStep, 3))
                   xStep*=-1;
            }
            
            if(yStep<0)
            {
                if(!Ghost_CanMove(DIR_UP, -yStep, 3))
                   yStep*=-1;
            }
            else
            {
                if(!Ghost_CanMove(DIR_DOWN, yStep, 3))
                   yStep*=-1;
            }
            
            // And move
            Ghost_MoveXY(xStep, yStep, 3);
            Ghost_Waitframe(this, ghost, true, true);
        }
    }
}
This will work with walking enemies so you can use their touch effects. Other attributes won't work normally.

Attribute 3 (Death Attr. 1): Tile width (1-4, default 1)
Attribute 4 (Death Attr. 2): Tile Height (1-4, default 1)
Attribute 5 (Death Attr. 3): Move over water (0: no, 1: yes)
Attribute 6 (Extra Shots): Move over direct warps (0: no, 1: yes)
  • Tabletpillow likes this

#3 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 05 November 2017 - 02:24 PM

Seems like something's wrong with your script saffith. It doesn't run at all.

 

Edit: Setting attribute 11 from 0 to -1 fixed it xd


Edited by Avataro, 05 November 2017 - 04:08 PM.


#4 judasrising

judasrising

    I play guitar

  • Members
  • Location:Sweden but born in Finland

Posted 05 November 2017 - 02:57 PM

Seems like something's wrong with your script saffith. It doesn't run at all.

This works

 

-----------------------------------------------------------------------------------------------------

// import "std.zh"
// import "string.zh"
// import "ghost.zh"
 
// npc->Attributes[] indices
const int WB_ATTR_TILE_WIDTH = 2;
const int WB_ATTR_TILE_HEIGHT = 3;
const int WB_ATTR_IGNORE_WATER = 4;
const int WB_ATTR_IGNORE_PITS = 5;
 
ffc script WallBouncer
{
    void run(int enemyID)
    {
        npc ghost;
        int flags;
        int angle;
        float step;
        float xStep;
        float yStep;
        
        // Initialize
        ghost=Ghost_InitAutoGhost(this, enemyID, GHF_NO_FALL);
        Ghost_TileWidth=VBound(Floor(ghost->Attributes[WB_ATTR_TILE_WIDTH]), 4, 1);
        Ghost_TileHeight=VBound(Floor(ghost->Attributes[WB_ATTR_TILE_HEIGHT]), 4, 1);
        Ghost_SpawnAnimationPuff(this, ghost);
        
        // Set flags
        flags=GHF_STUN|GHF_CLOCK;
        if(ghost->Attributes[WB_ATTR_IGNORE_WATER]>0)
            flags|=GHF_IGNORE_WATER;
        if(ghost->Attributes[WB_ATTR_IGNORE_PITS]>0)
            flags|=GHF_IGNORE_PITS;
        Ghost_SetFlags(flags);
        
        // Get initial movement
        angle=45+90*Rand(4);
        step=ghost->Step/100;
        ghost->Step=0; // In case it's a walker
        
        xStep=step*Cos(angle);
        yStep=step*Sin(angle);
        
        while(true)
        {
            // Bounce
            if(xStep<0)
            {
                if(!Ghost_CanMove(DIR_LEFT, -xStep, 3))
                   xStep*=-1;
            }
            else
            {
                if(!Ghost_CanMove(DIR_RIGHT, xStep, 3))
                   xStep*=-1;
            }
            
            if(yStep<0)
            {
                if(!Ghost_CanMove(DIR_UP, -yStep, 3))
                   yStep*=-1;
            }
            else
            {
                if(!Ghost_CanMove(DIR_DOWN, yStep, 3))
                   yStep*=-1;
            }
            
            // And move
            Ghost_MoveXY(xStep, yStep, 3);
            Ghost_Waitframe(this, ghost, true, true);
        }
    }
}


#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 05 November 2017 - 03:22 PM

I made one of these. I was sure it was in the database, but it doesn't seem to be. 

// import "std.zh"
// import "string.zh"
// import "ghost.zh"

// npc->Attributes[] indices
const int WB_ATTR_TILE_WIDTH = 2;
const int WB_ATTR_TILE_HEIGHT = 3;
const int WB_ATTR_IGNORE_WATER = 4;
const int WB_ATTR_IGNORE_PITS = 5;

ffc script WallBouncer
{
    void run(int enemyID)
    {
        npc ghost;
        int flags;
        int angle;
        float step;
        float xStep;
        float yStep;
        
        // Initialize
        ghost=Ghost_InitAutoGhost(this, enemyID, GHF_NO_FALL);
        Ghost_TileWidth=Ghost_GetAttribute(ghost, WB_ATTR_TILE_WIDTH, 1, 1, 4);
        Ghost_TileHeight=Ghost_GetAttribute(ghost, WB_ATTR_TILE_HEIGHT, 1, 1, 4);
        Ghost_SpawnAnimationPuff(this, ghost);
        
        // Set flags
        flags=GHF_STUN|GHF_CLOCK;
        if(ghost->Attributes[WB_ATTR_IGNORE_WATER]>0)
            flags|=GHF_IGNORE_WATER;
        if(ghost->Attributes[WB_ATTR_IGNORE_PITS]>0)
            flags|=GHF_IGNORE_PITS;
        Ghost_SetFlags(flags);
        
        // Get initial movement
        angle=45+90*Rand(4);
        step=ghost->Step/100;
        ghost->Step=0; // In case it's a walker
        
        xStep=step*Cos(angle);
        yStep=step*Sin(angle);
        
        while(true)
        {
            // Bounce
            if(xStep<0)
            {
                if(!Ghost_CanMove(DIR_LEFT, -xStep, 3))
                   xStep*=-1;
            }
            else
            {
                if(!Ghost_CanMove(DIR_RIGHT, xStep, 3))
                   xStep*=-1;
            }
            
            if(yStep<0)
            {
                if(!Ghost_CanMove(DIR_UP, -yStep, 3))
                   yStep*=-1;
            }
            else
            {
                if(!Ghost_CanMove(DIR_DOWN, yStep, 3))
                   yStep*=-1;
            }
            
            // And move
            Ghost_MoveXY(xStep, yStep, 3);
            Ghost_Waitframe(this, ghost, true, true);
        }
    }
}
This will work with walking enemies so you can use their touch effects. Other attributes won't work normally.Attribute 3 (Death Attr. 1): Tile width (1-4, default 1)Attribute 4 (Death Attr. 2): Tile Height (1-4, default 1)Attribute 5 (Death Attr. 3): Move over water (0: no, 1: yes)Attribute 6 (Extra Shots): Move over direct warps (0: no, 1: yes)

Would you object at all if I pull this into the Zelda 3 module?

#6 judasrising

judasrising

    I play guitar

  • Members
  • Location:Sweden but born in Finland

Posted 05 November 2017 - 03:34 PM

And the script is in the old script database https://www.purezc.n...showtopic=57417



#7 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 06 November 2017 - 03:29 PM

Would you object at all if I pull this into the Zelda 3 module?

No, go ahead.

#8 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 09 November 2017 - 04:01 AM

No, go ahead.

Thank you. As soon as I reinstall everything onto my new SSD, and have my laptop running again, I'll push it to: Zelda3.zh on GitHub.

You might find the project interesting. I have not made threads for it to date, as I do not wish to raise expectations of the userbase in such an early state, but this is what a few of us have been doing on the sidelines, for the Z3 module scripts.

Edited by ZoriaRPG, 09 November 2017 - 04:04 AM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users