Restricting spectators exploration
Restricting spectators exploration
In general terms, I understand how to create spectators, and stop them from crafting, prevent them having inventory, stop them mining, changing recipes in assemblers etc.
I'd like them to be able to move about and explore the factory, but I'd also like to stop them from moving outside the revealed area of the map, and revealing it to the other players. How can I do this?
I'd like them to be able to move about and explore the factory, but I'd also like to stop them from moving outside the revealed area of the map, and revealing it to the other players. How can I do this?
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restricting spectators exploration
I was going to say "just watch if they move too far outwards, then teleport them back"...but apparently god controllers don't currently raise on_player_changed_position. I filed a bug report on that. If it's fixed you should be able to do:
With appropriate position values of course.
Code: Select all
/c script.on_event(defines.events.on_player_changed_position,function(e) local p = game.players[e.player_index] print(serpent.line(p.position)) if math.abs(p.position.x) > 100 or math.abs(p.position.y) > 100 then p.teleport({0,0}) end end)
Re: Restricting spectators exploration
By god controllers do you also mean....eradicator wrote:I was going to say "just watch if they move too far outwards, then teleport them back"...but apparently god controllers don't currently raise on_player_changed_position. I filed a bug report on that. If it's fixed you should be able to do:With appropriate position values of course.Code: Select all
/c script.on_event(defines.events.on_player_changed_position,function(e) local p = game.players[e.player_index] print(serpent.line(p.position)) if math.abs(p.position.x) > 100 or math.abs(p.position.y) > 100 then p.teleport({0,0}) end end)
Code: Select all
defines.controllers.ghost Can't interact with the world, can only observe. Used in the multiplayer waiting-to-respawn screen.
That was the one I was gravitating towards for a spectator. You don't have to mess with a lot of other permissions and settings then. Also I don't want to keep teleporting them, I want them to move freely, but I don't want them activating and revealing new chunks by moving to the edge of the revealed map.
Re: Restricting spectators exploration
There is some code in the vanilla PvP scenario that uses the on_tick event to decide whether or not to 'chart' the surface depending on a player's force, but I cannot figure it out. Where is the default 'chart' being suppressed, if at all?
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Restricting spectators exploration
Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restricting spectators exploration
No, i meant the actual defines.controllers.god controller, the one that you have in sandbox or when you destroy() your game.player.character in freeplay. I didn't know there was a special ghost controller.
I took a quick look at the pvp scenario and it appears that they just put spectators into a different force, which makes sense if you want them to see both/all teams. I doubt that prevents them from exploring or generating new map areas though, unless the ghost controller class is internally programmed to be unable to generate new chunks.
The idea with teleporting was that you can check if they leave a bounding box, and if they attempt to leave it to just teleport them back inside (i.e. a few meters back). You wouldn't constantly be teleporting them, only when they're attempting to get out of the box.
I took a quick look at the pvp scenario and it appears that they just put spectators into a different force, which makes sense if you want them to see both/all teams. I doubt that prevents them from exploring or generating new map areas though, unless the ghost controller class is internally programmed to be unable to generate new chunks.
The idea with teleporting was that you can check if they leave a bounding box, and if they attempt to leave it to just teleport them back inside (i.e. a few meters back). You wouldn't constantly be teleporting them, only when they're attempting to get out of the box.
Re: Restricting spectators exploration
And the code that seems to try and stop it in the PvP on_tick event handler seems broken too.bobingabout wrote:Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
Re: Restricting spectators exploration
The code doesn't try to stop it, it has nothing to do with preventing spectators from revealing chunksDRY411S wrote:And the code that seems to try and stop it in the PvP on_tick event handler seems broken too.bobingabout wrote:Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
Re: Restricting spectators exploration
My interpretation of the PvP on_tick code is that there is an attempt to stop the generated chunk from being charted.eradicator wrote:I didn't know there was a special ghost controller.
I took a quick look at the pvp scenario and it appears that they just put spectators into a different force, which makes sense if you want them to see both/all teams. I doubt that prevents them from exploring or generating new map areas though, unless the ghost controller class is internally programmed to be unable to generate new chunks.
Re: Restricting spectators exploration
OK thanks for confirming that. Is there a way of preventing spectators from revealing chunks?Klonan wrote:The code doesn't try to stop it, it has nothing to do with preventing spectators from revealing chunksDRY411S wrote:And the code that seems to try and stop it in the PvP on_tick event handler seems broken too.bobingabout wrote:Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
My guess was that the check_spectator_chart() function called in on_tick is to somehow stop the charting of the surface to spectators, with references to fog_of_war, but it appears to force (no pun intended) the surface to be charted if spectators are connected?
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restricting spectators exploration
It simply automatically charts the whole surface for the spectator force, so they don't have to constantly move around to get an up-to-date-map. And to save resources it skips that steps if there are no spectators.
Back to topic... as of the next version the ghost controller will raise on_player_changed correctly, so my original suggestion will work.
Back to topic... as of the next version the ghost controller will raise on_player_changed correctly, so my original suggestion will work.
Re: Restricting spectators exploration
Aha! So until then, one way to stop spectators from revealing chunks would be to prevent them from moving at all, and require them to use map view for anything beyond their line of sight.eradicator wrote:It simply automatically charts the whole surface for the spectator force, so they don't have to constantly move around to get an up-to-date-map. And to save resources it skips that steps if there are no spectators.
Back to topic... as of the next version the ghost controller will raise on_player_changed correctly, so my original suggestion will work.
Re: Restricting spectators exploration
Something like this would appear to work, though I haven't been able to check in multiplayer yet. It fixes the player at the origin of the map, as a 'ghost' unable to start walking, so their only interaction with the game is via the map view.
Code: Select all
-- Player wants to spectate
local character = player.character
player.character = nil
if character then character.destroy() end
player.set_controller{type = defines.controllers.ghost}
local spectator = game.create_force("spectator")
local permission = game.permissions.create_group("spectator")
permission.set_allows_action(defines.input_action.start_walking,false)
permission.add_player(player)
player.force = "spectator"
player.teleport({0,0}, "nauvis")
Re: Restricting spectators exploration
Yes, and it charts parts of the map that no player or radar has revealed, which is the exact opposite of what I want.eradicator wrote:It simply automatically charts the whole surface for the spectator force, so they don't have to constantly move around to get an up-to-date-map. And to save resources it skips that steps if there are no spectators.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restricting spectators exploration
It charts all chunks of the world that have been generated so far. Not more not less. It doesn't generate new chunks. It might look "bigger" to you because the game pre-generates chunks outside of the charted range of any force up to a certain distance.
Re: Restricting spectators exploration
Yep I understand that. The ghost controller mode with unrestricted movement generates new chunks and reveals large parts of the map. The ghost mode with restricted movement reveals generated, but previously uncharted chunks of the map using that function in the PvP scenario.eradicator wrote:It charts all chunks of the world that have been generated so far. Not more not less. It doesn't generate new chunks. It might look "bigger" to you because the game pre-generates chunks outside of the charted range of any force up to a certain distance.
I want spectators to have revealed to them, only chunks that have been revealed to non-spectators. I don't want spectators acting like a 'radar', able to give secrets away to players by pinging them with information that their force cannot see.
If a spectatator force is allied with all other forces, do spectators 'inherit' what other forces have revealed? Or will I need to do that programmatically?
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restricting spectators exploration
I have no clue. Either way imho your method of allowing only map view to spectators is not feasible. Map view does not show anything that is not actively revealed by a radar or another player, and continously recharting the whole map to keep it visible costs too much cpu. So unless i'm missing something a movement restriction method still sounds like the only feasible way to me.DRY411S wrote: If a spectatator force is allied with all other forces, do spectators 'inherit' what other forces have revealed? Or will I need to do that programmatically?
Re: Restricting spectators exploration
I've got a solution now that I'm reasonably happy with. My requirement is for a co-op scenario I'm planning on writing. Because it's co-op, all players and spectators can be in the same force. It's not wasn't what I originally wanted, but it'll work.eradicator wrote:I have no clue. Either way imho your method of allowing only map view to spectators is not feasible. Map view does not show anything that is not actively revealed by a radar or another player, and continously recharting the whole map to keep it visible costs too much cpu. So unless i'm missing something a movement restriction method still sounds like the only feasible way to me.
Players who choose to be spectators are just restricted from moving and have ghost controllers. The map is revealed to them as the other players reveal it.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restricting spectators exploration
Are the spectators supposed to interact with the players? What i meant is that while a player can at any time chose to go somewhere without radar coverage to see what's going on, a spectator is forced to follow a player manually because otherwise he won't be able to see anything. Also personally i couldn't stand watching the map "snow" shader all the time :P.DRY411S wrote: Players who choose to be spectators are just restricted from moving and have ghost controllers. The map is revealed to them as the other players reveal it.
Re: Restricting spectators exploration
My view of what a spectator is that they can watch what other players do, and can see what other players can see. They shouldn't be able to go to parts of the map or see what hasn't been revealed to the players. They shouldn't be some kind of spy satelliteeradicator wrote:
Are the spectators supposed to interact with the players? What i meant is that while a player can at any time chose to go somewhere without radar coverage to see what's going on, a spectator is forced to follow a player manually because otherwise he won't be able to see anything. Also personally i couldn't stand watching the map "snow" shader all the time .
I'd expect them to interact via console or things like Discord.