Make npc occasionally stop walking forward and look left and right

Description: Have idea for a script, but you can't make it? Post it here!
Moderators: Lx Xzit, Yoshi021, 5438A38A, Moderators, Semi-moderatos

Mushroom King
Topic author, Marquis
Marquis
Mushroom King
Topic author, Marquis
Marquis
Reputation: 32
Posts: 155
Joined: 31 Dec 2015

Post #1by Mushroom King » 26 Feb 2017, 19:26

I would need a script to make a npc occasionally stop walking, look left and right and walking again every x frames, like the shyguys in Yoshi Island. Maybe even make the npc change direction after the stop. Is that possible?

Super Mario Player M
Duke
Duke
Avatar
Super Mario Player M
Duke
Duke
Reputation: 25
Posts: 135
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes)
Tencent QQ

Post #2by Super Mario Player » 6 Mar 2017, 0:14

You can use the variable NPC(id).facing to set the direction this NPC is facing, and NPC(id).Xsp and NPC(id).Ysp to set its horizontal and vertical speed.

You can try the following : letting him walk a few steps, set its horizontal and vertical speed to 0, toggle its facing direction between left and right a few times, then send him in the direction he's facing, and repeat this process.

(I can't make the script for the moment because I'm transferring my SMBX data to my new hard drive, I'll try to script that asap)
My current project:
Spoiler
The Legend of Zelda: The Curse of the Wise Men
Image

The Tower of Challenges

Languages I speak (if you want to PM me):
Spoiler
Image Image Image

Click to see my YouTube channel
Image

Mushroom King
Topic author, Marquis
Marquis
Mushroom King
Topic author, Marquis
Marquis
Reputation: 32
Posts: 155
Joined: 31 Dec 2015

Post #3by Mushroom King » 6 Mar 2017, 12:05

Thanks. I appreciate your help.

Super Mario Player M
Duke
Duke
Avatar
Super Mario Player M
Duke
Duke
Reputation: 25
Posts: 135
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes)
Tencent QQ

Post #4by Super Mario Player » 9 Mar 2017, 19:51

I'm currently running into an issue :/
I've tried the following code:

Code: Select all

with npc(sysval(param1))
   if val(timer)>val(WalkTime) and val(timer)<val(WalkTime)+val(RestartTime) then
      do
         val(npctimer)=val(npctimer)+1
         call sleep(1)
      loop until val(npctimer)=val(ToggleTime)
      select case .facing
         case -1
            .facing=1
         case 1
            .facing=-1
      end select
      .Xsp=0
      .Ysp=0
   end if
   call sleep(1)
end with


I'm setting the value of variables via events.
I've put call sleep(1) statements where they are needed but the game still freezes :mad:
My current project:
Spoiler
The Legend of Zelda: The Curse of the Wise Men
Image

The Tower of Challenges

Languages I speak (if you want to PM me):
Spoiler
Image Image Image

Click to see my YouTube channel
Image

Mushroom King
Topic author, Marquis
Marquis
Mushroom King
Topic author, Marquis
Marquis
Reputation: 32
Posts: 155
Joined: 31 Dec 2015

Post #5by Mushroom King » 9 Mar 2017, 21:10

Can you share your test level, just for looking at the script and testing it myself if freeze or not?

Super Mario Player M
Duke
Duke
Avatar
Super Mario Player M
Duke
Duke
Reputation: 25
Posts: 135
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes)
Tencent QQ

Post #6by Super Mario Player » 9 Mar 2017, 21:27

There it is:
test32.lvl
(6.22 KiB) Downloaded 57 times
My current project:
Spoiler
The Legend of Zelda: The Curse of the Wise Men
Image

The Tower of Challenges

Languages I speak (if you want to PM me):
Spoiler
Image Image Image

Click to see my YouTube channel
Image

Mushroom King
Topic author, Marquis
Marquis
Mushroom King
Topic author, Marquis
Marquis
Reputation: 32
Posts: 155
Joined: 31 Dec 2015

Post #7by Mushroom King » 9 Mar 2017, 21:41

Umm, yes, the shyguy just don't walk when attaching the script and the editor freeze. I guess the problem is the fact he's not even walking to begin but I really don't know enough about scripting to know what is making the npc act like this.

Yoshi021 M
Moderator
Moderator
Avatar
Yoshi021 M
Moderator
Moderator
Age: 18
Reputation: 120
Posts: 667
Joined: 15 Feb 2016
Location: Yoshi's Island

Post #8by Yoshi021 » 10 Mar 2017, 6:55

the function sleep() only works when called from an event.
Links
ImageImageImage
Image
Image
"Going to University is FUN!" :pardon:

Super Mario Player M
Duke
Duke
Avatar
Super Mario Player M
Duke
Duke
Reputation: 25
Posts: 135
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes)
Tencent QQ

Post #9by Super Mario Player » 10 Mar 2017, 9:40

Yoshi021 wrote:the function sleep() only works when called from an event.
OK... Next time I'll read the changelog more carefully. I'll reprogram the script later.
My current project:
Spoiler
The Legend of Zelda: The Curse of the Wise Men
Image

The Tower of Challenges

Languages I speak (if you want to PM me):
Spoiler
Image Image Image

Click to see my YouTube channel
Image


Return to “Script requests”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest