Jump to content

deleting map progress for my character


Recommended Posts

hey there, so there is a problem im having with my code. i am trying to delete the map progress whenever he opens it

 

local master_postinit = function(inst)
	-- Set starting inventory
    inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default
	
	-- choose which sounds this character will play
	inst.soundsname = "webber"
	
	-- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    inst.talker_path_override = "dontstarve_DLC001/characters/"
	
	-- Stats	
	inst.components.health:SetMaxHealth(TUNING.WAWERLY_HEALTH)
	inst.components.hunger:SetMax(TUNING.WAWERLY_HUNGER)
	inst.components.sanity:SetMax(TUNING.WAWERLY_SANITY)
	
	-- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
	
	-- Hunger rate (optional)
	inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
	
	inst.OnLoad = onload
    inst.OnNewSpawn = onload
	
	inst:DoPeriodicTask(2.0, function(inst)
		ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
	end)
	
	function MapScreen:OnBecomeActive()
 		ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
	end
	
end

so:mapsceen:onbecomeactive is what i used until not long ago, and doperiodictask is what i used as a change, if the onbecomeactive would just not work (don't worry, i didn't use them together, i just had the onbecomeactive, then i deleted it, and replaced it with the periodictask).
thing is, none of them really work. it either deleted the progress for every character, or just crashed the game when i desperately tried to insert inst. before the ExecuteConsoleCommand. so i got a question, do you guys know how to delete my map progress after opening the map?

Link to comment
Share on other sites

I think the problem is that you are running these commands on the server, so not on the client that should lose the progress.

Try adding these functions to the common_postinit and then add them to 

if TheNet:GetIsClient() or not TheNet:GetServerIsDedicated() then

if TheNet:GetIsClient() or not TheNet:GetServerIsDedicated() then
  	inst:DoPeriodicTask(2.0, function(inst)
		ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
	end)
	--or
	function MapScreen:OnBecomeActive()
 		ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
	end
end

This way the code will only run on the client, where it should reset the progress.

  • Like 1
Link to comment
Share on other sites

Common_postinit is run on the client and on the server, contrary  to master_postinit which is only run on the server.

If you compare it to the fn of items, common_postinit is the same as everything that comes before

if not TheWorld.ismastersim then
	return inst
end

and everything that comes afterwards is like the master_postinit

  • Like 1
Link to comment
Share on other sites

Oh is it now deleting the map for each character? Then try this:

if inst.prefab == "yourcharacter" then	--replace with your character prefab
	if TheNet:GetIsClient() or not TheNet:GetServerIsDedicated() then
  		inst:DoPeriodicTask(2.0, function(inst)
			ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
		end)
		--or
		function MapScreen:OnBecomeActive()
 			ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
		end
	end
end

This should make it only run for your character.

  • Like 1
Link to comment
Share on other sites

So, since it fails to find the prefab name, I'm gonna check.

The prefab file is gonna be pretty much the file under scrips/prefabs/(for example)waxwell.lua. in that case the prefab name would be "waxwell", right? Or is there another way to get the name?

 

Link to comment
Share on other sites

nvm, i'm just gonna go straight to the code.
this is how my common_postinit looks like

local common_postinit = function(inst)
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "waverly.tex" )
    
    --tags
    inst:AddTag("waverly")
    
    if inst.prefab == "waverly" then
        if TheNet:GetIsClient() or not TheNet:GetServerIsDedicated() then
            function MapScreen:OnBecomeActive()
                    ExecuteConsoleCommand("TheWorld.minimap.MiniMap:ClearRevealedAreas()")
                    MapScreen._base.OnBecomeActive(self)

                if not TheWorld.minimap.MiniMap:IsVisible() then
                    TheWorld.minimap.MiniMap:ToggleVisibility()
                    end
                self.minimap:UpdateTexture()
            
            end
        end
    end
end

that is how it looks like. the thing below the ExecuteConsoleCommand is to have the circle around visible on the map.

 

i'm sorry it has to go for so long, my stupid brain couldnt find any tutorials on making stuff character only. i will let you be after this one, i swear, like you've already done alot

if you dont find anything wrong, im gonna take a big study on the inst.prefab function

Edited by sirrNaDE
Link to comment
Share on other sites

No worries, I'm happy to help!

I got you covered!

AddPlayerPostInit(function(inst)
        if TheNet:GetIsClient() or not TheNet:GetServerIsDedicated() then
            if inst.prefab == "waverly" then
                TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(true)
            else
                TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(false)
            end
        end
end)

The reason it didn't work was because the character initialization takes some time, that's why the prefab name was not there. If you add this function in DoTaskInTime(0,fn) it will work as the prefab name will be there.

When trying to get it to work, I found this nice function ContinuouslyClearRevealedAreas. I does what it's called, so no need to make complicated functions if you have there :D

I added it now in a AddPlayerPostInit fn as otherwise the map would be continualy cleared when changing character. When I tested it it was working as intented :)

If you have more questions, don't hesitate to ask!

  • Like 1
Link to comment
Share on other sites

well theres a problem

[string "../mods/Wawerly the lost and confused/modma..."]:73: attempt to index global 'TheNet' (a nil value)
LUA ERROR stack traceback:
        ../mods/Wawerly the lost and confused/modmain.lua(73,1) in function 'fn'
        scripts/modutil.lua(505,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(169,1) in function 'prefabpostinitany'
        scripts/mainfunctions.lua(322,1)	

line 73 is the:

if TheNet:GetIsClient() or not TheNet:GetServerIsDedicated() then
            

in other mods, people use GLOBAL.TheNet..., shouldnt it be there aswell?

Link to comment
Share on other sites

If you have errors like these, it's mostly the GLOBAL that is missing, as a lot of function are not in the environement of the modmain, so you just need a GLOBAL before.

Add this before the code snippet:

local TheNet = GLOBAL.TheNet
local TheWorld = GLOBAL.TheWorld

 

  • Like 2
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...