Skip to content

Commit

Permalink
Add spawn map command
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroKnight committed Jun 17, 2019
1 parent fb89b99 commit 4ec2335
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -32,6 +32,12 @@ Prints the current spawn point of the invoking user's force to the console.
Like `get`, but uses a `[gps]` tag, which shows the spawn point as a waypoint
on the map.

### map

`map`

Toggles a map tag (waypoint) showing the location of the spawn point.

### reset

`reset`
Expand Down
2 changes: 2 additions & 0 deletions api-dependencies.txt
@@ -1,5 +1,7 @@
Functions:
LuaForce.(set|get)_spawn_position
LuaForce.add_chart_tag
LuaCustomChartTag.destroy()

Events:
on_force_created
26 changes: 26 additions & 0 deletions commands.lua
Expand Up @@ -38,13 +38,22 @@ function command_spawn(command, args)
-- Defaults to current position if no arguments given
if pos.x and pos.y then
player.force.set_spawn_position(pos, 1)
update_map_tag(player, pos)
game.print{
(gps and "setspawn.spawn-point-set-gps" or "setspawn.spawn-point-set"),
player.force.name, pos.x, pos.y
}
else
game.print{"invalid-parameter"}
end
elseif subcommand == "map" then
-- Toggles map tag for the current spawn point
if global.map_tag[player.force.name] == nil then
set_map_tag(player, player.force.get_spawn_position(1))
else
global.map_tag[player.force.name].destroy()
global.map_tag[player.force.name] = nil
end
elseif subcommand == "get" or subcommand == "show" then
pos = player.force.get_spawn_position(1)
game.print{
Expand All @@ -54,6 +63,23 @@ function command_spawn(command, args)
elseif subcommand == "reset" then
pos = global.original_spawn[player.force.name]
player.force.set_spawn_position(pos, 1)
update_map_tag(player, pos)
game.print{"setspawn.spawn-point-reset", player.force.name, pos.x, pos.y}
end
end
function set_map_tag(player, pos)
global.map_tag[player.force.name] = player.force.add_chart_tag(1, {
position = pos,
text = "Spawn Point",
last_user = player
})
end
function update_map_tag(player, pos)
local tag = global.map_tag[player.force.name]
if tag then
global.map_tag[player.force.name].destroy()
set_map_tag(player, pos)
end
end
1 change: 1 addition & 0 deletions control.lua
Expand Up @@ -11,6 +11,7 @@ require('commands')
function do_init()
global.original_spawn = {}
global.map_tag = {}
update_original_spawns()
register_commands()
end
Expand Down
2 changes: 1 addition & 1 deletion locale/en/config.cfg
@@ -1,5 +1,5 @@
[setspawn]
help=<set / set x,y / set [gps=x,y] / set x y / get / show / reset> - Set, get or reset the spawn point for your current force, or show its location on the map.
help=<set / set x,y / set [gps=x,y] / set x y / get / show / map / reset> - Set, get or reset the spawn point for your current force, or show its location on the map.
spawn-point-set=Set spawn point for '__1__' force to {x: __2__, y: __3__}
spawn-point-set-gps=Set spawn point for '__1__' force to [gps=__2__,__3__]
spawn-point-get=Spawn point for '__1__' force: {x: __2__, y: __3__}
Expand Down

0 comments on commit 4ec2335

Please sign in to comment.