Variable drones number based on enhancement

Everything about mods can be found here.

Moderator: Morax

Re: Variable drones number based on enhancement

Postby HUSSAR » 07 Nov 2018, 00:51

IMO, these drone upgrades should be replacing existing drones with new drones that have higher build rate. This way the number of drones will remain the same and it will not slow down the game if you upgrades a lot of units. Also, managing so many drone might be difficult for some players.
________________________________________________________
MY FAF CONTRIBUTIONS:
UI Mod - Supreme Score Board
FAF Feature - Accurate Units Stats
FAF Feature - Unit Restriction Manager
User avatar
HUSSAR
Avatar-of-War
 
Posts: 126
Joined: 17 Sep 2015, 06:59
Location: Philly, USA
Has liked: 38 times
Been liked: 59 times
FAF User Name: HUSSAR

Re: Variable drones number based on enhancement

Postby DDDX » 07 Nov 2018, 09:19

no, i plan to code them for just 1 unit - or 1 set of units - a RPG style hero that counts mass value killed and evolves into 1 of 5 forms as it gets enough kills. The level 1 spawns at start and cannot be built...so no danger of too many drones on too many units ;)

Right now I am at the point where the unit starts with no drones and gets them when it gets the apropriate ACU-style enhancement...but it would be much better if I could better manipulate the number of drones through enhancements (for example, have multiple stages of the drone-numbered enhancements, or the ability to replace the existing drones with other drone-like units, like you said).

And like I said, I can totally do that too, but...then they do not get rebuilt :/
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: Variable drones number based on enhancement

Postby Franck83 » 07 Nov 2018, 14:38

This is not beautiful code, but it works. I simply reset the current drone table at enhancement to set the new.

There should be a way to add a new drone in the existing table if you have more time.



File --> https://ufile.io/gmf1x
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Variable drones number based on enhancement

Postby DDDX » 07 Nov 2018, 15:27

who cares about code beauty if it works ;)
Unfortunately I cannot open the .rar archive, says corrupted.
Mind uploading again, or sending directly to my e-mail? Imma send it to you on Discord.
many thanks for helping me with this bothersome issue ;)
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: Variable drones number based on enhancement

Postby DDDX » 07 Nov 2018, 20:51

bad news...they, too, do not rebuild when killed. The 2 of them do, but when upgraded into 3, they do not :(
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: Variable drones number based on enhancement

Postby Franck83 » 09 Nov 2018, 13:43

I asked you on discord.

It seems that enhancements broke the state machine thread. It should be able a fix this but it may need a time invest to understand the drone and the state machine archtecture.
Maybe somebody has some better drone knowledge.

The simple way to do an equal goal you want is to apply a buff on drones on enhancement. This would be quick, will have no side effects and best performance.

If you want a better graphic effect, you can increase size of your drone at enhancement (changing meshes). So you maybe have light, medium and heavy drones.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Variable drones number based on enhancement

Postby DDDX » 11 Nov 2018, 17:24

it would seem that states are to blame.
Now, I have been able to fix the issue of not rebuilding drones while building other stuff, using the Tempest's script - to be honest I did not even notice the drones don't get rebuilt during my unit constructing other things.
The issue is fixed using this code:

Code: Select all
    OnStartBuild = function(self, unitBuilding, order)
        AAirUnit.OnStartBuild(self, unitBuilding, order)
        self.UnitBeingBuilt = unitBuilding
        ChangeState(self, self.BuildingState)
    end,

    OnStopBuild = function(self, unitBeingBuilt)
        AAirUnit.OnStopBuild(self, unitBeingBuilt)
        ChangeState(self, self.FinishedBuildingState)
    end,

    OnFailedToBuild = function(self)
        AAirUnit.OnFailedToBuild(self)
        ChangeState(self, self.DroneMaintenanceState)
    end,


however, the states still get broken upon enhancing, and that is why the issue occurs. It is also why your proposed fix will now work :(
Now, there are 2 ways around this, one is a script for working state (enhancing), similar to this one for building state,
the other is forcing the drones to be rebuilt using the UEF acu's 2 engineer drones script.

I guess I could mutate and use the Blackops:ACUs script but as far as I can see each drone must be then set-up individually (and for 6,7,8+ drones that's a shitload of code)... so if anyone knows of a quick fix, a code for OnWorkBegin that is the same as this OnStartBuild that I quoted, I believe that will do the trick ;)

something like this...though I am pretty sure this is wrong ;)

OnWorkBegin = function(self)
AAirUnit.OnWorkBegin(self)
ChangeState(self, self.WorkingState)
end,

OnWorkEnd = function(self)
AAirUnit.OnWorkEnd(self)
ChangeState(self, self.FinishedWorkingState)
end,

OnWorkFailed = function(self)
AAirUnit.OnWorkEnd(self)
ChangeState(self, self.DroneMaintenanceState)
end,
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: Variable drones number based on enhancement

Postby DDDX » 12 Nov 2018, 17:37

solved ;)

I managed to find a working state and implement it in my code ;)

