Jump to content

Recommended Posts

On 8/5/2024 at 3:32 PM, Dezcoo said:

hi i need a mod that reveals the map for the player when he spawn in for dedicated server i have one but it's only for non dedicated

Do you want to reveal the map based on one entity or the entire map?
 

local function MapExplorer(inst)
    local find = TheSim:FindFirstEntityWithTag("king")
    if find then
        local x, y, z = find.Transform:GetWorldPosition()
        inst.player_classified.MapExplorer:RevealArea(x, y, z)
    end

end

AddPrefabPostInit("world", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end

    inst:ListenForEvent("ms_newplayerspawned", function(world, player)
        local mapexplorer = player:DoTaskInTime(3, MapExplorer)

    end)
end)

 

  • Like 1

I think this code will reveal map for all players I remember seeing it on dst wiki

also based on how big your map is and how many players and how many prefabs exist in world it will freeze up the game

 

for k, v in pairs(AllPlayers) do
  for x = -1600, 1600, 35 do for y = -1600, 1600, 35 do
      v.player_classified.MapExplorer:RevealArea(x, 0, y)
    end
  end
end

 

On 8/7/2024 at 6:01 AM, Haruhi Kawaii said:

Do you want to reveal the map based on one entity or the entire map?
 

local function MapExplorer(inst)
    local find = TheSim:FindFirstEntityWithTag("king")
    if find then
        local x, y, z = find.Transform:GetWorldPosition()
        inst.player_classified.MapExplorer:RevealArea(x, y, z)
    end

end

AddPrefabPostInit("world", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end

    inst:ListenForEvent("ms_newplayerspawned", function(world, player)
        local mapexplorer = player:DoTaskInTime(3, MapExplorer)

    end)
end)

 

it just makes the server lag and not work i tried leaving it on for more than 50 minutes but it doesn't work

20 hours ago, Dezcoo said:

Isen't there like a better way,can't you give someone cartographer's desk map scroll with full map and make them read it so it doesn't make the whole game lag?

Sharing map with cartographer's desk map scroll depending on how much map the player has revealed and if the player using it has very little map revealed will cause lag spike too for the entire game.

There's no avoiding lag spike when revealing the entire map unfortunately it's a demanding process on the server I assume which is why it causes lag for everybody

2 hours ago, . . . said:

There's no avoiding lag spike when revealing the entire map unfortunately it's a demanding process on the server I assume which is why it causes lag for everybody

you can avoid it by starting a new thread

5 hours ago, Dezcoo said:

how you do that though

 

function EntityScript:StartThread(fn)
    return StartThread(fn, self.GUID)
end

 

AddPrefabPostInit("world", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end

    inst:ListenForEvent("ms_newplayerspawned", function(world, player)
        player:StartThread(function() 
            for x = -1600, 1600, 35 do for y = -1600, 1600, 35 do
                player.player_classified.MapExplorer:RevealArea(x, 0, y)
            end
        end)
    end)
end)

 

  • Like 1
13 hours ago, _zwb said:

 

function EntityScript:StartThread(fn)
    return StartThread(fn, self.GUID)
end

 

AddPrefabPostInit("world", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end

    inst:ListenForEvent("ms_newplayerspawned", function(world, player)
        player:StartThread(function() 
            for x = -1600, 1600, 35 do for y = -1600, 1600, 35 do
                player.player_classified.MapExplorer:RevealArea(x, 0, y)
            end
        end)
    end)
end)

 

i just get brackets error when i run it

-- AddPrefabPostInit is used to modify the "world" prefab after its initialization
AddPrefabPostInit("world", function(inst)
    -- Ensure this code only runs on the master simulation
    if not TheWorld.ismastersim then
        return inst
    end

    -- Function to progressively reveal the map using a coroutine
    local function RevealMapCoroutine(player)
        local min_x, max_x = -1600, 1600
        local min_y, max_y = -1600, 1600
        local step = 100    -- Size of each chunk
        local delay = 0.1   -- Delay in seconds between reveals

        for x = min_x, max_x, step do
            for y = min_y, max_y, step do
                if player.player_classified and player.player_classified.MapExplorer then
                    player.player_classified.MapExplorer:RevealArea(x, 0, y)
                else
                    print("Error: MapExplorer not found for player " .. tostring(player.GUID))
                    return
                end
            end
            -- Yield to avoid locking up the server; this simulates running on a separate thread
            Sleep(delay)
        end
    end

    -- Listen for the event when a new player spawns
    inst:ListenForEvent("ms_newplayerspawned", function(world, player)
        -- Start a coroutine (simulated thread) to progressively reveal the map
        player:StartThread(function()
            -- Run the map reveal coroutine
            local reveal_thread = coroutine.create(function() RevealMapCoroutine(player) end)
            
            while coroutine.status(reveal_thread) ~= "dead" do
                local success, err = coroutine.resume(reveal_thread)
                if not success then
                    print("Coroutine error: " .. tostring(err))
                    break
                end
                -- Yield control to avoid blocking
                Sleep(0.1)
            end
        end)
    end)
end)

this is what chat gpt came up with but no matter what i do the server is frozen still if someone wants to help please

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...