Page 1 of 1

PvP scenario help needed

Posted: Sun May 14, 2017 9:27 pm
by orzelek
I've been asked to add support for PvP scenario to RSO.
I'm not sure how to do that currently - anyone knows if there is a way to figure out where players start to be able to spawn starting locations for them?

Re: PvP scenario help needed

Posted: Sun May 14, 2017 9:34 pm
by Klonan
orzelek wrote:I've been asked to add support for PvP scenario to RSO.
I'm not sure how to do that currently - anyone knows if there is a way to figure out where players start to be able to spawn starting locations for them?
Each force is given a unique spawn position based on what settings the player chooses,

So to get each spawn position you will need to worry about, look through the teams like this:

Code: Select all

for k, team in pairs(global.teams) do
  local force = game.forces[team.name]
  if force then
    make_spawn(force.get_spawn_position(global.surface))
  end
end
The PvP script itself will still need to be edited to support some custom spawning like this, but i don't think you will need to worry about that

Re: PvP scenario help needed

Posted: Sun May 14, 2017 9:42 pm
by orzelek
You used global.teams and global.surface there - I'm assuming those are from PvP scenario script.

I looked a bit and do I see correctly that when player is created I should have all the data needed to spawn starting area under him?
And would it work in PvP scenario in this way?
I would monitor players spawning and if I see new location I haven't spawned yet I would add new starting area there.

This could have side effects.. if someone creates players in different context then actually spawning them in game. But it's the best approach I see currently.

Re: PvP scenario help needed

Posted: Sun May 14, 2017 10:15 pm
by Klonan
orzelek wrote:You used global.teams and global.surface there - I'm assuming those are from PvP scenario script.

I looked a bit and do I see correctly that when player is created I should have all the data needed to spawn starting area under him?
And would it work in PvP scenario in this way?
I would monitor players spawning and if I see new location I haven't spawned yet I would add new starting area there.

This could have side effects.. if someone creates players in different context then actually spawning them in game. But it's the best approach I see currently.
It would be best i think to listen to 'on_player_changed_force',
As when a player joins, he is not immediately moved to the new force,

Then once a player joins that force, you can check if you have already created a starting area for that force, and if not, create one

Re: PvP scenario help needed

Posted: Mon May 15, 2017 11:50 am
by orzelek
Few questions:
1. Would this also work in single player? I'm assuming it should since player is in some force always.
2. How do I know whats the surface with starting location for force? Interface to get it requires surface and from what I see in pvp scenario I can't use nauvis since scenario is using more surfaces.

Re: PvP scenario help needed

Posted: Mon May 15, 2017 1:38 pm
by Klonan
orzelek wrote:Few questions:
1. Would this also work in single player? I'm assuming it should since player is in some force always.
2. How do I know whats the surface with starting location for force? Interface to get it requires surface and from what I see in pvp scenario I can't use nauvis since scenario is using more surfaces.
In single player they are still put on a team in global.teams,
The surface can be found with 'on_player_surface_changed'

If you'd prefer, work on a solution that is good for you, and i can add the necessary remote interface to the PvP script,
And/or any custom events you would like to listen to, such as an event for when the map is ready, or an event when the round is over etc.

Re: PvP scenario help needed

Posted: Tue May 16, 2017 10:31 am
by orzelek
Main problem I see now would be that there is no event that gives all the required information at once.
To generate starting area I need position and surface - from what you wrote it seems that those could be grabbed from two separate events.
If there is a guarantee that both of those events happen every time round is started then I could work with them I think. I would also need to detect when surface is regenerated when round changes - I think there is an event on surface destruction. If surface is reused then I'd need to have a way of detecting that round has ended to clear up previous round starting positions.