Page 1 of 1
Restricting spectators exploration
Posted: Tue Mar 13, 2018 9:07 pm
by DRY411S
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?
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 12:22 am
by eradicator
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:
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)
With appropriate position values of course.
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 12:52 am
by DRY411S
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:
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)
With appropriate position values of course.
By god controllers do you also mean....
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
Posted: Wed Mar 14, 2018 7:53 am
by DRY411S
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?
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 8:57 am
by bobingabout
Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 10:24 am
by eradicator
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.
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 10:13 pm
by DRY411S
bobingabout wrote:Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
And the code that seems to try and stop it in the PvP on_tick event handler seems broken too.
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 10:14 pm
by Klonan
DRY411S wrote:bobingabout wrote:Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
And the code that seems to try and stop it in the PvP on_tick event handler seems broken too.
The code doesn't try to stop it, it has nothing to do with preventing spectators from revealing chunks
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 11:02 pm
by DRY411S
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.
My interpretation of the PvP on_tick code is that there is an attempt to stop the generated chunk from being charted.
Re: Restricting spectators exploration
Posted: Wed Mar 14, 2018 11:03 pm
by DRY411S
Klonan wrote:DRY411S wrote:bobingabout wrote:Honestly, IMO, the fact that the ghost mode can uncover map feels like a bug to me.
And the code that seems to try and stop it in the PvP on_tick event handler seems broken too.
The code doesn't try to stop it, it has nothing to do with preventing spectators from revealing chunks
OK thanks for confirming that. Is there a way of preventing spectators from revealing chunks?
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?
Re: Restricting spectators exploration
Posted: Thu Mar 15, 2018 10:28 am
by eradicator
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
Posted: Thu Mar 15, 2018 5:06 pm
by DRY411S
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.
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.
Re: Restricting spectators exploration
Posted: Fri Mar 16, 2018 10:51 pm
by DRY411S
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
Posted: Sat Mar 17, 2018 6:16 pm
by DRY411S
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.
Yes, and it charts parts of the map that no player or radar has revealed, which is the exact opposite of what I want.
Re: Restricting spectators exploration
Posted: Sat Mar 17, 2018 6:37 pm
by eradicator
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
Posted: Sat Mar 17, 2018 7:01 pm
by DRY411S
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.
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.
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?
Re: Restricting spectators exploration
Posted: Sat Mar 17, 2018 9:31 pm
by eradicator
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?
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.
Re: Restricting spectators exploration
Posted: Sun Mar 18, 2018 7:18 am
by DRY411S
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.
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.
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
Posted: Sun Mar 18, 2018 9:30 am
by eradicator
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.
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.
Re: Restricting spectators exploration
Posted: Mon Mar 19, 2018 2:52 pm
by DRY411S
eradicator 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 
.
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 satellite
I'd expect them to interact via console or things like Discord.