Page 1 of 1

Reset level area when re-entering

Posted: Thu Jul 04, 2019 8:00 pm
by Cellinarac
ok, so back with another question. SMBX2, is there a way to have the level reset a "room" after you leave and re-enter? I'm asking because there are several instances where I will be entering and leaving the same rooms more than once. when I re-enter the room all the NPC's that I killed the last time through that room are still dead. is there any way to have the NPC's "reset" each time you re-enter the "room"? I know you can have NPC's "respawn" with time delays but thats not what I am looking for really. I remember on the SNES if you left an area and then went back through it, there was times the NPC's would also be back and that's what I am aiming for.
Thanks!

Re: Reset level area when re-entering

Posted: Fri Jul 05, 2019 4:10 am
by Emral

Re: Reset level area when re-entering

Posted: Fri Jul 05, 2019 11:35 am
by Cellinarac
Enjl wrote:
Fri Jul 05, 2019 4:10 am
viewtopic.php?f=101&t=24038
Doesn't seem to be working for me. no changes at all. Maybe I am doing something wrong

Re: Reset level area when re-entering

Posted: Sun Jul 07, 2019 11:12 pm
by Cellinarac
Still having no luck getting this to work. I've searched youtube for answers/Ideas but can't find a single thing on it so far. is this hopeless? I am now using the latest release as well thinking that would have solved the issue, but still not working.

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 12:39 am
by Emral
If your suspicion is that you're doing something wrong, sharing what you're doing sounds like a way to help others get an idea for where the problem may lie.

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 8:10 am
by Cellinarac
Enjl wrote:
Mon Jul 08, 2019 12:39 am
If your suspicion is that you're doing something wrong, sharing what you're doing sounds like a way to help others get an idea for where the problem may lie.
well, I'm not 100% sure how to use the scripts, I copied the script to a lunalua file and placed it in my level folder, that didn't work, so then I tried copying it to my worlds folder, that didn't work, then I tried putting it in the scripts folder under "data", that didn't work.... is there something I need to do to actually "activate" the script in the game? feeling a little lost at the moment. I have tested this with SMBX2-Beta3 and with SMBX2 PAL with no luck. it seems like it was easier to get scripts working in the old 1.4.4 back when I was using it. I'm not exactly sure how you get them working now, I remember back in the old versions you could make an event to launch the scripts, I can no longer find this option under "events"

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 1:19 pm
by Emral
In order to use a script you need to load it. This is typically done with local myLibrary = require("filename"), or in your case, local resetdoors = require("resetdoors")

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 4:28 pm
by Cellinarac
Enjl wrote:
Mon Jul 08, 2019 1:19 pm
In order to use a script you need to load it. This is typically done with local myLibrary = require("filename"), or in your case, local resetdoors = require("resetdoors")
so it should look like this?

local resetdoors = require("resetdoors")
function onStart()

local reset = {}

local pnpc = require("pnpc")
local savestate = require("savestate")

local newblocks = require("blocks/newblocks")

local blacklist = {}
local memory = {}

local schedule = {}
local blockstate

local warpwhitelist

reset.blocks = true
reset.npcs = true

local copyfields = {
"ai1",
"ai2",
"ai3",
"ai4",
"ai5",
"direction",
"width",
"height",
"msg",
"layerName",
"isHidden",
"dontMove",
"id",
}

function reset.blacklistNPCs(ids)
if type(ids) == "number" then
blacklist[ids] = true
else
for k,v in ipairs(ids) do
blacklist[v] = true
end
end
end

function reset.whitelistWarps(ids)
warpwhitelist = table.map(ids)
end

function reset.onInitAPI()
registerEvent(reset, "onStart")
registerEvent(reset, "onTickEnd")
registerEvent(reset, "onNPCKill")
end

function reset.onStart()
if reset.blocks then
blockstate = savestate.save(savestate.STATE_BLOCK)
end
if reset.npcs then
for k,v in ipairs(NPC.get()) do
if not blacklist[v.id] then
if v:mem(0x64, FIELD_BOOL) == false then
v = pnpc.wrap(v)
memory[v.uid] = {
basegame = table.clone(v.data._basegame),
x = v:mem(0xA8, FIELD_DFLOAT),
y = v:mem(0xB0, FIELD_DFLOAT),
section = v:mem(0x146, FIELD_WORD)
}
for _, f in ipairs(copyfields) do
memory[v.uid][f] = v[f]
end
end
end
end
end
end

local function scheduleForReset(v, kill)
v.data.reset = v.data.reset or {}
if kill then
v:kill(9)
end
v.data.reset.terminated = true
if v:mem(0x138, FIELD_WORD) == 0 then
table.insert(schedule, v.uid)
end
end

function reset.onNPCKill(o, v, r)
if not reset.npcs then return end
if (not v.friendly) and v:mem(0xDC, FIELD_WORD) > 0 then
v = pnpc.wrap(v)
if memory[v.uid] then
if not (v.data.reset and v.data.reset.terminated) then
scheduleForReset(v)
end
end
end
end

local lastwarp = 0

