From 4ec23350b6a23e206063141babb4e265058f1820 Mon Sep 17 00:00:00 2001 From: ZeroKnight Date: Mon, 17 Jun 2019 04:22:38 -0700 Subject: [PATCH] Add `spawn map` command --- README.md | 6 ++++++ api-dependencies.txt | 2 ++ commands.lua | 26 ++++++++++++++++++++++++++ control.lua | 1 + locale/en/config.cfg | 2 +- 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a292bc..871ea1a 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/api-dependencies.txt b/api-dependencies.txt index 7c34ee8..91bd802 100644 --- a/api-dependencies.txt +++ b/api-dependencies.txt @@ -1,5 +1,7 @@ Functions: LuaForce.(set|get)_spawn_position + LuaForce.add_chart_tag + LuaCustomChartTag.destroy() Events: on_force_created \ No newline at end of file diff --git a/commands.lua b/commands.lua index 743c0c1..b263cdf 100644 --- a/commands.lua +++ b/commands.lua @@ -38,6 +38,7 @@ 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 @@ -45,6 +46,14 @@ function command_spawn(command, args) 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{ @@ -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 \ No newline at end of file diff --git a/control.lua b/control.lua index 047cd7a..ba9b90b 100644 --- a/control.lua +++ b/control.lua @@ -11,6 +11,7 @@ require('commands') function do_init() global.original_spawn = {} + global.map_tag = {} update_original_spawns() register_commands() end diff --git a/locale/en/config.cfg b/locale/en/config.cfg index d17d3dc..b2f5155 100644 --- a/locale/en/config.cfg +++ b/locale/en/config.cfg @@ -1,5 +1,5 @@ [setspawn] -help= - Set, get or reset the spawn point for your current force, or show its location on the map. +help= - 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__}