Jump to content

Photo

How did leevers resurface in LA, OOA, OOS?


  • Please log in to reply
6 replies to this topic

#1 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 29 December 2016 - 01:55 PM

I was thinking of giving ghost.zh a try and scripting a leever.

however I was wondering how leevers resurface programmatically to where they don't resurface in the same spot as another leever surfacing?

 

 



#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 29 December 2016 - 05:12 PM

I was thinking of giving ghost.zh a try and scripting a leever.
however I was wondering how leevers resurface programmatically to where they don't resurface in the same spot as another leever surfacing?


The Gameboy code is Z80 assembly... Just check for another enemy at the location where you want them to rise, and either reset their timer, or do an additional Ghost_Move to offset their location.

#3 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 29 December 2016 - 06:23 PM

ok thankyou

 

Edit: @ZoriaRPG so whats the best to do the following things?

 

- check whether or not the leever is colliding with a wall ( so I can tell it to go back into the ground )

- check whether or not the leever is adjacent to link (so I can change its direction)

- check whether or not the leever is snapped to the grid on the x or y axis (so I can tell it to go back into the ground)

- and lastly how do I change the animation so that it shows digging into the ground and digging back out?


Edited by Shadowblitz16, 29 December 2016 - 08:05 PM.


#4 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 29 December 2016 - 10:39 PM

@ZoriaRPG

can you tell me why this script spawns a ton of leevers in the same place and then doesn't seem to do anything?

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

// A simple enemy that moves straight toward Link, periodically shooting
// fireballs off to his sides. Not much of an enemy, just a script example.
// Appears on screen 1 in the demo.

const int LEEVER_ENEMY_ID = 26;
const int LEEVER_BURIED_COMBO = 9864;
const int LEEVER_ATTACK_COMBO = 9865;
const int LEEVER_SURFACE_COMBO = 9866;
const int LEEVER_SUBMERGE_COMBO = 9867;

ffc script Ghosted_Leever
{
    void run()
    {
        npc ghost;
        int timer;
		int state;
		int HaltTime = 60;
        
        // Initialize
        ghost=Ghost_InitCreate(this, LEEVER_ENEMY_ID);
        Ghost_SetFlag(GHF_NORMAL);
        Ghost_SetFlag(GHF_4WAY);
        
        Ghost_SpawnAnimationPuff(this, ghost);
        timer=Rand(120, 180);
		state=0;
		
        while(true)
        {
			timer --;
			if(state && (timer <= 0 || Ghost_CanMove(Ghost_Dir, ghost->Step, 2) != true)) // if state is 1 and npc can't move or timer is up
            {
				Ghost_Data=LEEVER_SUBMERGE_COMBO;
				Ghost_Waitframes(this, ghost, true, true, 60); // delay next animation
				Ghost_Data=LEEVER_BURIED_COMBO;
				state = 0;
				timer=Rand(120, 180);
				
			}
			else if (!state && timer <= 0) // if state is 0 and npc timer is up
			{
				state = 1;
				Ghost_Data=LEEVER_SURFACE_COMBO;
				Ghost_Waitframes(this, ghost, true, true, 60); // delay next animation
				Ghost_Data=LEEVER_ATTACK_COMBO;
				timer=Rand(120, 180);
			}
			
			if(state)
			{
				Ghost_HaltingWalk4(-1, ghost->Step, ghost->Rate, ghost->Homing, ghost->Hunger, ghost->Haltrate, HaltTime); // Move towords link
				Ghost_CheckHit(this, ghost);
			}
			else
			{
				Ghost_HaltingWalk4(-1, ghost->Step, 4, 63, 0, 0, 0); // Move away from link
			}
			
			if (Ghost_GotHit() && Ghost_HP > 0) { Ghost_StopKnockback(); }
			Ghost_Waitframes(this, ghost, true, true, 1);
        }
    }
}   



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 30 December 2016 - 04:56 AM

Oh my... You're trying to script a leever, using the internal, hardcoded leever?!

 

Right, so, that's not a particularly wise idea. The internal leever has a lot of fundamental variables that simply cannot be read in 2.50.x. Hell, I hesitate to add them to any version of ZC.

 

What you want to do, is script the movement entirely, with a burrowing animation as a phase, a rising animation as a phase, and both underground, and above-ground movement phases. Use an NPC type of 'Other' for this, rather than going bonkers working with the internal leever enemy.



#6 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 30 December 2016 - 01:59 PM

I downloaded the Z4 Leever script and I think I see what I'm doing wrong

nope its the states ghost.zh doesn't like them. they freeze the ai.


Edited by Shadowblitz16, 30 December 2016 - 03:22 PM.


