Questions about mission scripts

2»

Comments

  • Explosion sounds are scaled by their size, so i think that will work out.
    I dont think you will have performance issues, but the main screen is the main risk then. As the rendering of those explosions is not that greatly optimized.

    The explosion and beam effect does not apply damage. By design. This gives the script more control over the damage.

    I wrote something that should get you started:
    -- Name: Test
    -- Description: Test
    -- Type: Basic
    
    require("utils.lua")
    
    function init()
    	player1 = PlayerSpaceship():setFaction("Human Navy"):setTemplate("Atlantis"):setRotation(200)
        addSuperWeapon(player1)
    end
    
    function addSuperWeapon(player)
        player.super_charge = 0.0
        player.super_charging = false
        player:addCustomButton("Weapons", "SUPER_BUTTON", "charge", function()
            player.super_charging = true
            player:removeCustom("SUPER_BUTTON")
            player:addCustomInfo("Weapons", "SUPER_INFO", "charging..")
        end)
    end
    
    function updateSuperWeapon(player, delta)
        if player.super_charging then
            player.super_charge = player.super_charge + delta
            if player.super_charge > 1.0 then
                player.super_charging = false
                player:removeCustom("SUPER_INFO")
                player:addCustomButton("Weapons", "SUPER_BUTTON", "fire", function()
                    local x, y = player:getPosition()
                    local dx, dy = vectorFromAngle(player:getRotation(), 1)
                    for n=1,20 do
                        ElectricExplosionEffect():setPosition(x+dx*n*100, y+dy*n*100):setSize(100)
                    end
                    for _, obj in ipairs(getAllObjects()) do
                        local ox, oy = obj:getPosition()
    
                        -- Calculate point q, which is a point on the line start-end that is closest to n->getPosition
                        local odx, ody = ox - x, oy - y
                        local f = (dx * odx) + (dy * ody)
                        if f < 0 then f = 0.0 end
                        if f > 20 * 100 then f = 20 * 100 end
                        local qx, qy = x + dx * f, y + dy * f
                        local dist_x, dist_y = qx - ox, qy - oy
                        local dist = math.sqrt((dist_x * dist_x) + (dist_y * dist_y))
                        if player ~= obj and dist < 300 then
                            obj:takeDamage(100, "kinetic", qx, qy)
                        end
                    end
                    
                    addSuperWeapon(player)
                end)
            end
        end
    end
    
    function update(delta)
        updateSuperWeapon(player1, delta)
    end
    
    I hope the math is right, uses the same "trick" that I use to see if nebula block sight to something.

    It looks pretty cool:
    image
  • Terandir said:


    Where exactly do you have problems? And which version are you using? Constantly updating buttons/labels used to be problematic, but it was fixed a few versions ago.

    I'm using 11.28, and my main problem is that I can't get the button to change its visuals. Or is this "deleting" one button and replacing it with another?
    It should be just replacing, as the function should automatically delete other buttons of the same name. So you just make an addCustomButton call again, using the new label text, but the same button name as before.
    Like this:
    addCustomButton("Tactical", "button1", "Charge", chargeBeam)
    -- later:
    addCustomButton("Tactical", "button1", "Fire", fireBeam)
    Terandir said:

    Does beameffect produce damage in itself? And is it stopped by targets?

    Thanks a lot, I did not know about beameffect!

    No worries, it is brandnew. It was added mid september, so 2019-10-28 was the first release that had it included.
    It don't do damage itself, wich I'd consider an advantage. That way you can decide the amount of damage, or wether it should cause any damage at all. That way you could also do stuff like mining, tractor beams,etc.
    The beam effect is defined between a source object and a target object, both of wich could be any type of spaceobject. Not sure what happens if the beam is interrupted by another object, i assume it would just get through.
  • @daid and BlueShadow

    Thanks so very much for your time and expertise! I literally couldn't have done this alone. The screenshot looks really great, I will use this!
  • The latest version as of this post is 2019.11.01. I can't find version 11.28. You must be using a version from 2017. I'll vouch with BlueShadow for a countdown timer working better since the enhancement was merged 10Sep2019. If you don't have the latest version it's much harder.

    The beam effect does not do damage on its own, nor do the explosion effects. You'll need to handle that yourself. The beam effect enhancements were added near the end of September 2019 (another reason to get the latest version). You control how far the beam effect goes.

    When you reduce power to other weapons, is that beam, missile or both? Is it permanent or can power be restored once the special weapon is charged? If the weapon is not fired within a given amount of time does it lose charge or damage systems? Can the weapon be fired while traveling at warp speed?
  • edited November 2019
    You're right, it's 20191028. I'm just too dumb to type simple numbers. I had not yet updated so I wouldn't have to update all the Android Clients in my gaming group, but: no more excuses... ☺

    I will experiment with beameffect, there are some things I was already wondering about how to implement... I have ideas now (sadly, I'm an ideas person, not an understanding-how-it's-done-person.

    I wanted to "drain" the whole weapons section during charge, but power can be restored to them once the charge is complete. Shouldn't be fired during warp... guess I'll have to add that condition. Good thought. And damage to the system is a nice idea... ☺☺

    Thanks!!
  • So, once again thanks. :)

    I employed this, and though I could have never written this, I managed to break it up into a series of black boxes of which I at least think I know what each of them does. Managed to add a charge sound, implement an energy cost, create different explosion effects and adjust to different ships. Still working on implementing a second effect using the simple explosion effects (as an opposing ship shall use a different kind of weapon) or change the whole thing to a beameffect, but that's for later.

    One thing I didn't get though: is there a way to change the charging time, maybe even implement one of these nifty charge bars the shield calibration or jump drive uses? Didn't really get if there's a value I could just change to lengthen the charge.

    Grateful greetings, Heinz

  • There's not a way to do a graphical charging bar using the Lua script add-on. However, you could code your own graphical widget if you want to modify the code base.

    If you're writing your own weapon, you set the charge time and if you set the charge time, you can change it as you wish or establish whatever criteria determines the charge time.

  • player.super_charge = player.super_charge + delta
            if player.super_charge > 1.0 then
    

    Controls the rate of charging. You can change the 1.0 to have it charge for a longer time before it is ready. Or you can multiply the delta with a value to charge faster/slower. (delta * 0.1 will charge at 10% of the speed)

  • Thanks for the answers - exactly what I need. Sorry for the delay, notifications were somehow turned off...

Sign In or Register to comment.