How do I make NPCs move as soon as the level starts instead of when first appearing on screen?

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

Omega02 M
Topic author, Our friend
Our friend
Avatar
Omega02 M
Topic author, Our friend
Our friend
Age: 21
Reputation: 26
Posts: 74
Joined: 30 May 2020
Youtube channel URL

Post #1by Omega02 » 23 Jun 2024, 5:07

Here are a list of NPCs I want to move at start of level instead of when first appearing on screen:

NPC 104
NPC 12
NPC 8
NPC 93
NPC 294
NPC 74
NPC 245
NPC 106
NPC 270
NPC 51
NPC 52
NPC 325
NPC 329
NPC 340

Lx Xzit M
Moderator
Moderator
Avatar
Lx Xzit M
Moderator
Moderator
Reputation: 403
Posts: 765
Joined: 9 Nov 2015
Website Youtube channel URL

Post #2by Lx Xzit » 27 Jun 2024, 4:04

That's not something you can do, unfortunately. The only NPCs that don't depend of the screen are the switch platforms.

Omega02 M
Topic author, Our friend
Our friend
Avatar
Omega02 M
Topic author, Our friend
Our friend
Age: 21
Reputation: 26
Posts: 74
Joined: 30 May 2020
Youtube channel URL

Post #3by Omega02 » 28 Jun 2024, 4:26

Here's a script someone gave me that works perfectly with platforms but doesn't function properly with other NPCs:

Code: Select all

dim i as long

for i = 1 to sysval(ncount)
    with npc(i)
        if .id = 12 or .id = 8 or .id = 93 or .id = 294 or .id = 74 or .id = 245 or .id = 270 or .id = 51 or .id = 52 or .id = 325 or .id = 329 then 'You can add or remove NPCs from this list   
         .prx = sysval(player1scrx)
            .pry = sysval(player1scry)
        end if
    end with
next

call sleep(1)

for i = 1 to sysval(ncount)
    with npc(i)
        if .id = 12 or .id = 8 or .id = 93 or .id = 294 or .id = 74 or .id = 245 or .id = 270 or .id = 51 or .id = 52 or .id = 325 or .id = 329 then 'You can add or remove NPCs from this list   
            .prx = .bkupx
            .pry = .bkupy
         .x = .bkupx
            .y = .bkupy
        end if
    end with
next


Also here's a YouTube video demonstrating the problems I have with the script: https://www.youtube.com/watch?v=NEzaQMDZYsI

Lx Xzit M
Moderator
Moderator
Avatar
Lx Xzit M
Moderator
Moderator
Reputation: 403
Posts: 765
Joined: 9 Nov 2015
Website Youtube channel URL

Post #4by Lx Xzit » 29 Jun 2024, 3:03

The script puts the NPCs spawn position inside the screen, then moves them back to their original position on the next frame. Technically, the NPCs were on-screen so the game loads them all. That was a clever idea, however the biggest issue is that the code doesn't handle NPC's behaviour off-screen (and it's super hard to actually deal with it). When they're moved back off-screen, they get unloaded, that's why you're seeing inconsistent results every time. The message box is likely breaking it because it completely halts everything (another script killer, like the time stop), so it might be interrupting one of the iterations.

In conclusion, it's impossible to do what you want in a reliable way. Perhaps using .activeevent would help (I never used it, but reading its description it seems fitting), and mess with .stimer (if it's a negative value, it doesn't reset after the NPC was first initialized).


Return to “TeaScript”

Who is online (over the past 5 minutes)

Users browsing this forum: 2 guests