Quesion: Modifying Unit Scripts

Everything about mods can be found here.

Moderator: Morax

Quesion: Modifying Unit Scripts

Postby Hawkei » 09 Apr 2014, 02:00

Hello,

I have a question about creating mods for units. The basic intention of my mod is to change all non-stealth submarines to become stealthed when stationary and not firing. For this behaviour I have copied the Seraphim combat scout behaviour. Which I have found uses a script instead of blueprint parameters to control its visibility status.

The modified script for the UEF T1 submarine should be as follows:

Code: Select all
#****************************************************************************
#**
#**  File     :  /cdimage/units/UES0203/UES0203_script.lua
#**  Author(s):  John Comes, David Tomandl, Jessica St. Croix
#**
#**  Summary  :  UEF Attack Sub Script
#**
#**  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
#**  Modified by Hawkei 2014
#****************************************************************************

local TSubUnit = import('/lua/terranunits.lua').TSubUnit
local TANTorpedoAngler = import('/lua/terranweapons.lua').TANTorpedoAngler
local TDFLightPlasmaCannonWeapon = import('/lua/terranweapons.lua').TDFLightPlasmaCannonWeapon

UES0203 = Class(TSubUnit) {
    PlayDestructionEffects = true,
    DeathThreadDestructionWaitTime = 0,

    Weapons = {
        Torpedo01 = Class(TANTorpedoAngler) {         
         OnWeaponFired = function(self, target)
            SDFPhasicAutoGunWeapon.OnWeaponFired(self, target)
            ChangeState( self.unit, self.unit.VisibleState )
         end,
         
         OnLostTarget = function(self)
            SDFPhasicAutoGunWeapon.OnLostTarget(self)
            if self.unit:IsIdleState() then
                ChangeState( self.unit, self.unit.InvisState )
            end
         end,},
        PlasmaGun = Class(TDFLightPlasmaCannonWeapon) {}
    },

    OnStopBeingBuilt = function(self, builder, layer)

        #These start enabled, so before going to InvisState, disabled them.. they'll be reenabled shortly
           self:DisableUnitIntel('SonarStealth')
      self.Stealthed = false
        ChangeState( self, self.InvisState ) # If spawned in we want the unit to be invis, normally the unit will immediately start moving
    end,
   
    InvisState = State() {
        Main = function(self)
            self.Stealthed = false
            local bp = self:GetBlueprint()
            if bp.Intel.StealthWaitTime then
                WaitSeconds( bp.Intel.StealthWaitTime )
            end
         self:EnableUnitIntel('SonarStealth')
         self.Stealthed = true
        end,
       
        OnMotionHorzEventChange = function(self, new, old)
            if new != 'Stopped' then
                ChangeState( self, self.VisibleState )
            end

    },
   
    VisibleState = State() {
        Main = function(self)
            if self.Cloaked then
                self:DisableUnitIntel('SonarStealth')
         end
        end,
       
        OnMotionHorzEventChange = function(self, new, old)
            if new == 'Stopped' then
                ChangeState( self, self.InvisState )
            end

    },

}


TypeClass = UES0203


So my question is this: Is it possible to merge or overwrite the existing script for the UES0203? Or do I need to create an entirely new unit?
User avatar
Hawkei
Supreme Commander
 
Posts: 1217
Joined: 03 Jun 2013, 18:44
Location: A rather obscure planet in a small cluster of stars on the outer edge of the Milky Way Galaxy
Has liked: 44 times
Been liked: 182 times
FAF User Name: Firewall

Re: Quesion: Modifying Unit Scripts

Postby IceDreamer » 09 Apr 2014, 02:04

Put "do" at the very top and "end" at the very bottom, without quotations, and put in modname/hook/units/UID (In capitals)/script.lua

However, something looks wrong with this script. I don't think this "ChangeState( self.unit, self.unit.VisibleState )" is correct :/
IceDreamer
Supreme Commander
 
Posts: 2607
Joined: 27 Dec 2011, 07:01
Has liked: 138 times
Been liked: 488 times

Re: Quesion: Modifying Unit Scripts

Postby Hawkei » 09 Apr 2014, 02:59

Thanks, I will see if that works.

The code is not yet tested. It will likely need debugging. It is a copy of the state change components from the Selen pasted into the Tigershark script.
User avatar
Hawkei
Supreme Commander
 
Posts: 1217
Joined: 03 Jun 2013, 18:44
Location: A rather obscure planet in a small cluster of stars on the outer edge of the Milky Way Galaxy
Has liked: 44 times
Been liked: 182 times
FAF User Name: Firewall

Re: Quesion: Modifying Unit Scripts

Postby IceDreamer » 09 Apr 2014, 06:42

It should work then. You will need Blueprint changes to go with it, remember.
IceDreamer
Supreme Commander
 
Posts: 2607
Joined: 27 Dec 2011, 07:01
Has liked: 138 times
Been liked: 488 times

Re: Quesion: Modifying Unit Scripts

Postby Hawkei » 09 Apr 2014, 07:50

Thanks,

The blueprint changes are easier. But ATM I'm having some difficulty getting the changed state script to work. I might have a look at this latter.

I think, for now, I will just focus on the other aspects of the submarine balance. A summary of the changes I am currently modelling:

- Increase Torpedo weapon damage by (100% T1, 75% T2, 50% T3/T4)
- Increase Submarine HP by (100% T1, 75% T2, 50% T3/T4)
- Apply sonar stealth capability to all submarines
- Increase underwater vision radius for submarines, frigates, destroyers, battle cruisers, sonar and torpedo platforms.
- Increase sonar range and decrease radar for destroyers
- Decrease underwater vision and sonar range for cruisers, battleships, and missile ships.
User avatar
Hawkei
Supreme Commander
 
Posts: 1217
Joined: 03 Jun 2013, 18:44
Location: A rather obscure planet in a small cluster of stars on the outer edge of the Milky Way Galaxy
Has liked: 44 times
Been liked: 182 times
FAF User Name: Firewall

Re: Quesion: Modifying Unit Scripts

Postby IceDreamer » 09 Apr 2014, 10:17

Is this part of a bigger mod? Seems kind of pointless if not, I don't get why you'd want to do this.
IceDreamer
Supreme Commander
 
Posts: 2607
Joined: 27 Dec 2011, 07:01
Has liked: 138 times
Been liked: 488 times

Re: Quesion: Modifying Unit Scripts

Postby rockoe10 » 09 Apr 2014, 18:36

there has been some small talk about boosting the effectiveness of submarines. One was making them a stealth while not moving. Although, I think this weakens cybrans in the water. Cybran would need a boost
ZeP: doesn't matter if it's an avatar, a trophy or a collection of dead cats
ZeP: it's the same code
User avatar
rockoe10
Avatar-of-War
 
Posts: 299
Joined: 05 Jan 2013, 05:09
Has liked: 36 times
Been liked: 17 times
FAF User Name: Rockoe10


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest