How to make a unit gain "experience" and level up?

Everything about mods can be found here.

Moderator: Morax

How to make a unit gain "experience" and level up?

Postby DDDX » 14 Oct 2018, 11:35

Hi guys.
Need some advice.
For the purpose of making a RPG - style unit, is it possible to code a detection in mass value killed, so that when you have killed let's say 1 million worth of mass with that unit, the map script would then remove the unit in question and replace it with a bigger, better, stronger version of itself?

The part I am having trouble with is the detecting of mass killed. Now, i remember once reading of a mod that plays around with unit stats based on that unit's veterancy, by making it have a shield on higher vet levels or even becoming a different unit altogether when it vets, but I cannot remember what that mod was. If it exists, it would be a good workaround for me if the mass killed thing is not possible to code.

Any ideas? Thanx in advance.
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: How to make a unit gain "experience" and level up?

Postby Franck83 » 14 Oct 2018, 13:29

You have a deep veterancy system on Alliance of Heroes mod.

The best way to do what to want is to hook the onKilled function in unit.lua
Code: Select all
   OldOnKilledUnit = Unit.OnKilledUnit,
   OnKilledUnit = function(self, unitKilled, massKilled)
      if not massKilled or massKilled == 0 then return end -- Make sure engine calls aren't passed with massKilled == 0
      if IsAlly(self:GetArmy(), unitKilled:GetArmy()) then return end -- No XP for friendly fire...
      self.MassKilled = self.MassKilled + massKilled -- Saving Mass Killed by unit
      -- Your stuff : unit creation or buffing
      ---------------------------------------
      Unit.OldOnKilledUnit(self, unitKilled, massKilled)
    end,


About the replacing system, do you want to keep the current unit graphic model ?

if yes, you can just apply a buff on your unit (that can boost, health, max health, damage, speed, rate of fire, regen...)
If no, you need a new model, you need to kill your unit (without explosion) and create a new graphic model :
for example
Code: Select all
local pos = uniKilled:GetPosition()
local unit = aiBrain:CreateUnitNearSpot('URL0107', pos[1], pos[3])


I'm not sure about pos[3], it's maybe pos[2], cause you have x, y, z position. You need to add some conditions depending of mass killed and unit models...

Ask if you need more information
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: How to make a unit gain "experience" and level up?

Postby Uveso » 14 Oct 2018, 14:45

Modifying the unit.lua will loop over every unit and count every masskill.
If you only want a single unit to count then modify only the unitscript like this:

Hooking 'OnKilledUnit' from unitscript:
Code: Select all
local TConstructionUnit = import('/lua/terranunits.lua').TConstructionUnit
local MassKilled = 0

DUMMY0815 = Class(TConstructionUnit) {
    OnKilledUnit = function(self, unitKilled, massKilled)
        -- add the mass of this kill to our mass counter
        MassKilled = MassKilled + massKilled
        -- if we killed over 1,000,000 mass then...
        if MassKilled > 1000000 then
            --do stuff here like creating new unit etc.
        end
        -- call the original function, so we don't break it.
        TConstructionUnit.OnKilledUnit(self, unitKilled, massKilled)
    end,
}
TypeClass = DUMMY0815
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: How to make a unit gain "experience" and level up?

Postby DDDX » 14 Oct 2018, 18:36

awesome. Thank you!!
I was hoping something like that would be possible.
I can remove wrecks, figure out positions, disable detah animations etc, that's not the problem. What I don't know i figure out through trial and error. This last piece of code, for specific units is exactly what I needed. i shall also look into the Alliance of heroes mod for more info.
Thanx again, man!
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