Difference between revisions of "Jumpdrive Script by GamePlayer"

From Pandorabox
Jump to navigation Jump to search
m
m (Change link to the source code last time.)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
__TOC__
+
=== Jumpdrive Script ===
  
=== Creator ===
+
<syntaxhighlight lang="Lua">
The creator of the code is GamePlayer.
+
--[[
 +
    ##################################
 +
    #  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).
  
=== Links ===
+
    Type 'help' in Terminal to see available commands.
[[Jumpdrive]] page
 
  
=== Informations ===
+
    Script is available on Gitea:
Hello all! I recently wrote a code to the luacontroller to control Jumpdrive. The code and the micro tutorial below. This is open-source code and free. Default digiline channel is "jumpdrive". Version: 1.0 Have fun!
+
    https://xdvuazhmpidi4euufr2vxbx4ddw2es2woaavx7dhdmo5zs4wv5eveqad.onion/gitea/GamePlayer-Pandorabox.io/Pandorabox-Jumpdrive
 +
--]]
  
=== JumpDrive settings X, Y, Z ===
+
local function jd_save() -- send save message to Jumpdrive
This is block to set JumpDrive.  For example: jd_set(<x coords>, <y coords>, <z coords>)
+
    digiline_send('jumpdrive', {command = 'save'})
 +
end
  
<syntaxhighlight lang="Lua">
+
local function jd_set(x, y, z) -- setup TARGET position in Jumpdrive
local function jd_set(jdx, jdy, jdz)
+
    digiline_send('jumpdrive', {command = 'set', key = 'x', value = x})
  digiline_send("jumpdrive", {command="set", key ="x", value=jdx})
+
    digiline_send('jumpdrive', {command = 'save'})
  digiline_send("jumpdrive", {command = "save"})
+
    digiline_send('jumpdrive', {command = 'set', key = 'y', value = y})
  digiline_send("jumpdrive", {command="set", key="y", value=jdy})
+
    digiline_send('jumpdrive', {command = 'save'})
  digiline_send("jumpdrive", {command = "save"})
+
    digiline_send('jumpdrive', {command = 'set', key = 'z', value = z})
  digiline_send("jumpdrive", {command="set", key="z", value=jdz})
+
    digiline_send('jumpdrive', {command = 'save'})
  digiline_send("jumpdrive", {command = "save"})
 
 
end
 
end
</syntaxhighlight>
 
  
=== JumpDrive - jump block ===
+
local function jd_jump() -- send JUMP signal
For example: jd_jump()
+
    digiline_send('jumpdrive', {command = 'jump'})
 +
end
  
<syntaxhighlight lang="Lua">
+
local function jd_show() -- send check signal
local function jd_jump()
+
    digiline_send('jumpdrive', {command = 'show'})
  digiline_send("jumpdrive", {command="jump"})
 
 
end
 
end
</syntaxhighlight>
 
  
=== JumpDrive - show block ===
+
if not mem.scan_state then -- Setup scan variables
For example: jd_show()
+
    mem.default_y = 6000
 +
    mem.scan_state = '0'
 +
end
  
<syntaxhighlight lang="Lua">
+
if mem.scanf == '1' then -- Scan process
local function jd_show()
+
    if mem.startscan == '1' then
  digiline_send("jumpdrive", {command="show"})
+
        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
</syntaxhighlight>
 
  
=== JumpDrive - save block ===
+
if event.type == 'digiline' then
For example: jd_save()
+
    -- 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)
  
<syntaxhighlight lang="Lua">
+
        elseif event.msg == 'setscan' then -- SETSCAN
local function jd_save()
+
            digiline_send('LCD','JD >> Set scan point:')
  digiline_send("jumpdrive", {command = "save"})
+
            mem.scan_state = '1'
end
 
</syntaxhighlight>
 
  
=== GetSpace - Stable JD Code ===
+
        elseif evnet.msg == 'setY' then -- setY
To run this code, you'll need:
+
            digiline_send('LCD', 'JD >> Y: ')
 +
            mem.setdefa = '1'
  
* one LuaController
+
        elseif event.msg == 'help' or event.msg == 'help 1' then -- HELP <page>
* one jumpdrive
+
            digiline_send('LCD', 'Available commands:')
* one keyboard
+
            digiline_send('LCD', 'help <page>;')
* one LCD (or other block to display text from digilines)
+
            digiline_send('LCD', 'jump | Send jump signal.')
* some digilines
+
            digiline_send('LCD', 'Page 1 of 4.')
  
Default channel for keyboard: "'''kb'''"
+
        elseif event.msg == 'help 2' then
Default channel for LCD: "'''LCD'''"
+
            digiline_send('LCD', 'set | Set target position;')
Default channel for JumpDrive: "'''jumpdrive'''"
+
            digiline_send('LCD', 'scan | Scan for free space.')
 +
            digiline_send('LCD', 'Page 2 of 4.')
  
Commands to keyboard:
+
        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.')
  
* '''jd_jump''' - Jump command
+
        elseif event.msg == 'help 4' then
* '''jd_set''' - Setuping coords: enter the command and X,Y,Z separately
+
            digiline_send('LCD', 'setscan | Set scan point;')
* '''jd_scan''' - Scaning (searching) asteroids, only you must set X and Z in jd_set
+
            digiline_send('LCD', 'setY | Set scan Y position.')
