1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-16 02:46:55 +02:00

implemented rusky-pvp

This commit is contained in:
James Gillham 2017-09-02 10:09:42 +01:00
parent 9f49802aeb
commit 41ec0ec911
3 changed files with 205 additions and 0 deletions

View File

@ -18,6 +18,7 @@ require "nuke_control"
require "walk_distance"
require "on_tick"
require "follow"
require "rusky_pvp"

View File

@ -1 +1,28 @@
msg-intro=This is the Factorio freeplay. Your task is to launch a rocket into space. Do this by constructing a Rocket Silo and launching a rocket with a satellite. You will need to research advanced technologies in order to unlock the Rocket Silo. Start small, work your way up with automation and don't forget to protect yourself from the natives.
[gui]
rockets-sent=Rockets launched
score=Score
create-force=Create Team
new-force=Create
force=Team
invite=Invite
leave=Leave
[msg]
close-position=This position is to close from another force!
force-created=New team created!
invalid-name=Player name not found!
player-invated=Player __1__ has been invited to your team
you-invated=You have been invited by __1__
force-destroyed=Your team has been destroyed!
force-leave="You have abandoned your team!
force-leave-confim=Input "leave" in text field then click leave button to abandoned your team!
info1=You can create your own team OR wait for another invitation
info2=Select location for the base and click button "Create"
info3=Spawn point will be installed where you stand
info4=Bitters will run away from you
info5=Do not click button if you are waiting for an invitation!
info11=You can invite player: input thier name and click "Invite"
info12=You can leave team: click "Leave"
rocket-launched-without-satellite=You launched the rocket, but you didn't put a satellite inside.

177
rusky_pvp.lua Normal file
View File