#7 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 30 December 2016 - 04:15 PM

@ZoriaRPG ok so this a built off of someone else's script the Z4 Leever to be precise

 

however I can seem to understand why they don't always face towards link when they spawn.

they are also supposed to face towards link when the "dirDelay" is up and they are adjacent to link.

 

here is my code

//This enemy behaves like a Leever, but homes in on Link whenever it's above ground.
// This approximately recreates the behavior of Leevers in Link's Awakening,
// among other games.
//
//Enemy Attributes Used:
// -Step Speed: Determines speed (standard: 50)
// -Misc. Attr. 1: Frames that the enemy will spend underground (default: 60)
// -Misc. Attr. 2: Frames that the enemy will spend aboveground (default: 120)
// -Misc. Attr. 11: Combo index for enemy graphics
// -Misc. Attr. 12: FFC Script Slot
//
//The combos must be four consecutive combos:
// 1. Initial surfacing combo
// 2. Second surfacing combo
// 3. Above ground combo
// 4. Below ground combo (usually blank)
//The combos play in the order 4-1-2-3-2-1-4-1-2-3... etc.

//Misc. Attribute Indexes
const int Z4LEEVER_COMBO_INDEX = 10;
const int Z4LEEVER_UNDER_TIME_INDEX = 0;
const int Z4LEEVER_ABOVE_TIME_INDEX = 1;

int angle;


ffc script Z4Leever {
    void run(int enemyID) {

        npc ghost;
		int combo;
        float step;
        int belowTime;
        int aboveTime;
        float lastX;
		int posDelay;
		int dirDelay;

		//Initialize
		ghost = Ghost_InitAutoGhost(this, enemyID);
		Ghost_SetFlag(GHF_NORMAL);
		combo = Ghost_GetAttribute(ghost, Z4LEEVER_COMBO_INDEX, 0);
		step = ghost->Step/100;
		belowTime = Ghost_GetAttribute(ghost, Z4LEEVER_UNDER_TIME_INDEX, 60);
		aboveTime = Ghost_GetAttribute(ghost, Z4LEEVER_ABOVE_TIME_INDEX, 120);
		posDelay = Rand(160, 300);
		dirDelay = Rand(60, 120);
			
		while(true) {

			bool skip = 0;
			if (posDelay > 0) posDelay --;
			if (dirDelay > 0) dirDelay --;
			
			//underground
			Ghost_Data = combo+3;
			ghost->CollDetection = false; //Make ghost intangible
			Ghost_Waitframes(this, ghost, true, true, belowTime);
			Change_Pos(Link->X, Link->Y);
			Change_Dir(Link->X, Link->Y);
			
			//surfacing
			Ghost_Data = combo;
			Ghost_Waitframes(this, ghost, true, true, 10);
			Ghost_Data = combo+1;
			Ghost_Waitframes(this, ghost, true, true, 10);
			
			//aboveground
			Ghost_Data = combo+2;
			ghost->CollDetection = true; //Make ghost tangible
			for(int i=0; i<aboveTime; i++) {
				if (dirDelay <= 0)
				{
					Change_Dir(Link->X, Link->Y);
					dirDelay = Rand(60, 120);
				}
				if (posDelay <= 0 || Ghost_CanMove(Ghost_Dir, step, 0) == false)
					skip = 1;
					posDelay = Rand(160, 300);
					
				if (!skip)
				{
					Ghost_Move(Ghost_Dir, step, 0);
					Ghost_Waitframe(this, ghost, true, true);
				}
			}
			
			//digging
			Ghost_Data = combo+1;
			ghost->CollDetection = false; //Make ghost intangible
			Ghost_Waitframes(this, ghost, true, true, 10);
			Ghost_Data = combo;
			Ghost_Waitframes(this, ghost, true, true, 10);
        }
    }
}
void Change_Dir(int x, int y)
{
	if (Ghost_X >= Link->X)
		Ghost_Dir = 2.5 + Sign(Link->X - Ghost_X) / 2;
	else if (Ghost_Y >= Link->Y)
		Ghost_Dir = 0.5 + Sign(Link->Y - Ghost_Y) / 2;
	else 
		Ghost_Dir = Ghost_Dir;
}

void Change_Pos(int x, int y)
{
	int r = Rand(0, 1);
	if (r == 0) 
	{
		Ghost_X = Link->X;
		Ghost_Y = Rand(0, 160);
	}
	else
	{
		Ghost_X = Rand(0, 304);
		Ghost_Y = Link->Y;	
	}
}





Edited by Shadowblitz16, 30 December 2016 - 04:16 PM.



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users