<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://pandorabox.io/index.php?action=history&amp;feed=atom&amp;title=Protection_Script</id>
	<title>Protection Script - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pandorabox.io/index.php?action=history&amp;feed=atom&amp;title=Protection_Script"/>
	<link rel="alternate" type="text/html" href="https://pandorabox.io/index.php?title=Protection_Script&amp;action=history"/>
	<updated>2026-05-24T14:18:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://pandorabox.io/index.php?title=Protection_Script&amp;diff=3292&amp;oldid=prev</id>
		<title>SwissalpS: Created page with &quot; This script assists to calculate coordinates to protect a larger area with multiple smaller areas.  &lt;syntaxhighlight lang=&quot;Lua&quot;&gt; #!/usr/bin/lua -- Code to prepare coordinates...&quot;</title>
		<link rel="alternate" type="text/html" href="https://pandorabox.io/index.php?title=Protection_Script&amp;diff=3292&amp;oldid=prev"/>
		<updated>2025-03-27T17:45:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; This script assists to calculate coordinates to protect a larger area with multiple smaller areas.  &amp;lt;syntaxhighlight lang=&amp;quot;Lua&amp;quot;&amp;gt; #!/usr/bin/lua -- Code to prepare coordinates...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
This script assists to calculate coordinates to protect a larger area with multiple smaller areas.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Lua&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/lua&lt;br /&gt;
-- Code to prepare coordinates to protect bigger areas&lt;br /&gt;
-- Author: SwissalpS&lt;br /&gt;
-- License: MIT&lt;br /&gt;
-- Version: 2250327.1338&lt;br /&gt;
-- Written to be run in terminal of a linux host. With few&lt;br /&gt;
-- changes this code can also be used in a moon-controller,&lt;br /&gt;
-- lua-controller, lua-tube or other in-game lua nodes.&lt;br /&gt;
------------------------------------------------------------&lt;br /&gt;
------------------- CONFIG BEGIN --------------------&lt;br /&gt;
------------------------------------------------------------&lt;br /&gt;
-- Should slashes be prefixed to output lines.&lt;br /&gt;
-- If you are going to copy paste in-game set to true.&lt;br /&gt;
-- Leave false if you are going to use web-ui.&lt;br /&gt;
local bPS = false&lt;br /&gt;
&lt;br /&gt;
-- Format string for protecting. Placeholders (%d) are&lt;br /&gt;
-- populated with x, y and z counts of areas.&lt;br /&gt;
local sName = 'protect &amp;lt;Insert Name&amp;gt; %d %d %d'&lt;br /&gt;
&lt;br /&gt;
-- First position. Bottom, South West corner.&lt;br /&gt;
local tPos1 = { x = 8649, y = 5000, z = 22949 }&lt;br /&gt;
-- Last position. Top, North East corner.&lt;br /&gt;
local tPos2 = { x = 9924, y = 5615, z = 23306 }&lt;br /&gt;
&lt;br /&gt;
local tSizeMedium = { x = 64, y = 128, z = 64 }&lt;br /&gt;
local tSizeHuge = { x = 512, y = 512, z = 512 }&lt;br /&gt;
-- Maximum size of subareas. Use one of the above predefined&lt;br /&gt;
-- or create your own custom size.&lt;br /&gt;
local tSize = tSizeMedium&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------&lt;br /&gt;
------------------- CONFIG END --------------------&lt;br /&gt;
------------------------------------------------------------&lt;br /&gt;
-----------------------------------------------------&lt;br /&gt;
-----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- Roughly validate coordinates&lt;br /&gt;
if tPos2.x &amp;lt; tPos1.x&lt;br /&gt;
	or tPos2.y &amp;lt; tPos1.y&lt;br /&gt;
	or tPos2.z &amp;lt; tPos1.z&lt;br /&gt;
then&lt;br /&gt;
	print('Pos 2 coordinates must be greater than Pos 1.')&lt;br /&gt;
	os.exit(1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local min = math.min&lt;br /&gt;
-- Prepare command strings with or without slash.&lt;br /&gt;
local sP = bPS and '/' or ''&lt;br /&gt;
sName = sP .. sName&lt;br /&gt;
local sP1 = sP .. 'area_pos1 %d %d %d'&lt;br /&gt;
local sP2 = sP .. 'area_pos2 %d %d %d'&lt;br /&gt;
&lt;br /&gt;
-- Subarea counters&lt;br /&gt;
local ix, iy, iz = 1, 1, 1&lt;br /&gt;
-- Temporary position 1&lt;br /&gt;
local t1 = { x = tPos1.x, y = tPos1.y, z = tPos1.z }&lt;br /&gt;
-- Temporary position 2&lt;br /&gt;
local t2 = {&lt;br /&gt;
	x = min(tPos2.x, t1.x + tSize.x - 1),&lt;br /&gt;
	y = min(tPos2.y, t1.y + tSize.y - 1),&lt;br /&gt;
	z = min(tPos2.z, t1.z + tSize.z - 1),&lt;br /&gt;
}&lt;br /&gt;
-- Loop in y-direction last. (Upward)&lt;br /&gt;
while t1.y &amp;lt;= tPos2.y do&lt;br /&gt;
	-- Loop in z-direction second. (Northward)&lt;br /&gt;
	while t1.z &amp;lt;= tPos2.z do&lt;br /&gt;
		-- Loop in x-direction first. (Eastward)&lt;br /&gt;
		while t1.x &amp;lt;= tPos2.x do&lt;br /&gt;
			-- Output chatcommands.&lt;br /&gt;
			print(string.format(sP1, t1.x, t1.y, t1.z))&lt;br /&gt;
			print(string.format(sP2, t2.x, t2.y, t2.z))&lt;br /&gt;
			print(string.format(sName, ix, iy, iz))&lt;br /&gt;
&lt;br /&gt;
			-- Increment counter.&lt;br /&gt;
			ix = ix + 1&lt;br /&gt;
			-- Increment x-coordinates.&lt;br /&gt;
			t1.x = t2.x + 1&lt;br /&gt;
			t2.x = min(tPos2.x, t1.x + tSize.x - 1)&lt;br /&gt;
		end&lt;br /&gt;
		-- Reset counter and x-coordinates.&lt;br /&gt;
		ix = 1&lt;br /&gt;
		t1.x = tPos1.x&lt;br /&gt;
		t2.x = min(tPos2.x, t1.x + tSize.x - 1)&lt;br /&gt;
&lt;br /&gt;
		-- Increment counter.&lt;br /&gt;
		iz = iz + 1&lt;br /&gt;
		-- Increment z-coordinates.&lt;br /&gt;
		t1.z = t2.z + 1&lt;br /&gt;
		t2.z = min(tPos2.z, t1.z + tSize.z - 1)&lt;br /&gt;
	end&lt;br /&gt;
	-- Reset counter and z-coordinates.&lt;br /&gt;
	iz = 1&lt;br /&gt;
	t1.z = tPos1.z&lt;br /&gt;
	t2.z = min(tPos2.z, t1.z + tSize.z - 1)&lt;br /&gt;
&lt;br /&gt;
	-- Increment counter.&lt;br /&gt;
	iy = iy + 1&lt;br /&gt;
	-- Increment y-coordinates.&lt;br /&gt;
	t1.y = t2.y + 1&lt;br /&gt;
	t2.y = min(tPos2.y, t1.y + tSize.y - 1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippet]]&lt;br /&gt;
[[Category:Protection]]&lt;/div&gt;</summary>
		<author><name>SwissalpS</name></author>
	</entry>
</feed>