* '''jd_stop''' - Stoping scaning asteroids
+
            digiline_send('LCD', 'Page 4 of 4.')
* '''jd_y''' - Setuping Y position, enter the command and Y separately
+
        end
* '''jd_coords''' - Checking actual position. (Warning: First set the jumpdrive command: jd_set)
 
  
Code:
+
    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
  
<syntaxhighlight lang="Lua">
+
        elseif event.msg.success then
local function jd_save()
+
            digiline_send('LCD', 'Success.')
  digiline_send("jumpdrive", {command = "save"})
+
        end
end
 
local function jd_set(jdx, jdy, jdz)
 
  digiline_send("jumpdrive", {command = "set", key = "x", value = jdx})
 
  digiline_send("jumpdrive", {command = "save"})
 
  digiline_send("jumpdrive", {command = "set", key = "y", value = jdy})
 
  digiline_send("jumpdrive", {command = "save"})
 
  digiline_send("jumpdrive", {command = "set", key = "z", value = jdz})
 
  digiline_send("jumpdrive", {command = "save"})
 
end
 
local function jd_jump()
 
  digiline_send("jumpdrive", {command = "jump"})
 
end
 
local function jd_show()
 
  digiline_send("jumpdrive", {command = "show"})
 
end
 
if(event.type == "digiline" and event.channel == "kb" and mem.jdset == "3") then
 
  mem.z = event.msg
 
  mem.jdset = "0"
 
  digiline_send("jumpdrive", {command = "set", key = "z", value = event.msg})
 
  jd_save()
 
end
 
if(event.type == "digiline" and event.channel == "kb" and mem.jdset == "2") then
 
  mem.y = event.msg
 
  mem.jdset = "3"
 
  digiline_send("LCD", "JD >> Z:")
 
  digiline_send("jumpdrive", {command = "set", key = "y", value = event.msg})
 
  jd_save()
 
end
 
if(event.type == "digiline" and event.channel == "kb" and mem.jdset == "1") then
 
  mem.x = event.msg
 
  mem.jdset = "2"
 
  digiline_send("LCD", "JD >> Y:")
 
  digiline_send("jumpdrive", {command = "set", key = "x", value = event.msg})
 
  jd_save()
 
end
 
if(event.type == "digiline" and event.channel == "kb" and event.msg == "jd_set") then
 
  mem.jdset = "1"
 
  digiline_send("LCD", "JD >> Set coordinates (X Y Z):")
 
  digiline_send("LCD", "JD >> X:")
 
end
 
if(event.type == "digiline" and event.channel == "kb" and event.msg == "jd_jump") then
 
  digiline_send("LCD", "JD >> Starting jump!")
 
  jd_jump()
 
end
 
if(event.type == "digiline" and event.channel == "kb" and event.msg == "jd_scan") then
 
  digiline_send("LCD", "JD >> Wait...")
 
  mem.startscan = "1"
 
  mem.scanf = "1"
 
end
 
if(event.type == "digiline" and event.channel == "jumpdrive" and event.msg.success) then
 
  digiline_send("LCD", "JD >> Jump done!")
 
end
 
if(event.type == "digiline" and event.channel == "kb" and event.msg == "jd_stop") then
 
  mem.scanf = "0"
 
  digiline_send("LCD", "JD >> Scan canceled!")
 
end
 
if(mem.scanf == "2") then
 
  if(event.type == "digiline" and event.channel == "jumpdrive") then
 
    if(event.msg.success) then
 
      digiline_send("LCD", "JD >> Asteroid detected!")
 
      mem.scanf = "0"
 
      digiline_send("LCD", "JD >> 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
 
     end
  end
 
end
 
if(mem.scanf == "1") then
 
  if(mem.startscan == "1") then
 
    mem.scany = 6000
 
    mem.startscan = "0"
 
    mem.postep = 0
 
  end
 
  mem.postep = mem.postep + 1
 
  digiline_send("LCD", mem.postep.." on 80 elements.")
 
  jd_set(mem.x, mem.scany, mem.z)
 
  jd_show()
 
  mem.scanf = "2"
 
  if(mem.postep == 80) then
 
    digiline_send("LCD", "JD >> Asteroid not founded!")
 
    mem.scanf = "0"
 
  end
 
end
 
if(event.type == "digiline" and event.channel == "kb" and event.msg == "jd_y") then
 
  digiline_send("LCD", "JD >> Y: ")
 
  mem.setdefa = "1"
 
end
 
if(mem.setdefa == "1") then
 
  if(event.type == "digiline" and event.channel == "kb") then
 
    mem.setdefa = "0"
 
    mem.y = event.msg
 
    digiline_send("jumpdrive", {command = "set", key = "y", value = mem.y})
 
    digiline_send("jumpdrive", {command = "save"})
 
  end
 
end
 
if(event.type == "digiline" and event.channel == "kb" and event.msg == "jd_coords") then
 
  digiline_send("LCD","JD >> Coords:")
 
  digiline_send("LCD","X: "..mem.x)
 
  digiline_send("LCD","Y: "..mem.y)
 
  digiline_send("LCD","Z: "..mem.z)
 
 
end
 
end
 +
 +
interrupt(2)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
[[Category:GetSpacePlaces]]
 
 
[[Category:Spaceship design]]
 
[[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)