Page 1 of 1
Possible with custom Scenario?
Posted: Wed Jul 29, 2015 7:56 pm
by abregado
I'm designing some levels and was looking at scripting options. I have not yet found a way to do these things, so please do tell me if it is possible, or if you know a way to manage it.
1) Spawn each player of a multiplayer game in a different place
2) Constantly replenish an Assembler so it never runs out of materials (for 'off map' deliveries and production)
3) Disable a recipe for a player, but still allow it to be built in his Assemblers
4) Track the contents of a chest for scoring and objective purposes
5) Set all structures on the map to be 'Unminable' and 'Unoperable'
Re: Possible with custom Scenario?
Posted: Wed Jul 29, 2015 8:39 pm
by FishSandwich
Well, I can help you with #1, I'm not sure about 2-5, I think some are not possible yet.
Code: Select all
require "defines"
function init()
if not global.deadPlayers then
global.deadPlayers = {}
end
end
game.on_init(init)
game.on_load(init)
game.on_event(defines.events.on_entity_died, function(event)
if event.entity.type == "player" then
for index, player in ipairs(game.players) do
if not player.character and not global.deadPlayers[index] then
global.deadPlayers[index] = true
break
end
end
end
end)
game.on_event(defines.events.on_tick, function(event)
for playerIndex, value in pairs(global.deadPlayers) do
local char = game.players[playerIndex]
if char.character then
if playerIndex == 1 then
local position = char.surface.find_non_colliding_position("player", {-1,-188}, 50, 1)
if position ~= nil then char.teleport(position) end
elseif playerIndex == 2 then
local position = char.surface.find_non_colliding_position("player", {149,-42}, 50, 1)
if position ~= nil then char.teleport(position) end
end
global.deadPlayers[playerIndex] = nil
end
end
end)
game.on_event(defines.events.on_player_created, function(event)
local char = game.players[event.playerindex]
if char.character then
if event.playerindex == 1 then
local position = char.surface.find_non_colliding_position("player", {-1,-188}, 50, 1)
if position ~= nil then char.teleport(position) end
elseif event.playerindex == 2 then
local position = char.surface.find_non_colliding_position("player", {149,-42}, 50, 1)
if position ~= nil then char.teleport(position) end
end
end
end)
This will spawn players in predesignated coordinates of the map, and will also respawn them in those coordinates if they die.
You'll obviously need to change the coordinates(you can see the coordinates in the editor with F5 pressed) and expand it if you want it to work with more players.
Re: Possible with custom Scenario?
Posted: Wed Jul 29, 2015 8:54 pm
by jorgenRe
2) Constantly replenish an Assembler so it never runs out of materials (for 'off map' deliveries and production)
Yes, but you don't need to use an assembler to do it. If you can replenish its materials(which is possible) you can spawn in the products too

