Jump to content

How to add MapExplorer to an entity? (Possible bugs with current RevealArea?)


Recommended Posts

I am using the following codes from Global Position to create an entity with a mapexplorer.

-- The file scripts/prefabs/worldmapexplorer.lua
local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddMapExplorer()
    inst.entity:AddNetwork()
    inst.entity:SetCanSleep(false)
    inst.entity:Hide()
    inst:AddTag("CLASSIFIED")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
      return inst
    end

    inst.persists = false

    return inst
end

return Prefab("worldmapexplorer", fn)

Then in the modmain.lua, simply use

AddPrefabPostInit("world", function(inst)
	inst.worldmapexplorer = GLOBAL.SpawnPrefab("worldmapexplorer")
end)

I met a strange phenomenon. The following are steps to reproduce them:

1. Reveal areas in the map to the TheWorld.worldmapexplorer by typing these to the console: 

Spoiler

local m=TheWorld.worldmapexplorer.MapExplorer local w,h = TheWorld.Map:GetSize() for x=-w*2,w,10 do for z=-h*2,h,10 do if TheWorld.Map:IsValidTileAtPoint(x,0,z) and m then m:RevealArea(x,0,z) end end end

2. Go to the cave, and return back. (This is necessary, if the player stays in the same world, repeating the third step does not produce unexcepted results)

3. Call RevealArea, and after calling the RevealAread once, all the data in the TheWorld.worldmapexplorer is lost. You can run the following codes in the console to call RevealArea. Run the following codes again to check the data in the TheWorld.worldmapexplorer.

Spoiler

print("before RevealArea") print(TheWorld.worldmapexplorer.MapExplorer:RecordMap()) TheWorld.worldmapexplorer.MapExplorer:RevealArea(0, 0, 0) print("after RevealArea") print(TheWorld.worldmapexplorer.MapExplorer:RecordMap())

Link to comment
Share on other sites

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
 Share

×
  • Create New...