Jump to content

[Quest Scheduler Request] Is there a way to make a quest run independet of player events? Lets say start quest automatically at server startup?


Recommended Posts

  • Premium
Posted (edited)

The idea is, i want this quest to run regardless of player actions, at the moment it seems to start at player login

ideally the quest would start at day Y(could have daily flag) hour X so basically a scheduler, so it won't be dependent on any player events
 

quest test_npcmove begin
    state start begin
		when letter begin
			chat("Started")
			set_state("spawn_monster_in_map_boss_1")
		end
    end

    -- State to check for/spawn boss 1
    state spawn_monster_in_map_boss_1 begin
        when letter begin
            chat("Spawning first boss")
            local mob_vnum = 102  -- Adjust VNUM for boss 1
            local map_index = 352
            local mobs = find_mobs_in_map(mob_vnum, map_index)
            local vid_boss1 = 0
            local mobs_str = "BOSS 1 VIDs: {" .. table.concat(mobs, ", ") .. "}"
            chat(mobs_str)
            chat("Player X: " .. 339 .. " Y: " .. 363)

            if table.getn(mobs) > 0 then
                vid_boss1 = mobs[1]
                chat("Boss 1 found, using existing with VID: " .. tostring(vid_boss1))
            else
                local vids = spawn_monster_in_map(mob_vnum, 1, false, map_index, 339, 363 + 10, true)
                vid_boss1 = vids[1]
				if vids[1] ~= nil then
					vid_boss1 = vids[1]
					chat("Boss 1 spawned with VID: " .. tostring(vid_boss1))
				else
					vids = find_mobs_in_map(mob_vnum, map_index)
					vid_boss1 = vids[1]
					chat("Boss 2 fetched vid for spwaned mob: " .. tostring(vid_boss1))
				end
            end

            pc.setqf("vid_boss1", vid_boss1)
            set_state("spawn_monster_in_map_boss_2")
        end
    end

    -- State to check for/spawn boss 2
    state spawn_monster_in_map_boss_2 begin
        when letter begin
            local mob_vnum = 101  -- Adjust VNUM for boss 2
            local map_index = 352
            local mobs = find_mobs_in_map(mob_vnum, map_index)
            local vid_boss2 = 0
            local mobs_str = "BOSS 2 VIDs: {" .. table.concat(mobs, ", ") .. "}"
            chat(mobs_str)

            if table.getn(mobs) > 0 then
                vid_boss2 = mobs[1]
                chat("Boss 2 found, using existing with VID: " .. tostring(vid_boss2))
            else
                local vids = spawn_monster_in_map(mob_vnum, 1, false, map_index, 339, 363 - 10, true)
                vid_boss2 = vids[1]
				if vids[1] ~= nil then
					vid_boss2 = vids[1]
					chat("Boss 1 spawned with VID: " .. tostring(vid_boss2))
				else
					vids = find_mobs_in_map(mob_vnum, map_index)
					vid_boss2 = vids[1]
					chat("Boss 2 fetched vid for spwaned mob: " .. tostring(vid_boss2))
				end
            end

            pc.setqf("vid_boss2", vid_boss2)
            set_state("move_bosses")
        end
    end

    -- State to move both bosses
    state move_bosses begin
        when letter begin
            local vid_boss1 = pc.getqf("vid_boss1")
            local vid_boss2 = pc.getqf("vid_boss2")
            local target_x = 339
            local target_y = 363

            mob_move(vid_boss1, target_x, target_y)
            mob_move(vid_boss2, target_x, target_y)

            chat("Both bosses moved to player's position.")
            set_state("bosses_fight")
        end
    end

    -- State where bosses fight
	state bosses_fight begin
		when letter begin
			local vid_boss1 = pc.getqf("vid_boss1")
			local vid_boss2 = pc.getqf("vid_boss2")
			local map_index = 352
			chat("Boss 1 VID: " .. tostring(vid_boss1))
			chat("Boss 2 VID: " .. tostring(vid_boss2))
			local success2, message2 = set_pc_can_attack_monster(vid_boss1, false, map_index)
			local success3, message3 = set_pc_can_attack_monster(vid_boss2, false, map_index)
			chat("Attempt to make boss 1 invinciple " .. tostring(success2) .. " - " .. message2)
			chat("Attempt to make boss 2 invinciple " .. tostring(success3) .. " - " .. message3)

			-- Attempt to make boss 1 attack boss 2
			local success1, message1 = attack_mob(vid_boss1, vid_boss2, map_index)
			if success1 ~= nil and message1 ~= nil then
				chat("Attack attempt from Boss 1 to Boss 2: " .. tostring(success1) .. " - " .. message1)
			else
				chat("Attack attempt from Boss 1 to Boss 2: success or message is nil")
			end

			-- Attempt to make boss 2 attack boss 1
			local success2, message2 = attack_mob(vid_boss2, vid_boss1, map_index)
			if success2 ~= nil and message2 ~= nil then
				chat("Attack attempt from Boss 2 to Boss 1: " .. tostring(success2) .. " - " .. message2)
			else
				chat("Attack attempt from Boss 2 to Boss 1: success or message is nil")
			end

			chat("Bosses are now set to fight each other.")
			chat("---------------------------------END------------------------------------")
			set_state("bosses_alive")
		end
	end
	
	state bosses_alive begin
		when letter begin
			chat("Checking if boss died")
			local vid_boss1 = pc.getqf("vid_boss1")
			local vid_boss2 = pc.getqf("vid_boss2")
			local map_index = 352

			-- Check if Boss 1 is alive
			local is_boss1_alive, boss1_msg = is_mob_alive_in_map(vid_boss1, map_index)
			chat("Boss 1 alive check: " .. tostring(is_boss1_alive) .. " - " .. boss1_msg)

			-- Check if Boss 2 is alive
			local is_boss2_alive, boss2_msg = is_mob_alive_in_map(vid_boss2, map_index)
			chat("Boss 2 alive check: " .. tostring(is_boss2_alive) .. " - " .. boss2_msg)

			-- Determine the next state based on the bosses' statuses
			if not is_boss1_alive or not is_boss2_alive then
				if is_mob_alive_in_map(vid_boss1, map_index) then
					local success2, message2 = set_pc_can_attack_monster(vid_boss1, true, map_index)
					chat("Resetting invicibility for boss1 " .. tostring(success2) .. " - " .. message2)
				end
				if is_mob_alive_in_map(vid_boss2, map_index) then
					local success3, message3 = set_pc_can_attack_monster(vid_boss2, true, map_index)
					chat("Resetting invicibility for boss2 " .. tostring(success3) .. " - " .. message3)
				end
				
				chat("One of the bosses is dead. Resetting quest.")
				set_state("start")
			else
				chat("Both bosses are alive. Continuing the fight.")
				set_state("bosses_alive")

			end
		end
	end
end

And the last state, called bosses_alive seems to also reexecute only at player relog (login)

Is there a way to make it so the states are independent of player events and just execute as soon as sv starts?

Edited by astroNOT
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.