Jump to content

Photo

Problematic Vaccum Script


  • Please log in to reply
4 replies to this topic

#1 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 10 March 2007 - 12:32 AM

CODE
//Notes for non-coders:
//suck_dist is the distance in pixels the vacuum will suck the enemy closer to Link
//dist_from_link is the range in pixels the enemy will have to be from Link for the vacuum to start sucking

item script Enemy_Vacuum
{

int suck_dist = 6;
int dist_from_link = 33;

    void run()
    {

    npc current_enemy;
    int i;

        if ( Screen->NumNPCs() == 0) {
            Quit();
        }


        for (i = 0; i < Screen->NumNPCs(); i++)
        {
            current_enemy = Screen->LoadNPC(i);

            if ( dist(Link->X, Link->Y, current_enemy->X, current_enemy->Y) < dist_from_link )
            {
                if (Link->X > current_enemy->X) {
                    current_enemy->X -= suck_dist;
                }
                else if (Link->X < current_enemy->X) {        
                    current_enemy->X += suck_dist;
                }
                else if (Link->X == current_enemy->X) {            
                    Quit();            
            
                
                if (Link->Y > current_enemy->Y) {
                    current_enemy->Y -= suck_dist;
                }
                else if (Link->Y < current_enemy->Y) {
                    current_enemy->X += suck_dist;
                }
                else if (Link->Y == current_enemy->Y) {            
                    Quit();    
                }
            }
        }
    }
}
float dist(float x1, float y1, float x2, float y2) {
  return Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

}


This is an enemy vacuum that draws enemies closer to link in a set range. (See variables at top). It compiles fine, but does absolutely nothing. I'm testing the script with it attached to wand, if that may be a factor prevent the script from working.

Does anyone have wise words of advice? icon_razz.gif

Edited by Fire Wizzrobe, 10 March 2007 - 05:31 PM.


#2 Radien

Radien

    Courage

  • Members
  • Real Name:Steve
  • Location:Oregon

Posted 10 March 2007 - 01:23 AM

I don't have any advice, of course, but I just have to drop in to say:

This script sucks.

....

icon_heh.gif ...*runs*

#3 Saffith

Saffith

    IPv7 user

  • Members

Posted 10 March 2007 - 01:41 AM

This:
CODE
for (i = 0; i == Screen->NumNPCs(); i++)

Should be this:
CODE
for (i = 0; i < Screen->NumNPCs(); i++)


#4 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 10 March 2007 - 09:56 AM

Thanks. I thought that using the == was a valid statement and the for loop would terminate when it equaled the number of NPCs.

So if the first NCP has a value of 0, and we have 8 enemies on the screen, NumNcps() will return 8 and not 7?

It's very strange, the whole program crashes upon use.

#5 Saffith

Saffith

    IPv7 user

  • Members

Posted 10 March 2007 - 03:04 PM

Hm. I didn't look at it that closely before. I see those two Quit() statements... I don't think you want those there. The whole script will quit running if it hits one of those. Also, the closing brace after the first one is missing. It seems to have joined the group of them just before dist() is defined. I'm sure that's not what you intended.

QUOTE(Fire Wizzrobe @ Mar 10 2007, 09:56 AM) View Post
Thanks. I thought that using the == was a valid statement and the for loop would terminate when it equaled the number of NPCs.
It's the other way around; with that condition, the loop will run only when they're equal. The loop executes as long as the condition is true, not until it is.
I see you edited it, but it's backward: it should be <, not >.

QUOTE
So if the first NCP has a value of 0, and we have 8 enemies on the screen, NumNcps() will return 8 and not 7?
Yeah. They may be numbered 0-7, but there are still eight of them.
Come to think of it, though, I think they're actually numbered 1-8. Try for (i = 1; i <= Screen->NumNPCs(); i++) instead if it still doesn't work right once the crashing is fixed.

QUOTE
It's very strange, the whole program crashes upon use.
I don't know why that would be. I don't see anything that should cause it to crash. It's not doing it for me, so I can't find where it's happening. Do you know how to use Trace()?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users