Jump to content

Photo

Sand Crab Enemy Behavior

enemy

  • Please log in to reply
21 replies to this topic

#1 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 04 August 2018 - 05:11 PM

I'm trying to make a script that makes a certain enemy speed up if it is moving horizontally.

This is what I tried, and somehow, it failed:

import "std.zh"
global script Sand_Crab{
void run(){
npc enemy;
float Px = enemy->X;
if(enemy->Attributes[14] == 5 && enemy->X != Px)
enemy->Step=150;
}
}
}

It says it was a success, but it does nothing when tested. I set the correct attribute of that enemy to the correct value.


EDIT: How do I move this out of the requests sub-forum?

EDIT 2: This topic isn't solved.


Edited by Mlvluu, 05 August 2018 - 01:50 PM.


#2 Avataro

Avataro

    Quest maker

  • Members
  • Real Name:Robin
  • Gender:Male
  • Location:Germany

Posted 04 August 2018 - 05:26 PM

Attributes[14] would be 15 in the editor because it starts from 1. Also I had trouble with this kind of enemy because it glitches out when you change it's speed around.



#3 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 04 August 2018 - 05:39 PM

I changed it to 13 and it still goes at its normal speed.

#4 TheBlueTophat

TheBlueTophat

    🔸

  • Members
  • Gender:Male
  • Location:USA

Posted 04 August 2018 - 10:59 PM

npc enemy isn't assigned to any onscreen enemy, firstly. You probably want to cycle through all the onscreen enemies, and check against each one if it's a type that's a crab.
 

for(int i = 1; i <= Screen->NumNPCs(); i++)
{
	npc enemy = Screen->LoadNPC(i);
	if(enemy->Attributes[14] == 5)
	{
		enemy->Step=150;
	}
}

The way you used Px is a bit odd since the enemy would move fast as soon as it moved left or right, and would stay that way forever and ever. If that's what you want then that's fine, but I would suggest checking if(enemy->Dir == DIR_LEFT ||  enemy->Dir == DIR_RIGHT) since it's more intuitive, and would work properly with multiple enemies on-screen.
Also, this only would happen for the very first frame that the script started, since it's not within a loop. On the other hand, this ought to work:

while(true)
{
	for(int i = 1; i <= Screen->NumNPCs(); i++)
	{
		npc enemy = Screen->LoadNPC(i);
		if(enemy->Attributes[15] == 5 && (enemy->Dir == DIR_LEFT || enemy->Dir == DIR_RIGHT))
		{
			enemy->Step=150;
		}
	}
	
	Waitframe();
}

This would go in the void run() curly brackets. Also, this doesn't unset the enemy's speed when it's moving vertically. Doing that is possible, as it just requires a check for the enemy's direction to be up or down instead of left or right.


  • Anthus likes this

#5 Jamian

Jamian

    ZC enthusiast

  • Members
  • Gender:Unspecified

Posted 05 August 2018 - 04:24 AM

You'll also want to make this an FFC script (instead of a global one), and place the script on screens where these enemies appear. Also make sure to use Waitframes(5); before the script starts loading the onscreen enemies, because they take around 5 frames to appear.



#6 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 05 August 2018 - 08:44 AM

"ERROR T29: THAT POINTER TYPE DOES NOT HAVE A VARIABLE NUMNPCS."



#7 Avataro

Avataro

    Quest maker

  • Members
  • Real Name:Robin
  • Gender:Male
  • Location:Germany

Posted 05 August 2018 - 07:24 PM

Screen->NumNPCs() is correct though.


  • TheBlueTophat likes this

#8 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 06 August 2018 - 07:45 AM

It compiled, but it still doesn't work. I tried Attribute[13], Attribute[14] and Attribute[15].



#9 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 06 August 2018 - 09:51 AM

You'll also want to make this an FFC script (instead of a global one), and place the script on screens where these enemies appear. Also make sure to use Waitframes(5); before the script starts loading the onscreen enemies, because they take around 5 frames to appear.

How is it that it would work as an FFC script?



#10 TheBlueTophat

TheBlueTophat

    🔸

  • Members
  • Gender:Male
  • Location:USA

Posted 06 August 2018 - 10:32 PM

How is it that it would work as an FFC script?

Change the bit that says global to ffc. Load the script into one of the ffc slots. Then, on the screen you want the script to run, right click->Place + Edit FFC, then assign the script in the dropdown box labeled "Script:". You can't use combo 0 on ffcs, due to internal reasons, but it's fine to use a blank combo. You probably want it out of the way in this case.



#11 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 07 August 2018 - 03:04 PM

I don't want to know how to do it, I want to know how it will work.



#12 TheBlueTophat

TheBlueTophat

    🔸

  • Members
  • Gender:Male
  • Location:USA

Posted 07 August 2018 - 09:26 PM

I don't want to know how to do it, I want to know how it will work.

I'm confused what you mean? FFC scripts run just like global scripts, except they only run on the screen they're placed, and they can run alongside the global and every other FFC script onscreen. If you're still confused, you'll need to elaborate.



#13 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 08 August 2018 - 06:51 AM

Then I won’t need to change the script type.

#14 Mlvluu

Mlvluu

    Initiate

  • Members

Posted 11 August 2018 - 10:45 AM

The script doesn't work.


Edited by Mlvluu, 11 August 2018 - 10:45 AM.


#15 Avataro

Avataro

    Quest maker

  • Members
  • Real Name:Robin
  • Gender:Male
  • Location:Germany

Posted 11 August 2018 - 11:06 AM

The script doesn't work.

 

I see. That is quite troublesome, this issue is very common among scripters and non scripters alike. It's good to see people talk about the problems and work together with other people to come to a solution.  :blind:


Edited by Avataro, 11 August 2018 - 02:17 PM.

  • TheBlueTophat likes this



Also tagged with one or more of these keywords: enemy

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users