bravespiritz
Member
- Joined
- Aug 10, 2023
- Messages
- 33
- Reaction score
- 5
This is the error I get, I dont really know how to fix it im using TFS 1.4.2. it is supposed to be a quest that starts when a player enters a portal,
Lua Script Error: [Test Interface]
data/actions/scripts/questPortal.lua
data/actions/scripts/questPortal.lua:69: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/actions/scripts/questPortal.lua:69: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/questPortal.lua
Lua Script Error: [Test Interface]
data/actions/scripts/questPortal.lua
data/actions/scripts/questPortal.lua:69: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/actions/scripts/questPortal.lua:69: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/questPortal.lua
LUA:
local requiredKills = 15
local completedPlayers = {} -- To track completed players
local spawnPosition = Position(999, 974, 7) -- This is the quest start area
local portalPosition = Position(1000, 988, 6) -- This is the portal's position
local function resetMonsters()
for _, creature in ipairs(spawnPosition:getCreatures()) do
creature:remove()
end
end
local function spawnMonstersForQuest()
for _ = 1, 2 do
local rand = math.random(#monsterList)
local monster = Game.createMonster(monsterList[rand], spawnPosition)
monster:registerEvent("SpawnRandomMonstersOnDeath")
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getId() == 1387 and item:getUniqueId() == 1000 and not completedPlayers[player:getName()] then
print("Player used magic forcefield portal with ID 1387")
-- Check if the player's position matches the portal's position
if player:getPosition() == portalPosition then
print("Player's position matches the portal's position")
player:teleportTo(Position(999, 974, 7)) -- Teleport to a waiting area
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Quest started! You have 5 minutes to kill 15 monsters.")
-- Spawn monsters for the quest
spawnMonstersForQuest()
local kills = 0
local timer = 5 * 60 -- 5 minutes in seconds
local questTimer
questTimer = function()
if kills >= requiredKills then
completedPlayers[player:getName()] = true
player:teleportTo(Position(1000, 1000, 7)) -- Teleport to completion area
local rewardItems = {"2457", "2509", "2465", "2478", "2511"}
local rewardItem = rewardItems[math.random(#rewardItems)]
player:addItem(rewardItem, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You've completed the quest and received a reward.")
else
if timer > 0 then
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Quest progress: " .. kills .. "/" .. requiredKills .. " monsters. Time left: " .. timer .. " seconds.")
timer = timer - 1
addEvent(questTimer, 1000)
else
player:teleportTo(Position(1000, 1000, 7)) -- Teleport to failure area
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Quest failed! You ran out of time.")
end
end
end
addEvent(questTimer, 1000)
else
print("Player is not at the correct portal position")
end
end
return true
end
-- Register the onUse function
for _, uniqueId in ipairs({1000}) do
local portalItem = Tile(portalPosition):getItemById(1387, uniqueId)
if portalItem then
portalItem:setActionId(100) -- Replace AID_EXAMPLE with your desired action ID
portalItem:setAttribute(ITEM_ATTRIBUTE_ACTIONID, 100)
portalItem:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, uniqueId)
portalItem:setAttribute(ITEM_ATTRIBUTE_TEXT, "Use")
end
end
-- Global event to spawn the portal
local portalSpawnPosition = Position(1000, 988, 6) -- This is where the portal should appear
local portalUniqueId = 1000 -- Replace with the desired unique ID
local portalEvent = GlobalEvent("SpawnQuestPortal")
function portalEvent.onStartup()
local portalItem = Game.createItem(1387, 1, portalSpawnPosition)
portalItem:setUniqueId(portalUniqueId)
end
portalEvent:register()