Staredit Network > Forums > Modding Assistance > Topic: Resource gain upon kill
Resource gain upon kill
Sep 7 2020, 1:41 pm
By: Netbek  

Sep 7 2020, 1:41 pm Netbek Post #1

When certain unit types kill certain enemy unit types, it's suppossed to generate some ore/minerals income.
I already know the code to use in the general-plugin-template-project in order to increase a players ore/gas, but that's about it:
resources->minerals[unit->playerId] += 1;

What code would I need to detect the killing unit, as well as the killed unit? Which file from GPTP would I need to change? Coding help plz! :0_o:

P.S.: As a bonus, I'd like the income gain to only occur when a certain tech is researched.

Sep 7 2020, 3:31 pm lifebot Post #2

Sep 7 2020, 4:59 pm MTiger156 Post #3

Veteran Mapper

It's possible to do this entirely with EUDs, including the Tech requirement.

Once in a DAT Editor, you can view or modify any unit's kill score. Keep those values in mind when creating your "Kill Score" trigger(s).
Use subtraction (instead of setting) when converting Kill Score to minerals. That way, units of a higher score can yield more minerals. It also allows multi-kills to be calculated correctly.

To add a Tech requirement to this system, add a Switch condition to the conversion trigger(s). Then with EUD triggers, when the player researches the desired Tech, set that Switch. (Also immediately set Kill Score to 0 at that point unless you want all prior kills to count)

"It takes far more than a simple ideology to map amazing things. Mapping requires a strong passion for SC as well as an even stronger devotion to your work. Avoid instant gratification. Set directions/goals for the map, and stick to them. Take pride in the work, be patient with it, and never settle for less."

Sep 12 2020, 3:04 pm Voyager7456 Post #4

Responsible for my own happiness? I can't even be responsible for my own breakfast

Guys, this is Modding Assistance.

Netbek - I think the easiest place to do this would be in weaponDamageHook in weapon_damage.cpp. That function has the attacking unit and target unit as arguments, so it should have everything you need. Right above the line
target->damageHp(damage, attacker, attackingPlayerId,
                            weaponId != WeaponId::Irradiate);         //Prevent Science Vessels from being continuously revealed to the irradiated target

I would add something along these lines:

        if(target && attacker && damage >= target->hitPoints && scbw::hasTechResearched(attackingPlayerId, TechId::YourTech)) {
            resources->minerals[attackingPlayerId] += 1;

all i am is a contrary canary
but i'm crazy for you
i watched you cradling a tissue box
sneezing and sniffling, you were still a fox

Modding Resources: The Necromodicon [WIP] | Mod Night
My Projects: SCFC | ARAI | Excision [WIP] | SCFC2 [BETA] | Robots vs. Humans | Leviathan Wakes [BETA]

  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[02:25 am]
MTiger156 -- w
[12:38 am]
lil-Inferno -- u
[2020-9-17. : 4:14 pm]
Voyager7456 -- u
[2020-9-17. : 10:09 am]
NudeRaider -- also entirely not the point of what I said.
[2020-9-17. : 10:09 am]
NudeRaider -- Corbo
Corbo shouted: NudeRaider hard to believe this had 1000 active users past month
active user probably a couple dozen. But hard to differentiate the lurkers from the bots. Don't know a good way to determine an estimate either.
[2020-9-17. : 7:43 am]
Oh_Man -- the new harry potter game looks too good to be true #Iwanttobelieve
[2020-9-17. : 5:13 am]
Ultraviolet -- man I can't remember where I found the bring at most 0 glitch described recently
[2020-9-17. : 4:00 am]
Corbo -- i mean, voy still connects xdxdxd
[2020-9-17. : 3:45 am]
O)FaRTy1billion[MM] -- "probably" implying there's a chance it wasn't xd
[2020-9-17. : 3:40 am]
Corbo -- probably all bots
Please log in to shout.

Members Online: jjf28, Oh_Man, lil-Inferno, jun3hong