Now not only do my drones rebuild after enhancing, it also works with multiple enhancements calling for different numbers of drones (so I am able to have more or less of them if I so desire, with different enhancements, and they will rebuild without the need for a big script like the UEF ACU has).

Simply duplicate the DroneSetup script and have it trigger for different enhancements, with multiple DroneData tables in the carrier's .bp file.

unsure if this can be done with different drones as models or must be with same drones (getting a non-existent bones error), no time to test it atm, but will give feedback later. It would be epic if it were possible ;) Possible workaround is editing drones themselves to get buffed if carrier gets enhancements.

-p.s. the code does not work during enhancing or building, no drones then-but does after they are finished or stopped. Good enough for me ;)


Code: Select all
    WorkingState = State {  -- needed to fix drones not being rebuilt upon enhancement obtained
        Main = function(self)
            while self.WorkProgress < 1 and not self.Dead do
                WaitSeconds(0.1)
            end
        end,

        OnWorkEnd = function(self, work)
            self:ClearWork()
            self:SetActiveConsumptionInactive()
            AddUnitEnhancement(self, work)
            self:CleanupEnhancementEffects(work)
            self:CreateEnhancement(work)
            self:PlayUnitSound('EnhanceEnd')
            self:StopUnitAmbientSound('EnhanceLoop')
            self:EnableDefaultToggleCaps()
            --ChangeState(self, self.IdleState)
            ChangeState(self, self.DroneMaintenanceState)
        end,
},

    OnStartBuild = function(self, unitBuilding, order)   --for drones not being built when the carrier builds other stuff
        AAirUnit.OnStartBuild(self, unitBuilding, order)
        self.UnitBeingBuilt = unitBuilding
        ChangeState(self, self.BuildingState)
      --  ChangeState(self, self.DroneMaintenanceState)
    end,

    OnStopBuild = function(self, unitBeingBuilt)
        AAirUnit.OnStopBuild(self, unitBeingBuilt)
        --ChangeState(self, self.FinishedBuildingState)
        ChangeState(self, self.DroneMaintenanceState)
    end,

    OnFailedToBuild = function(self)
        AAirUnit.OnFailedToBuild(self)
        ChangeState(self, self.DroneMaintenanceState)
    end,
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: Variable drones number based on enhancement

Postby Franck83 » 12 Nov 2018, 19:50

Good job DDDX, for the topic purpose and for future modders uses, can you indicate the steps and the files you modified in a more ordered manner. Ty for your contribution ;).
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Variable drones number based on enhancement

Postby DDDX » 13 Nov 2018, 02:03

Finally I am able to do something here without bothering Uveso and others ;)

