Jump to content

How to check if player is using the map?


Recommended Posts

Hello, if someone can help me out with this that'd be nice!

So, is there a way to check if the player is using the map?

In my function I want to change my character's minimap icon but only when the player's map is open

Spoiler

local function MapIconAnimate(inst)
	--if inst.HUD and inst.HUD:IsMapScreenOpen() then return end
	if inst.components.playercontroller == nil then return end
	
	inst.MiniMapEntity:SetIcon("vyu5.tex")
	inst:DoTaskInTime(.06, function() inst.MiniMapEntity:SetIcon("vyu4.tex") end)
	inst:DoTaskInTime(.12, function() inst.MiniMapEntity:SetIcon("vyu3.tex") end)
	inst:DoTaskInTime(.18, function() inst.MiniMapEntity:SetIcon("vyu2.tex") end)
	inst:DoTaskInTime(.24, function() inst.MiniMapEntity:SetIcon("vyu1.tex") end)
	inst:DoTaskInTime(.3, function() inst.MiniMapEntity:SetIcon("vyu2.tex") end)
	inst:DoTaskInTime(.36, function() inst.MiniMapEntity:SetIcon("vyu3.tex") end)
	inst:DoTaskInTime(.42, function() inst.MiniMapEntity:SetIcon("vyu4.tex") end)
	inst:DoTaskInTime(.48, function() inst.MiniMapEntity:SetIcon("vyu5.tex") end)
	inst:DoTaskInTime(.54, function() inst.MiniMapEntity:SetIcon("vyu6.tex") end)
end

 

I tried using code like this

Spoiler

if inst.HUD and inst.HUD:IsMapScreenOpen() then return end

 

but for some reason it doesn't work? As if I remove the " if inst.components.playercontroller == nil then return end " then  spawned in of my player prefab will activate this function even though they're obviously not using the map, thanks for your time :wilson_dorky:!

Edited by SuperDavid
Link to comment
Share on other sites

That's strange, when I try using "inst.HUD:IsMapScreenOpen()" in my local function the game crashes saying attempt to index field 'HUD' (a nil value)

Then I use this code as a test

local function MapIconAnimate(inst)
	if inst.HUD and inst.HUD:IsMapScreenOpen() then
		inst.components.talker:Say(GetString(inst, "ANNOUNCE_WINTER"))
	end 
end

--inside masterpostinit
inst:DoPeriodicTask(1.3, MapIconAnimate)

& I'm pretty sure when you're in the map your character can still talk, but my character said nothing while I was in the map.. this is so weird, thanks though :wilson_dorky:!

Edited by SuperDavid
Link to comment
Share on other sites

well a new crash has emerged

attempt to index local 'inst' (a nil value) "

Spoiler

local function MapIconAnimate(inst)
	local inst = ThePlayer
	if inst.HUD:IsMapScreenOpen() then return end
	if inst.sneaking == true or inst.components.playercontroller == nil or not inst.components.sanity:IsSane() then return end
	
	inst.MiniMapEntity:SetIcon("vyu5.tex")
	inst:DoTaskInTime(.06, function() inst.MiniMapEntity:SetIcon("vyu4.tex") end)
	inst:DoTaskInTime(.12, function() inst.MiniMapEntity:SetIcon("vyu3.tex") end)
	inst:DoTaskInTime(.18, function() inst.MiniMapEntity:SetIcon("vyu2.tex") end)
	inst:DoTaskInTime(.24, function() inst.MiniMapEntity:SetIcon("vyu1.tex") end)
	inst:DoTaskInTime(.3, function() inst.MiniMapEntity:SetIcon("vyu2.tex") end)
	inst:DoTaskInTime(.36, function() inst.MiniMapEntity:SetIcon("vyu3.tex") end)
	inst:DoTaskInTime(.42, function() inst.MiniMapEntity:SetIcon("vyu4.tex") end)
	inst:DoTaskInTime(.48, function() inst.MiniMapEntity:SetIcon("vyu5.tex") end)
	inst:DoTaskInTime(.54, function() inst.MiniMapEntity:SetIcon("vyu6.tex") end)
end

--masterpostinit
inst:DoPeriodicTask(1.3, MapIconAnimate)

 

still thanks for the help mate :D!!

Link to comment
Share on other sites

When do you get the error message? I'm guessing the function is running before ThePlayer is established and it's making it nil and may be what's causing the error. Normally if I need to troubleshoot these I'll add a print under the variable to see what it is. I would temporarily comment out the MapScreenOpen section and do...

local inst = ThePlayer
print (inst)

I can try to troubleshoot this when I get home tonight if you want to share your file.

Link to comment
Share on other sites

Hey I found out why it worked for you it's because the code "MapScreenOpen" seems to only work when in a non-caves world as it worked for me like that, but in a caves world it doesn't do anything.. also I did

local inst = ThePlayer print (inst)

and it said my character's name in console

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