@ -0,0 +1,177 @@
Event.register(-1,function()
global.players = {}
game.forces.enemy.set_cease_fire(game.forces.player ,true);
game.forces.player.disable_research();
game.forces.player.disable_all_prototypes();
game.forces.player.set_ammo_damage_modifier("rocket", -3);
end)
Event.register(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
--player.print("Info: PVP server mod 'Bearded Snails' (c) byte");
guiNewPlayer(player.gui.left);
printNewPlayer(player);
player.insert{name="heavy-armor", count=1}
player.insert{name="iron-plate", count=8}
player.insert{name="pistol", count=1}
player.insert{name="firearm-magazine", count=10}
player.insert{name="burner-mining-drill", count = 1}
player.insert{name="stone-furnace", count = 1}
player.insert{name="shotgun", count = 1}
player.insert{name="shotgun-shell", count = 10}
player.character.character_running_speed_modifier = 0.5
player.force.chart(player.surface, {{player.position.x - 200, player.position.y - 200}, {player.position.x + 200, player.position.y + 200}})
end)
Event.register(defines.events.on_player_respawned, function(event)
local player = game.players[event.player_index]
player.insert{name="heavy-armor", count=1}
player.insert{name="pistol", count=1}
player.insert{name="firearm-magazine", count=10}
player.insert{name="shotgun", count = 1}
player.insert{name="shotgun-shell", count = 10}
player.character.character_running_speed_modifier = 0.5
end)
Event.register(defines.events.on_rocket_launched, function(event)
local force = event.rocket.force
if event.rocket.get_item_count("satellite") > 0 then
if global.satellite_sent == nil then
global.satellite_sent = {}
end
if global.satellite_sent[force.name] == nil then
game.set_game_state{game_finished=true, player_won=true, can_continue=true}
global.satellite_sent[force.name] = 1
else
global.satellite_sent[force.name] = global.satellite_sent[force.name] + 1
end
for index, player in pairs(force.players) do
if player.gui.left.rocket_score == nil then
local frame = player.gui.left.add{name = "rocket_score", type = "frame", direction = "horizontal", caption={"gui.score"}}
frame.add{name="rocket_count_label", type = "label", caption={"", {"gui.rockets-sent"}, ":"}}
frame.add{name="rocket_count", type = "label", caption=tostring(global.satellite_sent[force.name])}
else
player.gui.left.rocket_score.rocket_count.caption = tostring(global.satellite_sent[force.name])
end
end
else
for index, player in pairs(force.players) do
player.print({"msg.gui-rocket-silo.rocket-launched-without-satellite"})
end
end
end)
Event.register(defines.events.on_gui_click, function(event)
local player = game.players[event.player_index]
local gui = player.gui.left;
if player.force == game.forces.player and event.element.name == "new_button" then
if neForceNear(player.position) then
local force = game.create_force(player.name);
force.set_spawn_position(player.position, game.surfaces[1]);
player.force = force;
killBitters(player.position);
player.force.chart(player.surface, {{player.position.x - 200, player.position.y - 200}, {player.position.x + 200, player.position.y + 200}})
player.force.set_ammo_damage_modifier("rocket", -3);
player.force.research_all_technologies();
gui.new_force.destroy();
guiForcePlayer(gui);
player.print{"msg.force-created"}
printForcePlayer(player)
else
player.print{"msg.close-position"}
end
elseif event.element.name == "inv_button" then
local name = gui.own_force.inv_name.text;
if name ~= nil and validPlayer(name) then
local iplayer = game.players[name];
local igui = iplayer.gui.left;
iplayer.force = player.force;
iplayer.teleport(player.force.get_spawn_position(game.surfaces[1]));
igui.new_force.destroy();
guiForcePlayer(igui);
player.print{"msg.player-invated", name}
iplayer.print{"msg.you-invated", player.name}
else
player.print{"msg.invalid-name"}
end
elseif event.element.name == "leave_button" and gui.own_force.inv_name.text == "leave" then
if #player.force.players == 1 then
game.merge_forces(player.force.name, game.forces.player.name);
gui.own_force.destroy();
guiNewPlayer(gui);
player.print{"msg.force-destroyed"}
elseif #player.force.players > 1 then
player.force = game.forces.player;
player.character.die();
gui.own_force.destroy();
guiNewPlayer(gui);
player.print{"msg.force-leave"}
end
elseif event.element.name == "leave_button" and gui.own_force.inv_name.text ~= "leave" then
player.print{"msg.force-leave-confim"}
end
end)
function neForceNear(pos)
for k, v in pairs(game.forces) do
if dist(pos, v.get_spawn_position(game.surfaces[1])) <= 50 then
return false;
end
end
return true;
end
function killBitters(pos)
for k, v in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x - 250, pos.y - 250}, {pos.x + 250, pos.y + 250}}, force= "enemy"})) do
v.destroy();
end
end
function dist(position1, position2)
return ((position1.x - position2.x)^2 + (position1.y - position2.y)^2)^0.5
end
function validPlayer(name)
if name ~= nil and game.players[name] ~= nil and game.players[name].force == game.forces.player then
return true;
end
return false;
end
function guiNewPlayer(gui)
local frame = gui.add{type="frame", name="new_force", caption={"gui.create-force"}, direction="vertical"}
frame.add{type="button", name="new_button", caption={"gui.new-force"}}
end
function guiForcePlayer(gui)
local frame = gui.add{type="frame", name="own_force", caption={"gui.force"}, direction="vertical"}
frame.add{type="textfield", name="inv_name"}
frame.add{type="button", name="inv_button", caption={"gui.invite"}}
frame.add{type="button", name="leave_button", caption={"gui.leave"}}
end
function printNewPlayer(player)
--player.print{"msg.info13"}
--player.print{"msg.info14"}
player.print{"msg.info1"}
player.print{"msg.info2"}
player.print{"msg.info3"}
player.print{"msg.info4"}
player.print{"msg.info5"}
--player.print{"msg.info6"}
--player.print{"msg.info7"}
--player.print{"msg.info8"}
end
function printForcePlayer(player)
player.print{"msg.info11"}
player.print{"msg.info12"}
end