Nuke "Fire Beetle"

Everything about mods can be found here.

Moderator: Morax

Nuke "Fire Beetle"

Postby Dudekahedron » 06 Dec 2016, 19:50

Hi Faf,
I've been trying to understand how nuke weapons work with considerable difficulty.

The kamikaze weapon seems easy enough to understand, in cybranweapons.lua it sets up the effects, in defaultweapons.lua it does the damage... But nukes don't appear to work the same way?

Why is the code under a Fire function, and not an OnFire? How would I sub in these details into the Fire Beetle?
Sorry that my question isn't very pointed, I really have no idea how to get this going!
Code: Select all
local NukeDamage = import('/lua/sim/NukeDamage.lua').NukeAOE
DeathNukeWeapon = Class(BareBonesWeapon) {
    OnFire = function(self)
    end,

    Fire = function(self)
        local bp = self:GetBlueprint()
        local proj = self.unit:CreateProjectile(bp.ProjectileId, 0, 0, 0, nil, nil, nil):SetCollision(false)
        proj:ForkThread(proj.EffectThread)
       
        -- Play the explosion sound
        local projBp = proj:GetBlueprint()
        if projBp.Audio.NukeExplosion then
            self:PlaySound(projBp.Audio.NukeExplosion)
        end
       
        proj.InnerRing = NukeDamage()
        proj.InnerRing:OnCreate(bp.NukeInnerRingDamage, bp.NukeInnerRingRadius, bp.NukeInnerRingTicks, bp.NukeInnerRingTotalTime)
        proj.OuterRing = NukeDamage()
        proj.OuterRing:OnCreate(bp.NukeOuterRingDamage, bp.NukeOuterRingRadius, bp.NukeOuterRingTicks, bp.NukeOuterRingTotalTime)

        local launcher = self.unit
        local pos = proj:GetPosition()
        local army = launcher:GetArmy()
        local brain = launcher:GetAIBrain()
        local damageType = bp.DamageType
        proj.InnerRing:DoNukeDamage(launcher, pos, brain, army, damageType)
        proj.OuterRing:DoNukeDamage(launcher, pos, brain, army, damageType)
       
        -- Stop it calling DoDamage any time in the future.
        proj.DoDamage = function(self, instigator, DamageData, targetEntity) end
    end,
}
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Nuke "Fire Beetle"

Postby Tokyto » 06 Dec 2016, 20:58

It was working in my mod 'Tokytos balanced beetle''. But something was changed and it no longer functions :S

Maybe you can check it out, might or might not help.
User avatar
Tokyto
Evaluator
 
Posts: 540
Joined: 29 May 2013, 16:39
Has liked: 452 times
Been liked: 302 times
FAF User Name: Tokyto_

Re: Nuke "Fire Beetle"

Postby Exotic_Retard » 06 Dec 2016, 21:12

a daethnuke weapon is never really fired in the normal way, so an onfire callback is not needed.

in the death thread the script in unit.lua checks for any weapons with the DeathNuke label and fires then by calling weapon:Fire() which is what you are seeing defined here.

or something like that anyway.

is this from the acu script or something?

why dont you look at the nuke weapon and its projectile script instead?
but yes nukes do work differently, they just end up calling that fire function one way or another since they have complex stuff going on especially with the effects and damage rings.
it could be placed in the OnImpact callback of a projectile for example, but you could call it on beetle death or OnFired, then set up the weapon to be a dummy and deal damage with just the script.
User avatar
Exotic_Retard
Contributor
 
Posts: 1470
Joined: 21 Mar 2013, 22:51
Has liked: 557 times
Been liked: 626 times
FAF User Name: Exotic_Retard

Re: Nuke "Fire Beetle"

Postby Dudekahedron » 06 Dec 2016, 21:53

@Tokyto; Your mod probably doesn't work because FAF moved the commander death weapon to defaultweapons.lua instead of the respective faction weapon files.

@Exotic; the code I pasted is from defaultweapons.lua
If I follow say UEB2305 (uef sml):
UEB2305_unit.bp
Code: Select all
            ProjectileId = '/projectiles/TIFMissileNuke01/TIFMissileNuke01_proj.bp',

TIFMissileNuke01_script.lua
Code: Select all
#
# Terran Nuke Missile
#
local TIFMissileNuke = import('/lua/terranprojectiles.lua').TIFMissileNuke

