REQ: Very Simple MP Mod Forces / friend Turrets -code inside

This is the place to request new mods or give ideas about what could be done.
User avatar
StoneLegion
Filter Inserter
Filter Inserter
Posts: 687
Joined: Fri Sep 05, 2014 7:34 pm
Contact:

REQ: Very Simple MP Mod Forces / friend Turrets -code inside

Post by StoneLegion »

EDIT: I lied the code I was given for the forces actually is part of a mod for RSO someone made here: https://forums.factorio.com/forum/vie ... 50#p102588

The 2nd reply I made to this thread was the working code at one time for forces.

So pretty much I would like a simple script that I don't have to worry about using commands to set players on their own team and to have friendly turrets. I have all the commands here as far as I know:

Example forces:

Code: Select all

/c game.local_player.force=game.forces.blue
/c game.local_player.force=game.forces.green

Example Friendly Turrets:

Code: Select all

/c local pforces = {}; for _, player in ipairs(game.players) do local fname = "player_" .. player.name; local force = game.forces[fname] or game.create_force(fname); player.force = force; for _, pforce in ipairs(pforces) do pforce.set_cease_fire(force.name, true); force.set_cease_fire(pforce.name, true) end; pforces[#pforces+1] = force end

I also would love this to be added someday too as a separate mod as maybe like a welding tool or something more for friendly servers so someone can claim a building back and forth maybe or a GUI option when you click the building:

Code: Select all

game.local_player.selected.force = game.forces["my force"]
Last edited by StoneLegion on Mon Sep 14, 2015 12:34 am, edited 1 time in total.
User avatar
StoneLegion
Filter Inserter
Filter Inserter
Posts: 687
Joined: Fri Sep 05, 2014 7:34 pm
Contact:

Re: REQ: Very Simple MP Mod Forces / friend Turrets -code inside

Post by StoneLegion »

I also have this really old code I forget its original from that is updated now to 0.12. I can't seem to quite get to work quite the same but it was for 0.11 forces but the idea here was it teleport players to a different base. Though with dedicated servers now this becomes a mess since I think if you joined first it place you at the other base lol.

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 player = game.players[playerIndex]
             if player.character then
             if playerIndex % 2 == 0 then
                   local position = player.surface.find_non_colliding_position("player", {-63,67}, 50, 1)
                   if position ~= nil then player.teleport(position) end
                else
                   local position = player.surface.find_non_colliding_position("player", {-159,-8105}, 50, 1)
                   if position ~= nil then player.teleport(position) end
             end
                global.deadPlayers[playerIndex] = nil
             end
       end
    end)

    game.on_event(defines.events.on_player_created, function(event)
       local player = game.players[event.player_index]
             if player.character then
             if event.player_index % 2 == 0 then
                   local position = player.surface.find_non_colliding_position("player", {-63,67}, 50, 1)
                   if position ~= nil then player.teleport(position) end
                else
                   local position = player.surface.find_non_colliding_position("player", {-159,-8105}, 50, 1)
                   if position ~= nil then player.teleport(position) end
             end
             end
    end)
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5406
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: REQ: Very Simple MP Mod Forces / friend Turrets -code inside

Post by Klonan »

I accept!

Im working on this, will post in here when I havea working prototype!

Thanks for posting all the code you know already, helps get the ball rolling ;)
User avatar
StoneLegion
Filter Inserter
Filter Inserter
Posts: 687
Joined: Fri Sep 05, 2014 7:34 pm
Contact:

Re: REQ: Very Simple MP Mod Forces / friend Turrets -code inside

Post by StoneLegion »

Thank you. Right now the 2nd code snip from the first post works perfectly for say 2 of us in a brand new game and that is what were using. Becomes derpy though if new players join in I find but it works perfectly just for a simple 2 player mp game with friendly turrets.

Would be neat overtime doubt possible code wise to make it so players can access and remove buildings and such but still be bound to the other player without having alerts happen for everyone. But baby steps :)
Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: REQ: Very Simple MP Mod Forces / friend Turrets -code inside

Post by Oxyd »

A lot of the forces support was based on “Let's just make a simple implementation for now and see how people like it, we can extend it later.” So if you have ideas about what forces could do in the future, by all means post them in the suggestions forum.
Post Reply

Return to “Ideas and Requests For Mods”