Author Topic: [REQUEST] Simple custom torpedo spawn script (SOLVED)  (Read 3349 times)

Mattoropael

  • Newbie
  • *
  • Posts: 15
    • View Profile
[REQUEST] Simple custom torpedo spawn script (SOLVED)
« on: March 09, 2018, 10:45:17 PM »
Simply put, something similar to [MOD][OPW] Overpowered Weaponry but for torpedoes.

I tried jury-rigging a command script from entitydbg.lua without much success. Didn't even get to mixing in customized elements like OPW - I failed at the stage of separating the "Add Torpedo" spawn script from entitydbg.lua into a functional chat command.
« Last Edit: March 10, 2018, 11:32:53 PM by Mattoropael »

Laserzwei

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script
« Reply #1 on: March 10, 2018, 10:46:33 AM »
Create 2 new files:
/scripts/commands/torpedo.lua
/scripts/player/torpedo.lua

/scripts/commands/torpedo.lua :
Code: [Select]
package.path = package.path .. ";data/scripts/lib/?.lua"
package.path = package.path .. ";data/scripts/player/?.lua"
function execute(sender, commandName, warhead)

    local ship = Player(sender).craft
    ship:addScriptOnce("data/scripts/player/torpedo.lua")
    ship:invokeFunction("data/scripts/player/torpedo.lua", "start", sender, commandName, warhead)

    return 0, "", ""
end

function getDescription()
    return "/torpedo [type]"
end

function getHelp()
    return "soo many torpedos"
end

/scripts/player/torpedo.lua :
Code: [Select]
package.path = package.path .. ";data/scripts/lib/?.lua"
local torps =
{
    Nuclear = 1,
    Neutron = 2,
    Fusion = 3,
    Tandem = 4,
    Kinetic = 5,
    Ion = 6,
    Plasma = 7,
    Sabot = 8,
    EMP = 9,
    AntiMatter = 10,
}

function initialize()

end

function start(sender, commandName, warhead)
    if not torps[warhead] then warhead = "Nuclear" end
    local ship = Player(sender).craft


    local TorpedoGenerator = require("torpedogenerator")
    local x, y = Sector():getCoordinates()

    local torpedo = TorpedoGenerator.generate(0, 0, nil, nil, torps[warhead])

    --stats
    ---general properties
    torpedo.rarity = Rarity(RarityType.Legendary)
    torpedo.tech = torpedo.tech
    torpedo.size = torpedo.size

    -- body properties
    torpedo.durability = torpedo.durability
    torpedo.turningSpeed = torpedo.turningSpeed
    torpedo.maxVelocity = torpedo.maxVelocity
    torpedo.reach = torpedo.reach

    -- warhead properties
    torpedo.shieldDamage = torpedo.shieldDamage
    torpedo.hullDamage = torpedo.hullDamage * 100
    torpedo.shieldPenetration = torpedo.shieldPenetration --[true or false]
    torpedo.shieldDeactivation = torpedo.shieldDeactivation --[true or false]
    torpedo.shieldAndHullDamage = torpedo.shieldAndHullDamage --[true or false]
    torpedo.energyDrain = torpedo.energyDrain --[true or false]
    torpedo.storageEnergyDrain = torpedo.storageEnergyDrain
    torpedo.damageType = DamageType.Physical
    torpedo.acceleration = torpedo.acceleration -- reach max velocity after 10km of travelled way

    if warhead.damageVelocityFactor then
        -- scale to normal dps damage dependent on maxVelocity
        torpedo.damageVelocityFactor = torpedo.damageVelocityFactor
        torpedo.maxVelocity = torpedo.maxVelocity
        torpedo.hullDamage = 0
    end

    -- torpedo visuals
    torpedo.numShockwaves = 1
    torpedo.shockwaveSize = 60
    torpedo.shockwaveDuration = 0.6
    torpedo.shockwaveColor = ColorRGB(0.9, 0.6, 0.3)
    -- torpedo.shockwaveColor = ColorRGB(0.1, 0.3, 1.2) -- this looks cool :)
    torpedo.explosionSize = 6
    torpedo.flashSize = 25
    torpedo.flashDuration = 1

    -- see /lib/torpedogenerator.lua for more

    local launcher = TorpedoLauncher()
    if launcher == nil then return end
    local shafts = {launcher:getShafts()}

    for _, shaft in pairs(shafts) do
        for i = 1, launcher:getMaxTorpedoes(shaft) do
            launcher:addTorpedo(torpedo, shaft)
        end
    end
    --torpedo storage
    --[[for j = 1, 50 do
        launcher:addTorpedo(torpedo)
    end]]
    terminate()
end

Ingame type
Quote
/torpedo
enjoy
Spoiler: show


My Mod Collection
My Discord     screw google captcha
My Github
Questions?
> PM me here on the forums!

Mattoropael

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script
« Reply #2 on: March 10, 2018, 06:02:02 PM »
Spoiler: show
Create 2 new files:
/scripts/commands/torpedo.lua
/scripts/player/torpedo.lua

