addHook("MobjSpawn", function(mo) mo.todar = 0 end, MT_PLAYER)
local maptokens = CV_RegisterVar({"rouge_tokenradar", "On", CV_NETVAR, CV_OnOff})

    addHook("MapLoad", do
            maptokens = {}
            for mo in mobjs.iterate()
                    if mo.type == MT_TOKEN table.insert(maptokens, mo) end
            end
    end)
     
    addHook("ThinkFrame", do
            for player in players.iterate
                    if not player.mo continue end
 
                    if leveltime & 127 == 0 return end
 
                    local nearest, nearesttoken = nil, nil
                    for _, token in pairs(maptokens)
                            if not token.valid continue end
                                                        local distance = abs(FixedHypot(token.x - player.mo.x, FixedHypot(token.y - player.mo.y, token.z - player.mo.z)))
                            if nearest == nil or distance < nearest nearest = distance nearesttoken = token end
                    end
                    if not nearesttoken or nearest > 3000*FRACUNIT
                                player.mo.todar = 0 continue end
     
                    if nearest <= 3000 * FRACUNIT
                    and nearest >= 2001 * FRACUNIT
				player.mo.todar = 1
                    end
                    if nearest <= 2001 * FRACUNIT
                    and nearest >= 1700 * FRACUNIT
				player.mo.todar = 2
                    end
                    if nearest <= 1700 * FRACUNIT
                    and nearest >= 1500 * FRACUNIT
				player.mo.todar = 3
                    end
                    if nearest <= 1500 * FRACUNIT
                    and nearest >= 900 * FRACUNIT
				player.mo.todar = 4
                    end
                    if nearest <= 900 * FRACUNIT
                    and nearest >= 0 * FRACUNIT
				player.mo.todar = 5
                    end
            end
    end)

addHook("NetVars", function(net)
	maptokens=net($)
end)