!
3) Disable a recipe for a player, but still allow it to be built in his Assemblers
Hmmm i'm not so sure about that, but it may work if there is some lua command to autoset recipe(il check so look for an update later)
4) Track the contents of a chest for scoring and objective purposes
Yes
5) Set all structures on the map to be 'Unminable' and 'Unoperable'
I guess with some coding you should be able to do it. Like if you set the structures on the enemy faction and then use lua to check everything that got destroyed and if they was in that force(enemy faction) they would instantly be replaced!
Re: Possible with custom Scenario?
Posted: Wed Jul 29, 2015 9:23 pm
by abregado
I managed to get 3 and 5 with one bit of code.
First I set all Assemblers on the map to use the game.forces.neutral force. Then I disable the recipes for the game.forces.player force. This map requires the player use Assemblers with fixed recipes that cant be moved. Some of them will need to be 'rescued' from the biters.
Code: Select all
game.on_init(function()
local s1 = game.get_surface("nauvis")
for i,e in ipairs(s1.find_entities{{-500, -500},{500, 500}}) do
e.destructible = false
e.minable = false
e.rotatable = false
e.operable = false
e.force = game.forces.neutral
end
local recipelist = game.forces.player.recipes
for i,v in pairs(recipelist) do
v.enabled = false
end
end
Handy hint, the game.player.findentities can no longer be used. You also don't seem to be able to reference the Surface via the player at init, so use get_surface('nauvis') which is the name of the default world.
Re: Possible with custom Scenario?
Posted: Wed Jul 29, 2015 9:26 pm
by abregado
FishSandwich wrote:Well, I can help you with #1
Thanks! This looks good. At some point I want to try to build a 'Lobby Surface' with teleports to different zones.
This particular map has 2-4 players on different islands with just indestructible conveyors and trains running between them. So I will create a list of spawn points, and cycle the spawns to even the players out. If more than 4 joining then they will start doubling up.
Re: Possible with custom Scenario?
Posted: Thu Jul 30, 2015 9:39 pm
by abregado
For number 2 I had considered checking contents each time a new item is produced. Any idea how one could add a custom event to listen for (on_item_assembled) ??
Re: Possible with custom Scenario?
Posted: Thu Jul 30, 2015 10:35 pm
by jorgenRe
abregado wrote:For number 2 I had considered checking contents each time a new item is produced. Any idea how one could add a custom event to listen for (on_item_assembled) ??
There is a can_insert function you can use.
Re: Possible with custom Scenario?
Posted: Mon Aug 10, 2015 9:10 am
by abregado
Ok, so far things are looking good.
3-5 Are done. Ive created a prototype level to demonstrate the idea. This level is designed for teams of students who should work together to build infrastructure for a factory to maximize its output.
I have not implemented the spawn system in this level but it seems to work AOK.
The level is for 12.1. Feedback appreciated!
https://www.dropbox.com/s/c4scxvzih6ini ... o.zip?dl=0
Re: Possible with custom Scenario?
Posted: Mon Aug 10, 2015 10:41 am
by jorgenRe
abregado wrote:Ok, so far things are looking good.
This level is designed for teams of students
Students :O!
Gosh those are some lucky students. Wish my teachers was like you

!
Re: Possible with custom Scenario?
Posted: Tue Aug 11, 2015 7:57 am
by abregado
Interesting, I just clicked on FishSandwichs 'Split Dependancies' series. Its a lot like what Im expecting the multiplayer to be like.
Fish: Did you find any gameplay issues with one area?
Did you find one player had too little to do?
if so, how did you combat it?
jorgenRe wrote:Gosh those are some lucky students. Wish my teachers was like you

!
Its a lot of fun, and the students really respect you as a teacher. I guess that is the hardest thing for a teacher to earn!
Re: Possible with custom Scenario?
Posted: Tue Aug 11, 2015 8:32 am
by jorgenRe
abregado wrote:Interesting, I just clicked on FishSandwichs 'Split Dependancies' series. Its a lot like what Im expecting the multiplayer to be like.
Fish: Did you find any gameplay issues with one area?
Did you find one player had too little to do?
if so, how did you combat it?
I watched their series and the biggest problem i think they had was doing the logistics between them
Its a mess to say it simply, but the series was fun

!
Re: Possible with custom Scenario?
Posted: Tue Aug 11, 2015 9:11 am
by FishSandwich
jorgenRe wrote:Fish: Did you find any gameplay issues with one area?
Did you find one player had too little to do?
if so, how did you combat it?
Sometimes we thought there was nothing to do, so we'd go and randomly fix issues in other 2 bases, or attack aliens. Apart from that, no real issues with it.
Re: Possible with custom Scenario?
Posted: Tue Aug 11, 2015 9:16 am
by abregado
FishSandwich wrote:
Sometimes we thought there was nothing to do, so we'd go and randomly fix issues in other 2 bases, or attack aliens. Apart from that, no real issues with it.
Ok, my levels wont have any aggressive combat in them, so I might have to entertain them some other way. Perhaps constant attacks and turret maintenance.