/scripts/commands/torpedo.lua :
Code: [Select]
package.path = package.path .. ";data/scripts/lib/?.lua"
package.path = package.path .. ";data/scripts/player/?.lua"
function execute(sender, commandName, warhead)

    local ship = Player(sender).craft
    ship:addScriptOnce("data/scripts/player/torpedo.lua")
    ship:invokeFunction("data/scripts/player/torpedo.lua", "start", sender, commandName, warhead)

    return 0, "", ""
end

function getDescription()
    return "/torpedo [type]"
end

function getHelp()
    return "soo many torpedos"
end

/scripts/player/torpedo.lua :
Code: [Select]
package.path = package.path .. ";data/scripts/lib/?.lua"
local torps =
{
    Nuclear = 1,
    Neutron = 2,
    Fusion = 3,
    Tandem = 4,
    Kinetic = 5,
    Ion = 6,
    Plasma = 7,
    Sabot = 8,
    EMP = 9,
    AntiMatter = 10,
}

function initialize()

end

function start(sender, commandName, warhead)
    if not torps[warhead] then warhead = "Nuclear" end
    local ship = Player(sender).craft


    local TorpedoGenerator = require("torpedogenerator")
    local x, y = Sector():getCoordinates()

    local torpedo = TorpedoGenerator.generate(0, 0, nil, nil, torps[warhead])

    --stats
    ---general properties
    torpedo.rarity = Rarity(RarityType.Legendary)
    torpedo.tech = torpedo.tech
    torpedo.size = torpedo.size

    -- body properties
    torpedo.durability = torpedo.durability
    torpedo.turningSpeed = torpedo.turningSpeed
    torpedo.maxVelocity = torpedo.maxVelocity
    torpedo.reach = torpedo.reach

    -- warhead properties
    torpedo.shieldDamage = torpedo.shieldDamage
    torpedo.hullDamage = torpedo.hullDamage * 100
    torpedo.shieldPenetration = torpedo.shieldPenetration --[true or false]
    torpedo.shieldDeactivation = torpedo.shieldDeactivation --[true or false]
    torpedo.shieldAndHullDamage = torpedo.shieldAndHullDamage --[true or false]
    torpedo.energyDrain = torpedo.energyDrain --[true or false]
    torpedo.storageEnergyDrain = torpedo.storageEnergyDrain
    torpedo.damageType = DamageType.Physical
    torpedo.acceleration = torpedo.acceleration -- reach max velocity after 10km of travelled way

    if warhead.damageVelocityFactor then
        -- scale to normal dps damage dependent on maxVelocity
        torpedo.damageVelocityFactor = torpedo.damageVelocityFactor
        torpedo.maxVelocity = torpedo.maxVelocity
        torpedo.hullDamage = 0
    end

    -- torpedo visuals
    torpedo.numShockwaves = 1
    torpedo.shockwaveSize = 60
    torpedo.shockwaveDuration = 0.6
    torpedo.shockwaveColor = ColorRGB(0.9, 0.6, 0.3)
    -- torpedo.shockwaveColor = ColorRGB(0.1, 0.3, 1.2) -- this looks cool :)
    torpedo.explosionSize = 6
    torpedo.flashSize = 25
    torpedo.flashDuration = 1

    -- see /lib/torpedogenerator.lua for more

    local launcher = TorpedoLauncher()
    if launcher == nil then return end
    local shafts = {launcher:getShafts()}

    for _, shaft in pairs(shafts) do
        for i = 1, launcher:getMaxTorpedoes(shaft) do
            launcher:addTorpedo(torpedo, shaft)
        end
    end
    --torpedo storage
    --[[for j = 1, 50 do
        launcher:addTorpedo(torpedo)
    end]]
    terminate()
end

Ingame type
Quote
/torpedo
enjoy




This works well for my purposes, thanks a lot.

NovaBreaker

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script (SOLVED)
« Reply #3 on: March 30, 2018, 05:44:54 AM »
I'm just gonna grab this, you should upload this as a mod file.

NovaBreaker

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script
« Reply #4 on: April 01, 2018, 10:01:29 PM »
RETRACTED, i had a stupid moment.
« Last Edit: April 01, 2018, 10:23:14 PM by NovaBreaker »

NovaBreaker

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script (SOLVED)
« Reply #5 on: February 20, 2019, 07:52:03 PM »
So others don't make the same mistake, this no longer works.

fordhamflash

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script (SOLVED)
« Reply #6 on: April 13, 2019, 07:57:31 AM »
I would love something like this. But doesn't look like that posted code is currently working. I tried playing around with torpedos and got nowhere.

fordhamflash

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: [REQUEST] Simple custom torpedo spawn script (SOLVED)
« Reply #7 on: July 09, 2019, 07:49:58 PM »
P.S. with a little modification, the above mod works like a champ in the current version.