bravespiritz
Member
- Joined
- Aug 10, 2023
- Messages
- 33
- Reaction score
- 5
I have this script, that im trying to this with. I need help with the quest system. Spawning the monsters works great. they should be linked together.
- when a player steps in a magic forcefield with the unique id "1000",
Here is the script below, any thoughts on how I can solve this?
- when a player steps in a magic forcefield with the unique id "1000",
- quest start when entering the portal
- a timer starts of 5 min. also the player needs to kill 15 monsters.
- inside the quest area the monsters 2 monsters should spawn, and after you kill one, two more should spawn. (this works in my script)
- when a player kills a monster, a message will show progress
- both needs to be completed for the quest to complete, time needs to reach 5min and creature kills 15.
- on completion the player is teleported to position(1000, 1000, 7)
- if timer runs out and the player has not killed 15 monsters, the player is teleported to position(1000, 1000, 7)
- the player who has completed the quest will receive randomly a item in a array. the items are "2457", "2509", "2465", "2478", "2511"
- when the player has failed or succeeded the monsters should be reset to like on startup.
Here is the script below, any thoughts on how I can solve this?
Lua:
local monsterIndex = 1
local spawnPosition = Position(999, 974, 7) -- this is the monster spawn position
local monsterList = {
"rat", "cave rat", "troll", "rotworm"
}
local requiredKills = 15
local completedPlayers = {} -- To track completed players
local creatureevent = CreatureEvent("SpawnRandomMonstersOnDeath")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
for _ = 1, 2 do
local rand = math.random(#monsterList)
local monster = Game.createMonster(monsterList[rand], spawnPosition)
monster:registerEvent("SpawnRandomMonstersOnDeath")
end
return true
end
creatureevent:register()
local globalevent = GlobalEvent("SpawnRandomMonstersOnStartup")
function globalevent.onStartup()
for _ = 1, 2 do
local rand = math.random(#monsterList)
local monster = Game.createMonster(monsterList[rand], spawnPosition)
monster:registerEvent("SpawnRandomMonstersOnDeath")
end
return true
end
globalevent:register()
local function resetMonsters()
for _, creature in ipairs(spawnPosition:getCreatures()) do
creature:remove()
end
end
function onStepIn(creature, item, position, fromPosition)
print("Player stepped into the magic forcefield with ID 1000")
if item:getId() == 1387 and not completedPlayers[creature:getName()] then
print("Quest started for player:", creature:getName())
creature:teleportTo(position(1000, 986, 7))
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Quest started! You have 5 minutes to kill 15 monsters.")
local kills = 0
local timer = 5 * 60 -- 5 minutes in seconds
local questTimer
questTimer = function()
if kills >= requiredKills then
completedPlayers[creature:getName()] = true
creature:teleportTo(position(1000, 1000, 7))
local rewardItems = {"2457", "2509", "2465", "2478", "2511"}
local rewardItem = rewardItems[math.random(#rewardItems)]
creature:addItem(rewardItem, 1)
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You've completed the quest and received a reward.")
else
if timer > 0 then
creature:sendTextMessage(MESSAGE_STATUS_WARNING, "Quest progress: " .. kills .. "/" .. requiredKills .. " monsters. Time left: " .. timer .. " seconds.")
timer = timer - 1
addEvent(questTimer, 1000)
else
creature:teleportTo(position(1000, 1000, 7))
creature:sendTextMessage(MESSAGE_STATUS_WARNING, "Quest failed! You ran out of time.")
end
end
end
addEvent(questTimer, 1000)
end
return true
end