[Solved] Apply a script to all NPCs in the level

Description: Internal scripting system of SMBX-38A Engine based on the simple VB-like language
Moderators: Yoshi021, Lx Xzit, 5438A38A, Semi-moderatos, Moderators

Super Mario Player M
Topic author, Duke
Duke
Avatar
Super Mario Player M
Topic author, Duke
Duke
Age: 18
Reputation: 25
Posts: 138
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes bro)
Tencent QQ

Post #1by Super Mario Player » 18 Aug 2016, 21:16

I'd like to make a script that applies to every NPC in the level, without having to add scripts=mynpcscriptname to the .txt file of every enemy I use in the level - which would be kinda boring. Is there a way to do this?
Thanks in advance!
Last edited by Super Mario Player on 19 Aug 2016, 17:22, edited 1 time in total.
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

JDM M
Nice citizen
Nice citizen
Avatar
JDM M
Nice citizen
Nice citizen
Age: 20
Reputation: 4
Posts: 10
Joined: 14 Aug 2016

Post #2by JDM » 19 Aug 2016, 10:52

From what I know there is no way to do it without adding scripts=XXX . But if you're too lazy you can easily made something automatic with Python, BATCH or any language.

Super Mario Player M
Topic author, Duke
Duke
Avatar
Super Mario Player M
Topic author, Duke
Duke
Age: 18
Reputation: 25
Posts: 138
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes bro)
Tencent QQ

Post #3by Super Mario Player » 19 Aug 2016, 11:19

Okay, that's too bad but I think I'll be able to handle it. BTW, thanks for the answer!
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

rotom407 M
Nice citizen
Nice citizen
rotom407 M
Nice citizen
Nice citizen
Age: 21
Reputation: 1
Posts: 15
Joined: 28 Jun 2016

Post #4by rotom407 » 19 Aug 2016, 11:20

Here is a somewhat inefficient solution that may cause the frame rate to drop if your script is complex or too many NPCs are on the screen.
(executed when the level starts, needs a variable to work)

Code: Select all

Do
For v(a)=1 to sysval(NCount)
With NPC(v(a))
If .x>sysval(Player1scrX)-100 And .x<sysval(Player1scrX)+900 And .y>sysval(Player1scrY)-100 And .y<sysval(Player1scrY)+700 Then
'Your script goes here
End If
End With
Next
Call sleep(1)
Loop

JDM M
Nice citizen
Nice citizen
Avatar
JDM M
Nice citizen
Nice citizen
Age: 20
Reputation: 4
Posts: 10
Joined: 14 Aug 2016

Post #5by JDM » 19 Aug 2016, 13:05

Oh ! I didn't know about sysval(NCount) ! Useful if you don't want to modify AI of monsters !

Super Mario Player M
Topic author, Duke
Duke
Avatar
Super Mario Player M
Topic author, Duke
Duke
Age: 18
Reputation: 25
Posts: 138
Joined: 23 Jun 2016
Location: The sewers (fixing teh pipes bro)
Tencent QQ

Post #6by Super Mario Player » 19 Aug 2016, 13:51

Unfortunately, this script works only if used at level start or with NPCs created after the beginning of the stage. Thanks a lot anyway!
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 “TeaScript”

Who is online (over the past 5 minutes)

Users browsing this forum: 6 guests