View Full Version : Quest Phasing
06-24-2014, 02:49 AM
I'm writing a quest line that involves big scenes that can't be played over top of each other. I can phase them so no 2 players will be in the same phase. One way would to create a table of phases that I could use, then use math.random to select one. But then there is a possibility to phase into another players phase while their scene is playing.
Does anyone else have an idea of what I could do? Maybe something that is more efficient.
06-24-2014, 03:50 AM
Why not just credit the people who has the quest once the cinematic is over with? Would be better than wasting time trying to phase everyone.
06-24-2014, 09:19 AM
Store which phases are in use.
Then loop through them to find a free one.
You can store the phases or the powers of 2.
Example without using a table:
local phases = 0
local uint32max = math.pow(2, 32)-1
-- Returns unused unique phase from phases or nil
local phase = 2
while (phase <= uint32max) do
local addPhase = bit32.bor(phases, phase)
if (addPhase ~= phases) then
phases = addPhase
phase = phase*2
-- Frees the given phase (can be mask)
phases = bit32.band(phases, bit32.bnot(phasemask))
local a, b, c = GetAndReservePhase(), GetAndReservePhase(), GetAndReservePhase()
print("Reserved phases:", a, b, c)
print("Freed phase:", b)
local d = GetAndReservePhase()
print("Next free phase:", d)
06-24-2014, 10:57 AM
Remember you would have to reset the specific phase whenever a player enters, seeing as you'd technically reuse phases others have been in before.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.