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