• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Quest Phasing

Status
Not open for further replies.

Neccta

Exalted Member
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.
 

Tommy

Founder
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.
 

Rochet2

Moderator / Eluna Dev
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:
Code:
local phases = 0
local uint32max = math.pow(2, 32)-1

-- Returns unused unique phase from phases or nil
function GetAndReservePhase()
    local phase = 2
    while (phase <= uint32max) do
        local addPhase = bit32.bor(phases, phase)
        if (addPhase ~= phases) then
            phases = addPhase
            return phase
        end
        phase = phase*2
    end
end

-- Frees the given phase (can be mask)
function FreePhase(phasemask)
    phases = bit32.band(phases, bit32.bnot(phasemask))
end

-- Example:
local a, b, c = GetAndReservePhase(), GetAndReservePhase(), GetAndReservePhase()
print("Reserved phases:", a, b, c)

FreePhase(b)
print("Freed phase:", b)

local d = GetAndReservePhase()
print("Next free phase:", d)
 

Foereaper

Founder
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.
 
Status
Not open for further replies.
Top