Ok, so steps to making any unit a drone carrier unit like the Blackop's Tempest or Goliath are:
(any half decent coder knows this already, consider this a beginner's guide to drones).

Basically 4 things are needed, first you make more DroneData tables, with different names ofc, inside the "carrier" unit's .bp script.
(ofc, you need to add other segments that pertain to drones, like 'PODSTAGINGPLATFORM' or GuardScanRadius (they are easy to spot compering a carrier and a non-carrier's .bp)).
Then you copy the entire code from Tempest's or Goliath's .script file concerning drones (I will have in my mod (Survival Mayhem&BO balance) the older version because...I made it before the Blackops patched it and also I needed to modify it a bit, for example the targets that the drones attack, the effects when they respawn. You can find it in the units folder of that mod, specifically units xaa9905, xaa9904, 3, 2 and 1.), the newest Blackops:unleashed patch did some changes as in it made the carriers (drone hosts ) into a new CLASS of units, and that file then gets called by every carrier .script, so that there is no need to set-up drones via them, the class script handles it instead when the carrier unit references it.

This is all you need to call it:

Code: Select all
local BaseTransport = import('/lua/defaultunits.lua').BaseTransport                                                     
local AirDroneCarrier = import('/mods/BlackOpsFAF-Unleashed/lua/BlackOpsunits.lua').AirDroneCarrier        -- the bit that does the actual work, take a look to see what it does and how and how it is different than individual DroneSetup in my xaa9901-5 units in my mod)

XAA9901 = Class(BaseTransport, AAirUnit, AirDroneCarrier) {  --this is how we call the carrier Blackops script

-- Create drones                                                           --goes in OnStopBeingBuilt
        ChangeState(self, self.DroneMaintenanceState)
        AirDroneCarrier.InitDrones(self)          -- this creates them via the Blackops carrier script. Place it here to have drones right away, or place it under an enhancement to activate it via an enhancement

    OnDamage = function(self, instigator, amount, vector, damagetype)
        AAirUnit.OnDamage(self, instigator, amount, vector, damagetype)
        AirDroneCarrier.SetAttacker(self, instigator)
    end,

    --Drone control buttons
    OnScriptBitSet = function(self, bit)
        --Drone assist toggle, on
        if bit == 1 then
            self.DroneAssist = false
        --Drone recall button
        elseif bit == 7 then
            self:RecallDrones()
            --Pop button back up, as it's not actually a toggle
            self:SetScriptBit('RULEUTC_SpecialToggle', false)
        else
            AAirUnit.OnScriptBitSet(self, bit)
        end
    end,   
    OnScriptBitClear = function(self, bit)
        --Drone assist toggle, off
        if bit == 1 then
            self.DroneAssist = true
        --Recall button reset, do nothing
        elseif bit == 7 then
            return
        else
            AAirUnit.OnScriptBitClear(self, bit)
        end
    end,
   
    --Handles drone docking
    OnTransportAttach = function(self, attachBone, unit)
        self.DroneData[unit.Name].Docked = attachBone
        unit:SetDoNotTarget(true)
        BaseTransport.OnTransportAttach(self, attachBone, unit)
    end,
   
    --Handles drone undocking, also called when docked drones die
    OnTransportDetach = function(self, attachBone, unit)
        self.DroneData[unit.Name].Docked = false
        unit:SetDoNotTarget(false)
        if unit.Name == self.BuildingDrone then
            self:CleanupDroneMaintenance(self.BuildingDrone)
        end
        BaseTransport.OnTransportDetach(self, attachBone, unit)
    end,


    OnKilled = function(self, instigator, damagetype, overkillRatio)
        AAirUnit.OnKilled(self, instigator, damagetype, overkillRatio)

        --Kill our heartbeat thread
        KillThread(self.HeartBeatThread)
        --Clean up any in-progress construction
        ChangeState(self, self.DeadState)
        --Immediately kill existing drones
        self:KillAllDrones()
        local nrofBones = self:GetBoneCount() -1
        local watchBone = self:GetBlueprint().WatchBone or 0
    end,

    -- Set on unit death, ends production and consumption immediately
    DeadState = State {
        Main = function(self)
            if self.gettingBuilt == false then
                self:CleanupDroneMaintenance(nil, true)
            end
        end,


That's it as far as the carrier's .script file is concerned - mind you, that's the code for if you decide to make the Blackops script do the whole work. Seeing as how I needed the drones to target all units and not just air,and I wanted spawn and respawn effects to happen for drones, and some other things... I made individual drone carrier scripts. If you will need those, they will be available within Survival mayhem&BO balance mod, unit xaa9905-1

You can call DroneSetup from enhancements if you want drones to be gained through enhancement, or you can copy the whole carrier and DroneSetup script like I did in unit xaa9905 and then make several DroneSetups, each relevant to the different DroneData in carrier's .bp file
- that way you can call multiple drone configurations with different enhancements, for example 1.st enhancement gets you 4 drones, second gets you 4 more, third gets you 6 more (for a total of 14 ;)
IN BOTH THOSE CASES DRONE REBUILD WILL GET BROKEN AS SOON A S YOU BUILD OR MAKE AN ENHANCEMENT (if you have it)

NOW for the useful part - getting drones to rebuild.
-the 3.rd thing you need.
Using enhancements, or building with the unit changes the carrier's state, so that it is no longer DroneMaintenance.
We restart it using this, for each of the things that change the state (building, finishing building, stopping the build, getting enhancement)

Code: Select all
WorkingState = State {  -- needed to fix drones not being rebuilt
        Main = function(self)
            while self.WorkProgress < 1 and not self.Dead do
                WaitSeconds(0.1)
            end
        end,

        OnWorkEnd = function(self, work)
            self:ClearWork()
            self:SetActiveConsumptionInactive()
            AddUnitEnhancement(self, work)
            self:CleanupEnhancementEffects(work)
            self:CreateEnhancement(work)
            self:PlayUnitSound('EnhanceEnd')
            self:StopUnitAmbientSound('EnhanceLoop')
            self:EnableDefaultToggleCaps()
            --ChangeState(self, self.IdleState)
            ChangeState(self, self.DroneMaintenanceState)
        end,   

        OnWorkFail = function(self, work)    --if you cancel an enhancement upgrade - i did not have time to test it yet
            self:ClearWork()
            self:SetActiveConsumptionInactive()
            self:PlayUnitSound('EnhanceFail')
            self:StopUnitAmbientSound('EnhanceLoop')
            self:CleanupEnhancementEffects()
            ChangeState(self, self.DroneMaintenanceState)
        end,
    },

    OnStartBuild = function(self, unitBuilding, order)  --same thing, but for when the carrier builds stuff
        AAirUnit.OnStartBuild(self, unitBuilding, order)
        self.UnitBeingBuilt = unitBuilding
        ChangeState(self, self.BuildingState)
      --  ChangeState(self, self.DroneMaintenanceState)
    end,

    OnStopBuild = function(self, unitBeingBuilt)
        AAirUnit.OnStopBuild(self, unitBeingBuilt)
        --ChangeState(self, self.FinishedBuildingState)
        ChangeState(self, self.DroneMaintenanceState)
    end,

    OnFailedToBuild = function(self)
        AAirUnit.OnFailedToBuild(self)
        ChangeState(self, self.DroneMaintenanceState)
    end,


The fourth thing is setting up the actual drone's .script and .bp file to make it into a drone, but you can copy that from BlackOps drones.

And that's it. 2 problems' though - the drones do not get rebuilt during carrier's time it is constructing units/buildings (but do when the building is done, or stopped)
and they do not spawn while the unit is getting an enhancement (but do as soon as you get it).
However, it could be argued that a unit cannot build 2 things at the same time, no? ;)

P.S. look for version 100+ of the Survival Mayhem&bo balance mod (i will upload it soon), earlier versions of it do not have units xaa9905,4,3,2,1 yet.
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Previous

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest