Jump to content

Photo

Moving Platform Script


  • Please log in to reply
44 replies to this topic

#1 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 29 February 2016 - 02:10 AM

Hi there.
New to ZC, still getting used to everything this editor has to offer.
I'm trying implement moving platforms to my quest. I found this script off an old forum topic, but it's not working as expected:
 

import "std.zh"
///Constants and Variables used by platform script;
const int DIAGONAL_MOVEMENT = 1; //Enable the option and change this to 0 for nes movement.
int onplatform; //Global variable use this to check if Link is on a platform for other scripts.
 
global script slot2_platform
{
    void run()
    {
        while(true)
        {
            NesMovementFix();
            Waitdraw();
            MovingPlatforms();
            Waitframe();
        }
    }
}
 
void NesMovementFix()
{
    if(DIAGONAL_MOVEMENT==0 && (Link->InputUp || Link->InputDown))
    {
        Link->InputLeft = false;
        Link->InputRight = false;
    }
}
 
void MovingPlatforms()
{
    onplatform = 0;
    if(Link->Z == 0)
    {
        int buffer[] = "movingplatform";
        for(int i = 1; i <= 32; i++)
        {
            ffc f = Screen->LoadFFC(i);
            if(f->Script != Game->GetFFCScript(buffer)) continue;
            if(Abs(Link->X + 8 - CenterX(f)) >= f->TileWidth* continue;
            if(Abs(Link->Y + 12 - CenterY(f)) >= f->TileHeight* continue;
            onplatform = FFCNum(f);
            break;
        }
    }
}
 
ffc script MovingPlatform
{
    void run()
    {
        float oldx = this->X;
        float oldy = this->Y;
        float linkx;
        float linky;
        while(true)
        {
            if(onplatform == FFCNum(this))
            {
                 linkx += this->X - oldx;
                 linky += this->Y - oldy;
                 if(linkx << 0 != 0)
                 {
                     Link->X += linkx << 0;
                     linkx -= linkx << 0;
                 }
                 if(linky << 0 != 0)
                 {
                     Link->Y += linky << 0;
                     linky -= linky << 0;
                 }
            }
            else
            {
                 linkx = 0;
                 linky = 0;
            }
            oldx = this->X;
            oldy = this->Y;
            Waitframe();
        }
    }
}

Details:

ZC 2.5.

The code successfully compiled.

This is the entirety of the script I'm using.

I've set it to the FFC I'm trying to use.

Link does not move with the platform, but simply falls off unless player actively moves him, the same as if no script were functioning.

Can anyone spot what I'm doing wrong?

 

I apologize for not being able to ask the script-author directly, but it was a three year old thread and I wasn't sure about thread-necroing policy, nor if the author (Mero?) was still around.

 



#2 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 29 February 2016 - 03:12 PM

So after a lot of fiddling and searching, I found this alternate script which seems to work:

//This function simply checks if that the center of Link is within the bounds of the ffc.
bool OnPlatform(ffc this){
    if(CenterLinkX() < this->X) return false;
    else if(CenterLinkX() >= this->X + this->EffectWidth) return false;
    else if(CenterLinkY() < this->Y) return false;
    else if(CenterLinkY() >= this->Y + this->EffectHeight) return false;
    else return true;
}

//This script turns a moving ffc into a platform so it carries Link.
ffc script Platform{
    void run(){
        //Initialize two variables to store the position of the ffc the previous frame.
        float oldx = this->X;
        float oldy = this->Y;
        //Initialize two variables to store the change in Link's position each frame.
        float linkx;
        float linky;
        //Loop Indefinitely.
        while(true){
            //Check if Link is on the platform and is not mid-air.
            if(OnPlatform(this) && Link->Z == 0){
                //Increment linkx by the change in the ffc's position along the x axis.
                linkx += this->X - oldx;
                //Check if the absolute value of linkx truncated to an int doesn't = 0.
                if(linkx<<0 != 0){
                    //Increment link's position by linkx truncated removed.
                    Link->X += linkx<<0;
                    //Decrement linkx by itself rounded down.
                    linkx -= linkx<<0;
                }
                //Vertical Movement is the same as horizontal movement just along the y axis.
                linky += this->Y - oldy;
                if(linky<<0 != 0){
                    Link->Y += linky<<0;
                    linky -= linky<<0;
                }
            }
            //Set oldx and oldy to the ffc's current position.
            oldx = this->X;
            oldy = this->Y;
            //Waitframe to prevent lag.
            Waitframe();
        }
    }
}

That said, would still appreciate an answer to original query, so I can write it to Mero's script submission.

Also, how do you spoiler text, i.e. the big block of code I put out?



#3 Theryan

Theryan

    Burrito

  • Members

Posted 29 February 2016 - 09:58 PM

Spoiler

[spoiler]Mero was banned indefinitely. I'm sure someone knows how to contact her though.[/spoiler]


#4 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 29 February 2016 - 10:50 PM

Ah, thanks for the answers.



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 01 March 2016 - 06:13 AM

Scri[pt-related: That platform script is broken. I;ve had to make fixes, or general replacements for it a number of times, and this version in the archived 'Old Script Database' is simply ancient.

I have a few platform scripts floating about somewhere, and I'll see if I can put one up in a few days. That, or expand one of the (better) existing scripts to include this feature.

I need to know if you are using, or plan to use any of the pits/holes/lava/falling combos scripts, to ensure that they are compatible.

I should make one of my platform scripts compatible with either, or both Moosh Holes & lava, whatever Binx makes, or Cavthena's 'Pit Fall' pits & lava script.

If you plan to use bottomless pits, please use either Mooshpits, or 'Pit Fall' as Mero's pit script is officially deprecated by the author, and no longer supported.

#6 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 01 March 2016 - 12:52 PM

I do plan on combining pitfall and moving platform scripts. Thanks for the heads-up.

I'm only a week into this, and I'm already feeling like ZQuest could've been so much easier to use if it were based on the gameboy games rather than Zelda1.



#7 cavthena

cavthena

    Apprentice

  • Members
  • Real Name:Clayton
  • Location:I wish I knew

Posted 01 March 2016 - 04:00 PM

Well I told myself that I would make a platform script that works with pitfall as soon as someone needed it. So I'll get right on that when I get home.
  • EJSnowden likes this

#8 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 10 March 2016 - 08:27 PM

So I did combine the mobile platform script and pits and holes script together.

Predictably, they don't work together.

In this case, platforms work fine on their own.

Pits always work.

Trying to jump on a platform over a pit will cause Link to fall.

Spoiler

 

 

And there's the relevant code.



#9 cavthena

cavthena

    Apprentice

  • Members
  • Real Name:Clayton
  • Location:I wish I knew

Posted 10 March 2016 - 09:06 PM

Change the platform detection to 1 pixel bigger than the platform ffc.

The Bool OnPlatform() function contains the collision checks.

#10 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 10 March 2016 - 11:14 PM

Tried this:

bool OnPlatform(ffc this){
    if(CenterLinkX() < this->X+1) return false;
    else if(CenterLinkX() >= this->X-1 + this->EffectWidth) return false;
    else if(CenterLinkY() < this->Y+1) return false;
    else if(CenterLinkY() >= this->Y-1 + this->EffectHeight) return false;
    else return true;

and this:

bool OnPlatform(ffc this){
    if(CenterLinkX() < this->X-1) return false;
    else if(CenterLinkX() >= this->X+1 + this->EffectWidth) return false;
    else if(CenterLinkY() < this->Y-1) return false;
    else if(CenterLinkY() >= this->Y+1 + this->EffectHeight) return false;
    else return true;

...without luck.

 

 

Edit:

Could I add a check for Onplatform in the pit function here:

int OnPitCombo()
{
    int comboLoc = ComboAt(Link->X+8, Link->Y + Cond(BIG_LINK==0, 12, 8));
    if(Screen->ComboT[comboLoc] != CT_HOLELAVA)
        return 0;
    else if(Screen->ComboI[comboLoc] == CF_PIT || Screen->ComboI[comboLoc] == CF_LAVA)
        return Screen->ComboI[comboLoc];
    else if(Screen->ComboF[comboLoc] == CF_PIT || Screen->ComboF[comboLoc] == CF_LAVA)
        return Screen->ComboF[comboLoc];
    else
        return 0;
}
 

and make it work?


Edited by EJSnowden, 10 March 2016 - 11:21 PM.


#11 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 11 March 2016 - 03:18 AM

int OnPitCombo()
{
    int moving_platform[] = "Platform";
    int script_num = Game->GetFFCScript(moving_platform);
    int comboLoc = ComboAt(Link->X+8, Link->Y + Cond(BIG_LINK==0, 12, 8));
    for (int i = 1; i <= 32; i++)
	{
		ffc f = Screen->LoadFFC(i);
		if (f->Script == script_num && OnPlatform(f))
			return 0;
	}
    if(Screen->ComboT[comboLoc] != CT_HOLELAVA)
        return 0;
    else if(Screen->ComboI[comboLoc] == CF_PIT || Screen->ComboI[comboLoc] == CF_LAVA)
        return Screen->ComboI[comboLoc];
    else if(Screen->ComboF[comboLoc] == CF_PIT || Screen->ComboF[comboLoc] == CF_LAVA)
        return Screen->ComboF[comboLoc];
    else
        return 0;
}

Edited by Lejes, 11 March 2016 - 06:30 PM.


#12 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 11 March 2016 - 06:23 AM

syntax error, unexpected qoutedstring on token "MovingPlatform", cannot parse input file


#13 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 11 March 2016 - 03:14 PM

I edited in the fix for that.

#14 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 11 March 2016 - 03:41 PM

Damn, that reminds me, I still have to write my pit script. I really am a procrastinator. Ah well, that's something for me to do.

 

Also, keep in mind some of Mero's (at least, I think it's theirs) scripts assume that the compiler is still case insensitive to caps, meaning that things like moving platforms will not drag link along (Your problem, I presume), because the script is checking for a script names "movingplatform", when it's called "MovingPlatform".

 

Edit:
 

import "std.zh"
///Constants and Variables used by platform script;
const int DIAGONAL_MOVEMENT = 1; //Enable the option and change this to 0 for nes movement.
int onplatform; //Global variable use this to check if Link is on a platform for other scripts.
 
global script slot2_platform
{
    void run()
    {
        while(true)
        {
            NesMovementFix();
            Waitdraw();
            MovingPlatforms();
            Waitframe();
        }
    }
}
 
void NesMovementFix()
{
    if(DIAGONAL_MOVEMENT==0 && (Link->InputUp || Link->InputDown))
    {
        Link->InputLeft = false;
        Link->InputRight = false;
    }
}
 
void MovingPlatforms()
{
    onplatform = 0;
    if(Link->Z == 0)
    {
        int buffer[] = "MovingPlatform";
        for(int i = 1; i <= 32; i++)
        {
            ffc f = Screen->LoadFFC(i);
            if(f->Script != Game->GetFFCScript(buffer)) continue;
            if(Abs(Link->X + 8 - CenterX(f)) >= f->TileWidth* continue;
            if(Abs(Link->Y + 12 - CenterY(f)) >= f->TileHeight* continue;
            onplatform = FFCNum(f);
            break;
        }
    }
}
 
ffc script MovingPlatform
{
    void run()
    {
        float oldx = this->X;
        float oldy = this->Y;
        float linkx;
        float linky;
        while(true)
        {
            if(onplatform == FFCNum(this))
            {
                 linkx += this->X - oldx;
                 linky += this->Y - oldy;
                 if(linkx << 0 != 0)
                 {
                     Link->X += linkx << 0;
                     linkx -= linkx << 0;
                 }
                 if(linky << 0 != 0)
                 {
                     Link->Y += linky << 0;
                     linky -= linky << 0;
                 }
            }
            else
            {
                 linkx = 0;
                 linky = 0;
            }
            oldx = this->X;
            oldy = this->Y;
            Waitframe();
        }
    }
}

Try this. It should work fine now. Maybe I'll add a check to make sure Link isn't moved into solid walls.


Edited by Dimentio, 11 March 2016 - 03:49 PM.


#15 EJSnowden

EJSnowden

    Initiate

  • Members
  • Location:U.S.A.

Posted 11 March 2016 - 03:57 PM

For Lejes:

Could not match type signature LOADFFC(SCREEN, FFC)

regarding this line:

ffc f = Screen->LoadFFC(f);

For Dimentio: Well, the platforms do work as intended, but only over water and walkable combos. The bottomless pits override the platforms, however.

I'll try your solution here in a bit.

 

Unexpected continue, can't parse, for:

if(Abs(Link->X + 8 - CenterX(f)) >= f->TileWidth* continue;

and presumably the next line as well.


Edited by EJSnowden, 11 March 2016 - 04:08 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users