TIFMissileNuke01 = Class(TIFMissileNuke) {

    InitialEffects = {'/effects/emitters/nuke_munition_launch_trail_02_emit.bp',},
    LaunchEffects = {
        '/effects/emitters/nuke_munition_launch_trail_03_emit.bp',
        '/effects/emitters/nuke_munition_launch_trail_05_emit.bp',
        '/effects/emitters/nuke_munition_launch_trail_07_emit.bp',
    },
    ThrustEffects = {'/effects/emitters/nuke_munition_launch_trail_04_emit.bp',
                     '/effects/emitters/nuke_munition_launch_trail_06_emit.bp',
    },
   
    OnImpact = function(self, TargetType, TargetEntity)
        if not TargetEntity or not EntityCategoryContains(categories.PROJECTILE, TargetEntity) then
            # Play the explosion sound
            local myBlueprint = self:GetBlueprint()
            if myBlueprint.Audio.Explosion then
                self:PlaySound(myBlueprint.Audio.Explosion)
            end
           
         nukeProjectile = self:CreateProjectile('/effects/Entities/UEFNukeEffectController01/UEFNukeEffectController01_proj.bp', 0, 0, 0, nil, nil, nil):SetCollision(false)
            nukeProjectile:PassDamageData(self.DamageData)
            nukeProjectile:PassData(self.Data)
        end
        TIFMissileNuke.OnImpact(self, TargetType, TargetEntity)
    end,

    DoTakeDamage = function(self, instigator, amount, vector, damageType)
        if self.ProjectileDamaged then
            for k,v in self.ProjectileDamaged do
                v(self)
            end
        end
        TIFMissileNuke.DoTakeDamage(self, instigator, amount, vector, damageType)
    end,

    OnCreate = function(self)
        TIFMissileNuke.OnCreate(self)
        local launcher = self:GetLauncher()
        if launcher and not launcher:IsDead() and launcher.EventCallbacks.ProjectileDamaged then
            self.ProjectileDamaged = {}
            for k,v in launcher.EventCallbacks.ProjectileDamaged do
                table.insert( self.ProjectileDamaged, v )
            end
        end
        self:SetCollisionShape('Sphere', 0, 0, 0, 2.0)
        self:ForkThread( self.MovementThread )
    end,

    CreateEffects = function( self, EffectTable, army, scale)
        for k, v in EffectTable do
            self.Trash:Add(CreateAttachedEmitter(self, -1, army, v):ScaleEmitter(scale))
        end
    end,

    MovementThread = function(self)
        local army = self:GetArmy()
        local launcher = self:GetLauncher()
        self.CreateEffects( self, self.InitialEffects, army, 1 )
        self:TrackTarget(false)
        WaitSeconds(2.5)      # Height
        self:SetCollision(true)
        self.CreateEffects( self, self.LaunchEffects, army, 1 )
        WaitSeconds(2.5)
        self.CreateEffects( self, self.ThrustEffects, army, 3 )
        WaitSeconds(2.5)
        self:TrackTarget(true) # Turn ~90 degrees towards target
        self:SetDestroyOnWater(true)
        self:SetTurnRate(47.36)
        WaitSeconds(2)                # Now set turn rate to zero so nuke flies straight
        self:SetTurnRate(0)
        self:SetAcceleration(0.001)
        self.WaitTime = 0.5
        while not self:BeenDestroyed() do
            self:SetTurnRateByDist()
            WaitSeconds(self.WaitTime)
        end
    end,

    SetTurnRateByDist = function(self)
        local dist = self:GetDistanceToTarget()
        #Get the nuke as close to 90 deg as possible
        if dist > 150 then       
            #Freeze the turn rate as to prevent steep angles at long distance targets
            self:SetTurnRate(0)
        elseif dist > 75 and dist <= 150 then
                  # Increase check intervals
            self.WaitTime = 0.3
        elseif dist > 32 and dist <= 75 then
                  # Further increase check intervals
            self.WaitTime = 0.1
        elseif dist < 32 then
                  # Turn the missile down
            self:SetTurnRate(50)
        end
    end,
   
    CheckMinimumSpeed = function(self, minSpeed)
        if self:GetCurrentSpeed() < minSpeed then
            return false
        end
        return true
    end,
   
    SetMinimumSpeed = function(self, minSpeed, resetAcceleration)
        if self:GetCurrentSpeed() < minSpeed then
            self:SetVelocity(minSpeed)
            if resetAcceleration then
                self:SetAcceleration(0)
            end
        end
    end,

    GetDistanceToTarget = function(self)
        local tpos = self:GetCurrentTargetPosition()
        local mpos = self:GetPosition()
        local dist = VDist2(mpos[1], mpos[3], tpos[1], tpos[3])
        return dist
    end,
}

TypeClass = TIFMissileNuke01

From that, I believe the lines that are useful are in the OnImpact function, but I have no idea how to transfer it into a kamikaze weapon, or just any sort of onfire command.
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Nuke "Fire Beetle"

Postby Tokyto » 06 Dec 2016, 22:01