function reset.onTickEnd()
if player:mem(0x15C, FIELD_WORD) > 0 and lastwarp == 0 then
if (warpwhitelist and warpwhitelist[player:mem(0x5A, FIELD_WORD)]) or not warpwhitelist then
if reset.npcs then
local s = Section(player.section)
for k,v in ipairs(NPC.getIntersecting(s.boundary.left, s.boundary.top, s.boundary.right, s.boundary.bottom)) do
if v:mem(0x64, FIELD_BOOL) == false then
if (not v.friendly) then
if v:mem(0x12C, FIELD_WORD) == 0 then
v = pnpc.wrap(v)
if memory[v.uid] then
if v:mem(0xDC, FIELD_WORD) > 0 then
scheduleForReset(v, true)
else
v.data.reset = {terminated = true}
v:kill(9)
end
end
end
end
end
end

for i = #schedule, 1, -1 do
local v = schedule
local lookup = memory[v]
local n = NPC.spawn(lookup.id, lookup.x, lookup.y, lookup.section, true)
n = pnpc.wrap(n)
n.data._basegame = table.clone(lookup.basegame)
for _, f in ipairs(copyfields) do
n[f] = lookup[f]
end

n:mem(0xD8, FIELD_FLOAT, lookup.direction)
n:mem(0xDE, FIELD_WORD, lookup.ai1)
n:mem(0xE0, FIELD_WORD, lookup.ai2)

memory[n.uid] = lookup
memory[v] = nil
schedule = nil
end
end
if reset.blocks then
savestate.load(blockstate, savestate.STATE_BLOCK)
newblocks.onStart()
end
end
end

lastwarp = player:mem(0x15C, FIELD_WORD)
end

return reset
end


and what directory should the LUA file be in? I have it in the Level folder but it still does not work
thank you for all the help, I am pretty new to all of this with the newer release of SMBX2 and feel like I am lost and starting over lol

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 4:33 pm
by Emral
no, literally just put resetdoors.lua in the level folder and put the require line at the top of luna.lua

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 4:49 pm
by Cellinarac
Enjl wrote:
Mon Jul 08, 2019 4:33 pm
no, literally just put resetdoors.lua in the level folder and put the require line at the top of luna.lua
ok, well I now have the "resetdoors.LUA" in the SMBX2\data\scripts\base\engine directory because it said it was looking for it there. and I have the lunalua file with the line "local resetdoors = require("resetdoors")" in the "worlds" folder, still nothing happens. before I put the "resetdoors" file in the "engine" directory I was getting an error stating that it was looking for the file in that directory

Added in 49 minutes 48 seconds:
enjl, if you have a video tutorial that might help, that would be great! I am subscribed to you on youtube

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 6:05 pm
by Emral
I said level folder. The folder named after your level, in the same directory as your level file. Dunno how that equates to base/engine...

Relevant fundamentals:
viewtopic.php?f=35&t=10507
the bottommost spoiler tag in the first post.

Relevant video area:
https://youtu.be/LUmyq7Rx1DI?list=PLfa8 ... MzI_&t=326
the following 5 seconds.

Re: Reset level area when re-entering

Posted: Mon Jul 08, 2019 6:14 pm
by Cellinarac
Enjl wrote:
Mon Jul 08, 2019 6:05 pm
I said level folder. The folder named after your level, in the same directory as your level file. Dunno how that equates to base/engine...

Relevant fundamentals:
viewtopic.php?f=35&t=10507
the bottommost spoiler tag in the first post.

Relevant video area:
https://youtu.be/LUmyq7Rx1DI?list=PLfa8 ... MzI_&t=326
the following 5 seconds.
yea, I know you said the level folder, but what I am saying is when I did that , an error popped up saying it could not find the file in the directory I listed, it was looking for it to be in "SMBX2\data\scripts\base\engine". I will remove the file from there and screenshot the error it gives. I don't get why either honestly, but thats exactly what it said lol

Added in 3 minutes 38 seconds:
Image

Added in 13 minutes 13 seconds:
Image

Added in 29 seconds:
Image

Re: Reset level area when re-entering

Posted: Tue Jul 09, 2019 4:20 am
by Emral
The error says that the library "require.lua", located in the base/engine directory, was unable to locate the library. If you enable windows file extensions the error becomes easier to see, but the last screenshot you showed already revealed it. Notice how luna.lua just says "luna" while resetdoors.lua says "resetdoors.lua"? Your file is called resetdoors.lua.lua

Re: Reset level area when re-entering

Posted: Tue Jul 09, 2019 8:21 am
by Cellinarac
omg!, I feel like an idiot lol. it works now. thank you very much for your help and patients

Re: Reset level area when re-entering

Posted: Tue Jul 09, 2019 1:37 pm
by Emral
No problem! Hope things work out with reset doors. They're still a bit quirky in some edge cases, after all (which it why it said BETA in the topic).

Re: Reset level area when re-entering

Posted: Tue Jul 09, 2019 3:43 pm
by Cellinarac
Enjl wrote:
Tue Jul 09, 2019 1:37 pm
No problem! Hope things work out with reset doors. They're still a bit quirky in some edge cases, after all (which it why it said BETA in the topic).
so far seem to be working fine, a slight delay but only like a second or so. so I'm happy!
Thanks again