Page 1 of 1

game.is_multiplayer required

Posted: Fri Jan 26, 2018 4:03 am
by acabin
Because I'm working on a permission system, i'd like to let the people who load saves from singleplayer have admin and all permissions. Is that possible?

Re: game.is_multiplayer required

Posted: Fri Jan 26, 2018 6:46 am
by Rseding91
Loading a save from single player already has the player as an admin.

Re: game.is_multiplayer required

Posted: Fri Jan 26, 2018 10:20 pm
by acabin
As my test, loading a multiplayer game at singleplayer would not give the player admin permission, for he can't run /permissions.

edit:
The player had been added to a permission group already.

Re: game.is_multiplayer required

Posted: Fri Jan 26, 2018 11:09 pm
by Rseding91
acabin wrote:As my test, loading a multiplayer game at singleplayer would not give the player admin permission, for he can't run /permissions.

edit:
The player had been added to a permission group already.
That's not what you said - you said loading single player games in multiplayer.

Re: game.is_multiplayer required

Posted: Sun Jan 28, 2018 12:43 am
by acabin
Rseding91 wrote: That's not what you said - you said loading single player games in multiplayer.
It looks like my pool English leads to some misunderstood. I'll describe what I am doing:

1. Start a new game in MP
2. With the host's settings, my mod will move some players to a 'guest' group, which nearly can't do anything
3. If a 'guest' want to play the map offline, he will start a singleplayer game and load the save
4. In that case, I want to give the 'guest' all permissions and the player.admin flag

Now the problem:
I can't detect if the player is playing singleplayer or he is the only online player in a headless server.

So, I want a game.is_multiplayer or script.is_multiplayer flag or a way to check.

Re: game.is_multiplayer required

Posted: Mon Feb 05, 2018 4:45 am
by acabin
Is there any update? :D

Re: game.is_multiplayer required

Posted: Mon Feb 05, 2018 5:57 am
by Rseding91
acabin wrote:
Rseding91 wrote: That's not what you said - you said loading single player games in multiplayer.
It looks like my pool English leads to some misunderstood. I'll describe what I am doing:

1. Start a new game in MP
2. With the host's settings, my mod will move some players to a 'guest' group, which nearly can't do anything
3. If a 'guest' want to play the map offline, he will start a singleplayer game and load the save
4. In that case, I want to give the 'guest' all permissions and the player.admin flag

Now the problem:
I can't detect if the player is playing singleplayer or he is the only online player in a headless server.

So, I want a game.is_multiplayer or script.is_multiplayer flag or a way to check.
I see.

Unfortunately that's not going to be possible. That information isn't deterministic - the best you can do is detect if #game.players is > 1 but that's still not going to do it fully.

Re: game.is_multiplayer required

Posted: Mon Feb 05, 2018 6:01 am
by quyxkh
You could try something along the lines of (edit: the desync bilka warned about doesn't happen, but his instincts are good, fixed a lesser desync. but this stsill doesn't work: it appears on_player_joined _does_ fire in singleplayer loads of saved multiplayer maps. Oh, well.)
nope-doesnt-work

Re: game.is_multiplayer required

Posted: Mon Feb 05, 2018 7:36 am
by Bilka
quyxkh wrote:You could try something along the lines of

Code: Select all

joined_this_session =  {} -- control.lua gets rerun for each map init/load
script.on_event(defines.events.on_player_joined_game,function(ev) joined_this_session[ev.player_index]=true end)

-- setup so `/makemeaboss` in sp mode works right
function makemeaboss(cparms)
    if not joined_this_session[cparms.player_index]
    then -- your grant-boss-powers code here
    else game.print(game.players[cparms.player_index].name..' wants to be a boss.')
        end
    end
commands.add_command('makemeaboss',{'','use the source'},makemeaboss)
That's a fast and easy way to produce desyncs, congratulations. It should start desyncing on join after the second person joined, for the person that is joining. The person will be stuck in a desync loop and unable to ever join, unless the server is restarted and the person joins as the first person.

Re: game.is_multiplayer required

Posted: Mon Feb 05, 2018 9:25 am
by quyxkh
Testing shows it doesn't desync on load, it desyncs when a second player joins and the first player tries the command, because the second player wasn't there for the first player's join event. I fixed that by loading up the context when the client sees its first join event, I can't make it desync now.

But that doesn't help, because loading a save of an mp map in singleplayer mode fires on_player_joined_game anyway.

Anybody _really_ desperate to do this can just edit the mod locally.