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:
Code
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



http://www.staredit.net/wiki/index.php/Kills_to_cash




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."
-Tiger

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
Code
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:

Code
        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]


Oct 5 2020, 6:25 pm Netbek Post #5



Voyager, it works so far, but how do I check if the owner of "target" is an enemy of "attacker"?

EDIT: nvm, I just found the "isTargetEnemy(target)" function :)
this is what the code looks like:
Code
if(target && attacker && damage >= target->hitPoints && attacker->isTargetEnemy(target)) {
    if(attacker->id == UnitId::TerranVulture && target->id == UnitId::ZergZergling) {
        resources->minerals[attackingPlayerId] += 3;
    }
}

I inserted it in "weapon_damage.cpp", above the science vessel lines you mentioned. I additonally made it check the unit type of attacker and target.
Thank you very much once again!

FOR FUTURE SEARCHERS:
I attached the full modified "weapon_damage.cpp". I used the General-Plugin-Template-Project for Visual Studio 2008. For step-by-step image tutorial on SC1 plugin creation, see my posts here & here

Attachments:
weapon_damage.cpp
Hits: 0 Size: 4.8kb

Post has been edited 1 time(s), last time on Oct 5 2020, 6:45 pm by Netbek.




Oct 5 2020, 6:45 pm Voyager7456 Post #6

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

scbw::isAlliedTo(attacker->playerId, target->playerId) will return true if target is allied to attacker.

EDIT: beat me to it



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]


Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[2026-10-11. : 6:02 am]
Donald -- Samase
[2026-10-09. : 2:53 am]
Mr.BurnLiquid -- Symmetry
Symmetry shouted: I'll check it out this weekend!
Thanks
[2026-10-09. : 2:47 am]
Symmetry -- I'll check it out this weekend!
[2026-10-09. : 2:40 am]
Mr.BurnLiquid -- Symmetry
Symmetry shouted: Another map maker? Damn we really ARE back
I invite you to try out the map I modified. I don't have the creativity to create maps from scratch, but I do have the know-how to modify existing ones; my project is to tweak community campaigns (specifically those with errors—to make them playable.
[2026-10-09. : 2:27 am]
Symmetry -- Another map maker? Damn we really ARE back
[2026-10-09. : 1:51 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: Mr.BurnLiquid actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Now that I wanted to change my avatar, the error image is showing up, haha.
[2026-10-09. : 1:34 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: Mr.BurnLiquid actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Mr.BurnLiquid
Mr.BurnLiquid shouted: Ultraviolet Thanks; I'm new to the site and a Spanish speaker. I must have missed the part where it was prohibited—I'll change it now.
I invite you to try out a mission I'm modifying from *StarCraft Reversed*; I'm trying to make it more playable and challenging.
[2026-10-09. : 1:33 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: Mr.BurnLiquid actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Thanks; I'm new to the site and a Spanish speaker. I must have missed the part where it was prohibited—I'll change it now.
[2026-10-09. : 1:31 am]
Ultraviolet -- Mr.BurnLiquid
Mr.BurnLiquid shouted: Ultraviolet Is it forbidden to have a large avatar?
actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Please log in to shout.


Members Online: Symmetry, Butch, Ultraviolet