Sorry to flood your thread :S But any idea what was this renamed to?

local CIFCommanderDeathWeapon = CWeapons.CIFCommanderDeathWeapon
User avatar
Tokyto
Evaluator
 
Posts: 540
Joined: 29 May 2013, 16:39
Has liked: 452 times
Been liked: 302 times
FAF User Name: Tokyto_

Re: Nuke "Fire Beetle"

Postby Exotic_Retard » 06 Dec 2016, 22:04

so you simply copy that code from either the nuke projectile and put it into onfire instead
or you copy it from the deathnuke and also put it into onfire

then you just get the beetle to fire its weapon. which should be default.
what we are doing here is simply transferring the code from the projectile to the units weapon, so here it will go off as soon as its fired and not when it hits sth

probably easier to copy from the deathnuke since its more related to the unit and would need to be tweaked less.
User avatar
Exotic_Retard
Contributor
 
Posts: 1470
Joined: 21 Mar 2013, 22:51
Has liked: 557 times
Been liked: 626 times
FAF User Name: Exotic_Retard

Re: Nuke "Fire Beetle"

Postby Dudekahedron » 06 Dec 2016, 22:25

@Tokyto; no worries;
Code: Select all
local DeathNukeWeapon = import('/lua/sim/defaultweapons.lua').DeathNukeWeapon


@Exotic; So spoilers for my mod thread lol
Do you mean like this? This is in my hooked terranweapons.lua file;
Code: Select all
local KamikazeWeapon = WeaponFile.KamikazeWeapon
DeployableNuke = Class(KamikazeWeapon){
    OnFire = function(self)
    end,

    Fire = function(self)
        local bp = self:GetBlueprint()
        local proj = self.unit:CreateProjectile(bp.ProjectileId, 0, 0, 0, nil, nil, nil):SetCollision(false)
        proj:ForkThread(proj.EffectThread)
       
        -- Play the explosion sound
        local projBp = proj:GetBlueprint()
        if projBp.Audio.NukeExplosion then
            self:PlaySound(projBp.Audio.NukeExplosion)
        end
       
        proj.InnerRing = NukeDamage()
        proj.InnerRing:OnCreate(bp.NukeInnerRingDamage, bp.NukeInnerRingRadius, bp.NukeInnerRingTicks, bp.NukeInnerRingTotalTime)
        proj.OuterRing = NukeDamage()
        proj.OuterRing:OnCreate(bp.NukeOuterRingDamage, bp.NukeOuterRingRadius, bp.NukeOuterRingTicks, bp.NukeOuterRingTotalTime)

        local launcher = self.unit
        local pos = proj:GetPosition()
        local army = launcher:GetArmy()
        local brain = launcher:GetAIBrain()
        local damageType = bp.DamageType
        proj.InnerRing:DoNukeDamage(launcher, pos, brain, army, damageType)
        proj.OuterRing:DoNukeDamage(launcher, pos, brain, army, damageType)
       
        -- Stop it calling DoDamage any time in the future.
        proj.DoDamage = function(self, instigator, DamageData, targetEntity) end
    end,
}


(Accidentally hit submit): The detonation command doesn't do anything but no errors are produced, except when i Control-K and I get:
WARNING: Error running lua script: ...ata\faforever\gamedata\lua.nx2\lua\terranweapons.lua(274): attempt to call method `GetBlueprint' (a nil value)
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Nuke "Fire Beetle"

Postby Exotic_Retard » 06 Dec 2016, 23:20

Code: Select all
    OnFire = function(self)
    self:Fire()
    KamikazeWeapon.OnFire()
    end,


i meant something like this.

atm it wont fire ofc since nothing is calling it xD
Onfire is a callback that is called.... on fire xD
Fire is just a function that is SOMETIMES called if a script asks for it. only place i know of that happening is the death thread, which has to do it like this since weapons are cleared by that point.

you should also rename the Fire function to something else, or just put the function inside Onfire instead.
User avatar
Exotic_Retard
Contributor
 
Posts: 1470
Joined: 21 Mar 2013, 22:51
Has liked: 557 times
Been liked: 626 times
FAF User Name: Exotic_Retard

Re: Nuke "Fire Beetle"

Postby Dudekahedron » 07 Dec 2016, 21:42

Took me a bit of fiddling, but finally got it working! There were a lot of little things that had to be fixed, and I continuously interpreted the error messages poorly! Thanks for your help Exotic. New unit added to my mod thread :p
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Nuke "Fire Beetle"

Postby EntropyWins » 24 Jan 2018, 23:49

I'm apparently trying to do the same thing... or something quite similar. See /viewtopic.php?f=53&t=15788

Could you be so kind to link or paste the code in which you got the beetles to go nuclear?
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest