Mind control/hacker weapon

Everything about mods can be found here.

Moderator: Morax

Mind control/hacker weapon

Postby DDDX » 02 Nov 2019, 01:23

Hi guys.

Ok so... I'd like to give a weapon when fired at an enemy (namely overcharge), a certain % chance of giving over control of the targeted unit instead of damaging it. A sort of mind control, if you will.

I am currently stuck on the piece of code needed to actually do the unit ownership transfer itself.
Basically, I edit OnImpact of the weapon so that I
1. exclude any overpowered categories from any ownership transfer chance whatsoever,
2. Create a 20% initial chance of the event triggering
3. further create a 50:50 chance if the target is an experimental unit

4 ...yeah...now would come the actual transferring of the unit that was hit by the projectile to a new owner.

How would one go about that? Can it even be done directly within the OnImpact (or OnWeaponFired)?

Clearly unit ownership can be transferred. I just need a way to apply that to the current target of a weapon.

Here's my seriously lacking script so far
Code: Select all

        OverCharge = Class(TDFOverchargeWeapon) {
           --give us a % chance of mind control of the target instead of damaging it
            OnImpact = function(self, TargetType, TargetEntity) 
                --first let's exclude OP units
                if not EntityCategoryContains(categories.COMMAND + categories.BOSS + categories.OMEGA, TargetEntity) then
                    local mcChance = 1
                    local mcChance2 = 1
                    mcChance = math.random(1, 5)  --20% chance of success
                    mcChance2 = math.random(1, 2)  --50% chance of success to further reduce getting experimentals
                    if mcChance == 2 then  --we got a winner!!!!!
                        if EntityCategoryContains(categories.EXPERIMENTAL) then    --the target is an experimental, go for the second filter       
                            if mcChance2 == 2 then --we got a winner again!!!

                               --(target gets mind controlled)

                            else
                                TDFOverchargeWeapon.OnImpact(self, TargetType, TargetEntity)
                            end
                        else

                             --(target gets mind controlled)

                        end
                    else
                        TDFOverchargeWeapon.OnImpact(self, TargetType, TargetEntity)
                    end
                else  --apply damage as usual
                    TDFOverchargeWeapon.OnImpact(self, TargetType, TargetEntity)
                end
            end,     
        },


If anyone has any clue how to do this OR EVEN BETTER, KNOWS OF A MOD WHERE IT IS ALREADY DONE so I figure it for myself, that would be just epic.
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: Mind control/hacker weapon

Postby nine2 » 02 Nov 2019, 06:11

I don't know - but I'm sure you know its possible for users to gift units to their ally. I would follow the code path from the ui to the sim layer to see how it does that. Maybe that is something you can use, maybe not.
nine2
Councillor - Promotion
 
Posts: 2416
Joined: 16 Apr 2013, 10:10
Has liked: 285 times
Been liked: 515 times
FAF User Name: Anihilnine

Re: Mind control/hacker weapon

Postby DDDX » 03 Nov 2019, 00:47

Thanks for your reply.
Yeah that's what I was hoping for.
I have found the appropriate code that handles unit gifting, but am too noob in coding to transmute it into something that triggers within a weapon fire.

For example, as far as I can tel OnImpact is a dud - does nothing for the weapon itself, but is there only in a projectile script, not weapon blueprint.

So i can either hook the OnFire function of the weapon itself, or the OnImpact of the projectile to mind control.

But again, that's the least of my concerns and not hard to do - once I have the main problem solved - actual "TransferUnitsOwnership" working with a weapon...

One way comes to mind - the Loyalty gun from SupCom2. It is a long range point defence that does exactly what i need - perhaps there's something there I can use, or at least to fighure out how it's done.
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: Mind control/hacker weapon

Postby DDDX » 03 Nov 2019, 17:23

yeah...SupCom2 is too different for me to catch heads or tails of it.
Back to the scripts we know then :p

So, I got the TransferUnitsOwnership function here
https://github.com/FAForever/fa/blob/775b4b00ec0474dc112537c9938c081e0810cb3c/lua/SimUtils.lua#L59%20BTW

Anyone willing to give me a hand on how to make it trigger for the current target of a weapon, so that the projectile converts it under my control?
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: Mind control/hacker weapon

Postby DDDX » 05 Nov 2019, 21:42

nobody interested in helping me make a mind control weapon, like the Loyalty gun from SupCom 2 ?
I'd think there'd be a lot of use for such a weapon, in many mods...I can already see ACU upgrades, turrets, sniper bots, even Aeon equivalent Fire beetles with such a weaponized ability...
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: Mind control/hacker weapon

Postby Exotic_Retard » 09 Nov 2019, 17:57

hey man, ping me on the nomads discord and i can walk you through how to do it, as well as answer any other questions you might have :>
https://discord.gg/eV3wmAX
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: Mind control/hacker weapon

Postby DDDX » 09 Nov 2019, 23:08

Ok for anyone wanting to make a mind control weapon, or aura, or whatever.
Here's the deal, curtesy of Exotic_Retard

First import the function with
local TransferUnitsOwnership = import('/lua/SimUtils.lua').TransferUnitsOwnership

Then call it in an event (be it OnFire, OnGotTarget, or in a projectile script with the OnImpact). Imma make it as a small % chance for each Overcharge fire, as well as an aura around my hero unit with a small chance of success on random units inside the aura range.

Here's a simple example how a weapon's script would be the one to handle it, when the weapon hits

Code: Select all
OnImpact = function(self, targetType, targetEntity)
        if targetType == 'Unit' then
            TransferUnitsOwnership({targetEntity}, self:GetArmy(), true)
            self:Destroy()
        else
            --OverchargeProjectile.OnImpact(self, targetType, targetEntity)
            APRoundCap.OnImpact(self, targetType, targetEntity)
        end
    end,


OFC, you can code all sorts of conditions and restrictions here, to not make it a 100% chance on everything.
A big THANK YOU to Exotic_Retard
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


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest