Difference between revisions of "Jumpdrive Script by GamePlayer"
Jump to navigation
Jump to search
GamePlayer (talk | contribs) m |
GamePlayer (talk | contribs) m (Change link to the source code last time.) |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | === Jumpdrive Script === | |
− | = | + | <syntaxhighlight lang="Lua"> |
− | + | --[[ | |
+ | ################################## | ||
+ | # Copyright C 2022 GamePlayer # | ||
+ | # AERO Kianit License 1.0 # | ||
+ | ################################## | ||
+ | --]] | ||
+ | |||
+ | --[[ | ||
+ | This script is for Luacontroller in Minetest game. | ||
+ | It's controlling Jumpdrive block by Terminal (LCD + Keyboard). | ||
+ | It requires: | ||
+ | - Jumpdrive on channel 'jumpdrive' (+ power); | ||
+ | - Luacontroller; | ||
+ | - Digilines; | ||
+ | - LCD (or something similar) on channel 'LCD'; | ||
+ | - Keyboard (or something similar) on channel 'kb'. | ||
+ | |||
+ | It allows: | ||
+ | - Saving home location; | ||
+ | - Teleport you and your spaceship / home all around the world; | ||
+ | - Search for free space (useful for finding asteroids). | ||
− | + | Type 'help' in Terminal to see available commands. | |
− | |||
− | + | Script is available on Gitea: | |
− | + | https://xdvuazhmpidi4euufr2vxbx4ddw2es2woaavx7dhdmo5zs4wv5eveqad.onion/gitea/GamePlayer-Pandorabox.io/Pandorabox-Jumpdrive | |
+ | --]] | ||
− | + | local function jd_save() -- send save message to Jumpdrive | |
− | + | digiline_send('jumpdrive', {command = 'save'}) | |
+ | end | ||
− | + | local function jd_set(x, y, z) -- setup TARGET position in Jumpdrive | |
− | local function jd_set( | + | digiline_send('jumpdrive', {command = 'set', key = 'x', value = x}) |
− | + | digiline_send('jumpdrive', {command = 'save'}) | |
− | + | digiline_send('jumpdrive', {command = 'set', key = 'y', value = y}) | |
− | + | digiline_send('jumpdrive', {command = 'save'}) | |
− | + | digiline_send('jumpdrive', {command = 'set', key = 'z', value = z}) | |
− | + | digiline_send('jumpdrive', {command = 'save'}) | |
− | |||
end | end | ||
− | |||
− | + | local function jd_jump() -- send JUMP signal | |
− | + | digiline_send('jumpdrive', {command = 'jump'}) | |
+ | end | ||
− | + | local function jd_show() -- send check signal | |
− | local function | + | digiline_send('jumpdrive', {command = 'show'}) |
− | |||
end | end | ||
− | |||
− | + | if not mem.scan_state then -- Setup scan variables | |
− | + | mem.default_y = 6000 | |
+ | mem.scan_state = '0' | ||
+ | end | ||
− | + | if mem.scanf == '1' then -- Scan process | |
− | + | if mem.startscan == '1' then | |
− | + | mem.scany = mem.default_y | |
+ | mem.startscan = '0' | ||
+ | mem.progress = 0 | ||
+ | end | ||
+ | mem.progress = mem.progress + 1 | ||
+ | digiline_send('LCD', mem.progress..' on 80 - '..mem.y..' Y') | ||
+ | jd_set(mem.x, mem.scany, mem.z) | ||
+ | jd_show() | ||
+ | mem.scanf = '2' | ||
+ | if mem.progress == 80 then | ||
+ | digiline_send('LCD', 'Asteroid not found.') | ||
+ | mem.scanf = '0' | ||
+ | end | ||
end | end | ||
− | |||
− | === | + | if event.type == 'digiline' then |
− | + | -- Event process (in YandereDev style, lol) | |
+ | if event.channel == 'kb' then | ||
+ | if mem.jdset == '3' then -- Set Z Position | ||
+ | mem.z = event.msg | ||
+ | mem.jdset = '0' | ||
+ | digiline_send('jumpdrive', {command = 'set', key = 'z', value = event.msg}) | ||
+ | jd_save() | ||
+ | |||
+ | elseif mem.jdset == '2' then -- Set Y Position | ||
+ | mem.y = event.msg | ||
+ | mem.jdset = '3' | ||
+ | digiline_send('LCD', 'Z:') | ||
+ | digiline_send('jumpdrive', {command = 'set', key = 'y', value = event.msg}) | ||
+ | jd_save() | ||
+ | |||
+ | elseif mem.jdset == '1' then -- Set X Position | ||
+ | mem.x = event.msg | ||
+ | mem.jdset = '2' | ||
+ | digiline_send('LCD', 'Y:') | ||
+ | digiline_send('jumpdrive', {command = 'set', key = 'x', value = event.msg}) | ||
+ | jd_save() | ||
+ | |||
+ | elseif mem.setdefa == '1' then -- Set Y Position | ||
+ | mem.setdefa = '0' | ||
+ | mem.y = event.msg | ||
+ | digiline_send('jumpdrive', {command = 'set', key = 'y', value = mem.y}) | ||
+ | digiline_send('jumpdrive', {command = 'save'}) | ||
+ | |||
+ | elseif mem.scan_state == '1' then -- Set Y position | ||
+ | mem.default_y = event.msg | ||
+ | mem.scan_state = '2' | ||
+ | |||
+ | elseif event.msg == 'set' then -- SET | ||
+ | mem.jdset = '1' | ||
+ | digiline_send('LCD', 'Set coordinates (X Y Z):') | ||
+ | digiline_send('LCD', 'X:') | ||
+ | |||
+ | elseif event.msg == 'jump' then -- JUMP | ||
+ | digiline_send('LCD', 'Jumping...') | ||
+ | jd_jump() | ||
+ | |||
+ | elseif event.msg == 'scan' then -- SCAN | ||
+ | digiline_send('LCD', 'Scanning...') | ||
+ | mem.startscan = '1' | ||
+ | mem.scanf = '1' | ||
+ | |||
+ | elseif event.msg == 'stop' then -- STOP | ||
+ | mem.scanf = '0' | ||
+ | digiline_send('LCD', 'Scan canceled!') | ||
+ | |||
+ | elseif event.msg == 'sethome' then -- SETHOME | ||
+ | mem.homex = mem.x | ||
+ | mem.homey = mem.y | ||
+ | mem.homez = mem.z | ||
+ | digiline_send('LCD','Done.') | ||
+ | |||
+ | elseif event.msg == 'home' then -- HOME | ||
+ | mem.x = mem.homex | ||
+ | mem.y = mem.homey | ||
+ | mem.z = mem.homez | ||
+ | jd_set(mem.x, mem.y, mem.z) | ||
+ | digiline_send('LCD','Teleportation...') | ||
+ | jd_jump() | ||
+ | |||
+ | elseif event.msg == 'coords' then -- COORDS | ||
+ | digiline_send('LCD','JD >> Coords:') | ||
+ | digiline_send('LCD','X: '..mem.x) | ||
+ | digiline_send('LCD','Y: '..mem.y) | ||
+ | digiline_send('LCD','Z: '..mem.z) | ||
− | + | elseif event.msg == 'setscan' then -- SETSCAN | |
− | + | digiline_send('LCD','JD >> Set scan point:') | |
− | + | mem.scan_state = '1' | |
− | |||
− | |||
− | == | + | elseif evnet.msg == 'setY' then -- setY |
− | + | digiline_send('LCD', 'JD >> Y: ') | |
+ | mem.setdefa = '1' | ||
− | + | elseif event.msg == 'help' or event.msg == 'help 1' then -- HELP <page> | |
− | + | digiline_send('LCD', 'Available commands:') | |
− | + | digiline_send('LCD', 'help <page>;') | |
− | + | digiline_send('LCD', 'jump | Send jump signal.') | |
− | + | digiline_send('LCD', 'Page 1 of 4.') | |
− | + | elseif event.msg == 'help 2' then | |
− | + | digiline_send('LCD', 'set | Set target position;') | |
− | + | digiline_send('LCD', 'scan | Scan for free space.') | |
+ | digiline_send('LCD', 'Page 2 of 4.') | ||
− | + | elseif event.msg == 'help 3' then | |
+ | digiline_send('LCD', 'stop | Stop scan;') | ||
+ | digiline_send('LCD', 'coords | Show coords.') | ||
+ | digiline_send('LCD', 'Page 3 of 4.') | ||
− | + | elseif event.msg == 'help 4' then | |
− | + | digiline_send('LCD', 'setscan | Set scan point;') | |
− | + | digiline_send('LCD', 'setY | Set scan Y position.') | |
− | + | digiline_send('LCD', 'Page 4 of 4.') | |
− | + | end | |
− | + | elseif event.channel == 'jumpdrive' then | |
+ | if mem.scanf == '2' then | ||
+ | if event.msg.success then | ||
+ | digiline_send('LCD', 'Asteroid detected!') | ||
+ | mem.scanf = '0' | ||
+ | digiline_send('LCD', 'Y: '..mem.scany) | ||
+ | digiline_send('jumpdrive', {command = 'set', key = 'y', value = mem.scany}) | ||
+ | digiline_send('jumpdrive', {command = 'save'}) | ||
+ | else | ||
+ | mem.scany = mem.scany + 25 | ||
+ | mem.y = mem.scany | ||
+ | mem.scanf = '1' | ||
+ | end | ||
− | + | elseif event.msg.success then | |
− | + | digiline_send('LCD', 'Success.') | |
− | + | end | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
+ | |||
+ | interrupt(2) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | [[Category: | + | [[Category:Spaceship design]] |
Latest revision as of 11:03, 6 August 2022
Jumpdrive Script
--[[
##################################
# Copyright C 2022 GamePlayer #
# AERO Kianit License 1.0 #
##################################
--]]
--[[
This script is for Luacontroller in Minetest game.
It's controlling Jumpdrive block by Terminal (LCD + Keyboard).
It requires:
- Jumpdrive on channel 'jumpdrive' (+ power);
- Luacontroller;
- Digilines;
- LCD (or something similar) on channel 'LCD';
- Keyboard (or something similar) on channel 'kb'.
It allows:
- Saving home location;
- Teleport you and your spaceship / home all around the world;
- Search for free space (useful for finding asteroids).
Type 'help' in Terminal to see available commands.
Script is available on Gitea:
https://xdvuazhmpidi4euufr2vxbx4ddw2es2woaavx7dhdmo5zs4wv5eveqad.onion/gitea/GamePlayer-Pandorabox.io/Pandorabox-Jumpdrive
--]]
local function jd_save() -- send save message to Jumpdrive
digiline_send('jumpdrive', {command = 'save'})
end
local function jd_set(x, y, z) -- setup TARGET position in Jumpdrive
digiline_send('jumpdrive', {command = 'set', key = 'x', value = x})
digiline_send('jumpdrive', {command = 'save'})
digiline_send('jumpdrive', {command = 'set', key = 'y', value = y})
digiline_send('jumpdrive', {command = 'save'})
digiline_send('jumpdrive', {command = 'set', key = 'z', value = z})
digiline_send('jumpdrive', {command = 'save'})
end
local function jd_jump() -- send JUMP signal
digiline_send('jumpdrive', {command = 'jump'})
end
local function jd_show() -- send check signal
digiline_send('jumpdrive', {command = 'show'})
end
if not mem.scan_state then -- Setup scan variables
mem.default_y = 6000
mem.scan_state = '0'
end
if mem.scanf == '1' then -- Scan process
if mem.startscan == '1' then
mem.scany = mem.default_y
mem.startscan = '0'
mem.progress = 0
end
mem.progress = mem.progress + 1
digiline_send('LCD', mem.progress..' on 80 - '..mem.y..' Y')
jd_set(mem.x, mem.scany, mem.z)
jd_show()
mem.scanf = '2'
if mem.progress == 80 then
digiline_send('LCD', 'Asteroid not found.')
mem.scanf = '0'
end
end
if event.type == 'digiline' then
-- Event process (in YandereDev style, lol)
if event.channel == 'kb' then
if mem.jdset == '3' then -- Set Z Position
mem.z = event.msg
mem.jdset = '0'
digiline_send('jumpdrive', {command = 'set', key = 'z', value = event.msg})
jd_save()
elseif mem.jdset == '2' then -- Set Y Position
mem.y = event.msg
mem.jdset = '3'
digiline_send('LCD', 'Z:')
digiline_send('jumpdrive', {command = 'set', key = 'y', value = event.msg})
jd_save()
elseif mem.jdset == '1' then -- Set X Position
mem.x = event.msg
mem.jdset = '2'
digiline_send('LCD', 'Y:')
digiline_send('jumpdrive', {command = 'set', key = 'x', value = event.msg})
jd_save()
elseif mem.setdefa == '1' then -- Set Y Position
mem.setdefa = '0'
mem.y = event.msg
digiline_send('jumpdrive', {command = 'set', key = 'y', value = mem.y})
digiline_send('jumpdrive', {command = 'save'})
elseif mem.scan_state == '1' then -- Set Y position
mem.default_y = event.msg
mem.scan_state = '2'
elseif event.msg == 'set' then -- SET
mem.jdset = '1'
digiline_send('LCD', 'Set coordinates (X Y Z):')
digiline_send('LCD', 'X:')
elseif event.msg == 'jump' then -- JUMP
digiline_send('LCD', 'Jumping...')
jd_jump()
elseif event.msg == 'scan' then -- SCAN
digiline_send('LCD', 'Scanning...')
mem.startscan = '1'
mem.scanf = '1'
elseif event.msg == 'stop' then -- STOP
mem.scanf = '0'
digiline_send('LCD', 'Scan canceled!')
elseif event.msg == 'sethome' then -- SETHOME
mem.homex = mem.x
mem.homey = mem.y
mem.homez = mem.z
digiline_send('LCD','Done.')
elseif event.msg == 'home' then -- HOME
mem.x = mem.homex
mem.y = mem.homey
mem.z = mem.homez
jd_set(mem.x, mem.y, mem.z)
digiline_send('LCD','Teleportation...')
jd_jump()
elseif event.msg == 'coords' then -- COORDS
digiline_send('LCD','JD >> Coords:')
digiline_send('LCD','X: '..mem.x)
digiline_send('LCD','Y: '..mem.y)
digiline_send('LCD','Z: '..mem.z)
elseif event.msg == 'setscan' then -- SETSCAN
digiline_send('LCD','JD >> Set scan point:')
mem.scan_state = '1'
elseif evnet.msg == 'setY' then -- setY
digiline_send('LCD', 'JD >> Y: ')
mem.setdefa = '1'
elseif event.msg == 'help' or event.msg == 'help 1' then -- HELP <page>
digiline_send('LCD', 'Available commands:')
digiline_send('LCD', 'help <page>;')
digiline_send('LCD', 'jump | Send jump signal.')
digiline_send('LCD', 'Page 1 of 4.')
elseif event.msg == 'help 2' then
digiline_send('LCD', 'set | Set target position;')
digiline_send('LCD', 'scan | Scan for free space.')
digiline_send('LCD', 'Page 2 of 4.')
elseif event.msg == 'help 3' then
digiline_send('LCD', 'stop | Stop scan;')
digiline_send('LCD', 'coords | Show coords.')
digiline_send('LCD', 'Page 3 of 4.')
elseif event.msg == 'help 4' then
digiline_send('LCD', 'setscan | Set scan point;')
digiline_send('LCD', 'setY | Set scan Y position.')
digiline_send('LCD', 'Page 4 of 4.')
end
elseif event.channel == 'jumpdrive' then
if mem.scanf == '2' then
if event.msg.success then
digiline_send('LCD', 'Asteroid detected!')
mem.scanf = '0'
digiline_send('LCD', 'Y: '..mem.scany)
digiline_send('jumpdrive', {command = 'set', key = 'y', value = mem.scany})
digiline_send('jumpdrive', {command = 'save'})
else
mem.scany = mem.scany + 25
mem.y = mem.scany
mem.scanf = '1'
end
elseif event.msg.success then
digiline_send('LCD', 'Success.')
end
end
end
interrupt(2)