1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

moved walkabout

This commit is contained in:
Valansch 2017-07-08 23:06:39 +02:00
parent f8f5eb340a
commit 7574025466
2 changed files with 77 additions and 73 deletions

View File

@ -36,79 +36,7 @@ function player_joined(event)
end
function walkabout(player_name, distance)
if distance == nil then
--game.print("Specify rough distance for the walkabout.")
distance = math.random(5000, 10000)
return
end
if distance == "close" then
distance = math.random(3000, 7000)
else
if distance == "far" then
distance = math.random(7000, 11000)
else
if distance == "very far" then
distance = math.random(11000, 15000)
else
game.print("Walkabout failed.")
return
end
end
end
local x = 1
while game.players[x] ~= nil do
local player = game.players[x]
if player_name == player.name then
local repeat_attempts = 5
local r = 1
local surface = game.surfaces[1]
local distance_max = distance * 1.05
local distance_min = distance * 0.95
distance_max = round(distance_max, 0)
distance_min = round(distance_min, 0)
--while r <= repeat_attempts do
x = math.random(distance_min, distance_max)
if 1 == math.random(1, 2) then
x = x * -1
end
y = math.random(distance_min, distance_max)
if 1 == math.random(1, 2) then
y = y * -1
end
if 1 == math.random(1, 2) then
z = distance_max * -1
x = math.random(z, distance_max)
else
z = distance_max * -1
y = math.random(z, distance_max)
end
--r = r + 1
--local tile = surface.get_tile(x,y)
--game.print(tile.name)
--if tile.name == "deep-water" or tile.name == "water" then
--if r >= repeat_attempts then
--game.print(player_name .. " tried to go on a walkabout, but could only find water.")
--return
--end
--else
local pos = {x, y}
player.teleport(pos)
game.print(player_name .. " went on a walkabout, to find himself.")
return
--end
--end
end
x = x + 1
end
game.print(player_name .. " could not go on a walkabout.")
game.player.print("This command moved to /walkabout.")
end
--function player_respawned(event)
--local player = game.players[event.player_index]

View File

@ -62,6 +62,81 @@ function kill()
game.player.character.die()
end
function walkabout(cmd)
if not game.player.admin then
cant_run(cmd.name)
return
end
params = {}
if cmd.parameter == nil then
game.print("Walkabout failed.")
return
end
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
local player_name = params[1]
local distance = ""
if params[3] == nil then
distance = params[2]
else
distance = params[2] .. " " .. params[3]
end
if distance == nil or distance == "" then
distance = math.random(5000, 10000)
end
if tonumber(distance) ~= nil then
elseif distance == "close" then
distance = math.random(3000, 7000)
elseif distance == "far" then
distance = math.random(7000, 11000)
elseif distance == "very far" then
distance = math.random(11000, 15000)
else
game.print("Walkabout failed.")
return
end
local x = 1
while game.players[x] ~= nil do
local player = game.players[x]
if player_name == player.name then
local repeat_attempts = 5
local r = 1
local surface = game.surfaces[1]
local distance_max = distance * 1.05
local distance_min = distance * 0.95
distance_max = round(distance_max, 0)
distance_min = round(distance_min, 0)
--while r <= repeat_attempts do
x = math.random(distance_min, distance_max)
if 1 == math.random(1, 2) then
x = x * -1
end
y = math.random(distance_min, distance_max)
if 1 == math.random(1, 2) then
y = y * -1
end
if 1 == math.random(1, 2) then
z = distance_max * -1
x = math.random(z, distance_max)
else
z = distance_max * -1
y = math.random(z, distance_max)
end
local pos = {x, y}
player.teleport(pos)
game.print(player_name .. " went on a walkabout, to find himself.")
return
end
x = x + 1
end
game.print(player_name .. " could not go on a walkabout.")
end
commands.add_command("kill", "Will kill you.", kill)
@ -69,3 +144,4 @@ commands.add_command("detrain", "<player> - Kicks the player off a train.", detr
commands.add_command("tpplayer", "<player> - Teleports you to the player.", teleport_player)
commands.add_command("invoke", "<player> - Teleports the player to you.", invoke)
commands.add_command("tppos", "Teleports you to a selected entity.", teleport_location)
commands.add_command("walkabout", '<player> - <"close", "far", "very far", number>', walkabout)