[QUESTION] Add (max) HP on taking damage? / [now: Veterancy Mod]

I’m trying to do something like, e.g., “every time X hp is lost, max hp is increased by Y”. Can anyone point me in the right direction in terms of scripting this?

If this is impossible, I’m hoping that something like “increment all living ShipType HP by 1 per second” will be doable.

I’m not a complete modding novice, but I can’t think of how to implement this – of course .ship files have a max health variable, and there’s an AddShipMultiplier function that can change max health, but both (if I understand correctly) affect all ships of the specified type, instead of changing individual ship stats.

I’m just not sure how to trigger a change to an individual ship’s stats based on a timer or event. THANK YOU a ton for any assistance!

On this way, you need to create temporary SobGroup for your ship. And you can use matrix to have all ship identify in this matrix. [ In SSC, we use matrix to place one by one ship in one place, if place is taken by ship, we place this ship in free area ]

You need to use, to know status of your ship : http://hw2bsg.org/wiki.hw2.info/FunctionSobGroup_HealthPercentage.html

To change the Health of the ship in this SobGroup [Try to have only one ship in this SobGroup, or, if you have X ship, you need to multiplied by X your value … You can use variable to have dynamic script :wink: ]
http://hw2bsg.org/wiki.hw2.info/FunctionSobGroup_SetHealth.html

[ Note : Need to be more 1, 1 is the full max health say in .ship .]

You have some way’s to made this … Probably other method but i see only this one right now… :slight_smile:

1 Like

SobGroup_SetHealth doesn’t change the maximum health of the ship, just the current health (which may or may not be more than the maximum health of the ship, leaving you with, for example, 130% health).

1 Like

Yeah, something like temporary Health point.

But you can’t change the value in the game [Value of .ship], except via Research …

@BitVenom : If any way to do that [Change value except via Research], without the use of SobGroup_SetHealth [It’s boost, but when ship loose this value of healt, he CAN’T retrieves this health ^^] …

1 Like

Thank you very much for the help, Pascal! (and radar3301!)

So I create a temporary SobGroup, and SobGroup_SetHealth will let me boost the HP of those ships (but not permanently). I think I get it. :slight_smile: (I’m not sure how to use a matrix like you say, though – I looked here: http://hw2bsg.org/wiki.hw2.info/FunctionReference.html – but I don’t see any matrix function, so probably I have misunderstood!)

Hmm… re: research: do you guys think that maybe I could create a series of custom researches and apply them to ships as needed? Like: “If ship takes 25 / 50 / 75% damage, apply HP-Research 1/2/3”? (Or, if it is easier, “If ship is alive for 5/10/15 minutes, apply HP-Research 1/2/3”?)

Or will the researches end up being applied to ALL ships (present and future) of the type, instead of just those in the SobGroup?

Maybe it could be worked around by creating duplicate ships with a different identifier, and replacing “old” ships as needed: say, once a ship of ShipType1 meets the criterion we want, replace it with ShipType2 that has the adjusted stat (but is otherwise identical). E.g., FlakFrigate turns into FlakFrigate2, all the same except with +1000 hp (or whatever).

Does anything like these ideas seem practical or possible at all?

Again, thank you very much for the assistance; I really appreciate it more than I can say. It’s huge for me! :slight_smile:

Actually : You can only apply to one type of ship, or all ship or all capital etc …
But you can’t apply to SobGroup.

Or we don’t discover this ^^

Dang! You’re referring to the research idea, right?

It’s looking like the best option, then, is either the SobGroup_SetHealth boost, or maybe replacing ships with edited duplicates. Do you think that could work? That is, create a SobGroup for a ship (say: a Flak Frigate), check its HP percent, and if it reaches 50% (or whatever) then replace that Flak Frigate with a “Flak Frigate 2” in the same position?

You can Despawn ship and respawn new one. But you need to know the location and rotation of the previous ship before replace ship ^^

But you need to create function for this.

Or, @BitVenom can say if we have already function can return coordinate of SobGroup, if this SobGroup have only one ship. If not, it’s a suggestion.

2 Likes

By “matrix”, he might have meant “array.” (Forgive me for assuming, but I don’t believe English is his native language, and some meanings get lost in translation.)

[quote=“Jormungandr, post:5, topic:1245263”]
Or will the researches end up being applied to ALL ships (present and future) of the type, instead of just those in the SobGroup?
[/quote]Yes, all ships of that type would be affected.

[quote=“Jormungandr, post:5, topic:1245263”]
Maybe it could be worked around by creating duplicate ships with a different identifier, and replacing “old” ships as needed: say, once a ship of ShipType1 meets the criterion we want, replace it with ShipType2 that has the adjusted stat (but is otherwise identical). E.g., FlakFrigate turns into FlakFrigate2, all the same except with +1000 hp (or whatever).
[/quote]As you say in your next sentence, this isn’t very practical, but it is possible (technically, although the workaround is quite the ugly beast).

1 Like

Thanks, radar3301 – that all makes sense. Really appreciate the help. :slight_smile: Pascal, I think we do have a function that returns a SobGroup position! I hope this is right.

So, I’m willing to try the ugly beast! A few final (ha!) more questions for the HW modding geniuses here at GBForums :smiley: :

1.) Er, super noob, but… how do I add the right units to a SobGroup?! I see some functions to create empty SobGroup, but I’m not sure how to get something like “all Flak Frigates” into it.

2.) Do you think it is possible to track how “old” a unit is, e.g. set up a timer on its creation perhaps, and thus do my “replace with ShipType2” function based on how long the unit has been alive? Or will it be better to use the damage-based (“if any [ShipType] falls to x% hp”) trigger for the replacement, like originally planned?

3.) I’m thinking of adding subsystems or defense fields instead of outright replacing a ship. So maybe, if it is much easier, I could just trigger the addition of a new weapons subsystem for +damage, or add extra defense with a defense field. It’s not quite what I originally planned, but what do you guys think?


If anyone is curious, the motivation for all this is to represent “veterancy” (saying that, I hope this hasn’t been an example of the “XY problem”!) – ships should be worth keeping around, right? – so +HP (or defense field?) is supposed to represent “this crew is pretty experienced now”.

I’m excited to try to start implementing this stuff (I’m about to go test a subsystem bug I read about that might help, fingers crossed!), I just want to make sure I’m not going down toward a dead end. That’s why your help has been so invaluable; again, I really appreciate it, @pascal76680 & @radar3301. :slight_smile:

I got a bee in my bonnet about this, now that you mention veterancy… Stay tuned while I do a write-up!

1 Like

Here’s what I’ve come up with.

Code:

data:scripts\lib\veteran.lua

-- Some tunables
MAX_VETERAN_RANK = 5 -- After this many ranks of veterancy, stop gaining ranks
VETERAN_RANK_UP = { 30, 120, 270, 480, 750 } -- experience needed for level up
UPDATE_FREQUENCY = 1
-- Code
veterancy = {}
function NewVeteranShip(CustomGroup, playerIndex, shipID)
    ship = {}
    ship.CustomGroup = CustomGroup
    ship.playerIndex = playerIndex
    ship.shipID = shipID
    ship.timeCreated = Universe_GameTime()
    ship.experience = 0
    ship.rank = 0
    return ship
end
function Create_VeteranShip(CustomGroup, playerIndex, shipID)
    veterancy[tostring(shipID)] = NewVeteranShip(CustomGroup, playerIndex, shipID)
end
function Update_VeteranShip(CustomGroup, playerIndex, shipID)
    -- timeAlive = Universe_GameTime() - veterancy[tostring(shipID)].timeCreated
    ship = veterancy[tostring(shipID)];
    if (ship ~= nil) then
        if (SobGroup_UnderAttack(CustomGroup) == 1) then
            ship.experience = ship.experience + UPDATE_FREQUENCY
        end
        if ((ship.experience >= VETERAN_RANK_UP[ship.rank)) and (ship.rank < MAX_VETERAN_RANK)) then
            ship.rank = ship.rank + 1
            SobGroup_CreateSubSystem(CustomGroup, "vet_mod_rank" .. ship.rank)
        end
    end
end
function Destroy_VeteranShip(CustomGroup, playerIndex, shipID)	
    veterancy[tostring(shipID)] = nil
end

In your ship file (replace <sShipName> with the actual ship name):

addCustomCode(NewShipType,"data:scripts\lib\veteran.lua","","Create_VeteranShip","Update_VeteranShip","Destroy_VeteranShip",<sShipName>,1) StartShipHardPointConfig(NewShipType,"Veteran1","Hardpoint_Veteran1","System","Innate","Indestructible","","vet_rank_mod1","","","","","","",""); StartShipHardPointConfig(NewShipType,"Veteran2","Hardpoint_Veteran2","System","Innate","Indestructible","","vet_rank_mod2","","","","","","",""); StartShipHardPointConfig(NewShipType,"Veteran3","Hardpoint_Veteran3","System","Innate","Indestructible","","vet_rank_mod3","","","","","","",""); StartShipHardPointConfig(NewShipType,"Veteran4","Hardpoint_Veteran4","System","Innate","Indestructible","","vet_rank_mod4","","","","","","",""); StartShipHardPointConfig(NewShipType,"Veteran5","Hardpoint_Veteran5","System","Innate","Indestructible","","vet_rank_mod5","","","","","","","");

Create 5 subsystems with empty (or 1 small polygon) meshes, and name them “vet_mod_rankN.”

Add modifiers to those subsystems in their respective “.subs” files to reflect the bonuses you’d like to add at each rank of veterancy.


Note: I haven’t actually tested this code, so it might be broken, but let me know if it doesn’t work.

Edit: The nice thing about having the “vet_mod_rankN” subsystems is that you can pick more than one ability to add at a certain rank (similar to DoK); and you can do more than one ability per rank!


Edit: And this entire system can support customization, too!

2 Likes

WOW, this is FANTASTIC! Thanks times a million – I guess it was an “XY problem” after all, because I think this is way better than whatever I’d have eventually come up with!

If I read this correctly, you’ve left a (commented) “timeAlive” function just in case, but have gone with a more natural “time in combat” measure. I’m staggered at how excellently this works out – I truly never thought that an “exp” system could be implemented; fantastic, again. :slight_smile:

I’m gonna rush off and try it, to report back! If I understand aright, we can use AddSubSystemMultiplier in the .subs file for each subsystem… and the sky’s the limit – there are a LOT of modifiable values! Veteran ships can have better accuracy, hp, damage…

(I also found this bug where a subsystem stat can take precedence over a ship stat, but I’m not quite sure what the use of it is even if it’s still around, considering what AddSubSystemModifier gives us.)

Amazing!!!

Now all you need is a ui icon to show the veteran status… @Dwarfinator?

Yes. Of course, I just chose an arbitrary value, but in theory, any number of events (kills, heals, RUs collected, etc) could trigger the XP gain.

(actually, I don’t know if kills could be recorded; it would likely be a very expensive set of calculations)

IIRC, the subsystem slots will show up on the ship details, so we’d just need subsystem icons. But I’m sure a new healthbar UI style could be created to add this functionality as well.

Update & apologies for the delay in getting this working – if I may make my excuses under the pretense that you’ve all been waiting for my basically unimportant input ;), I’m blaming school + catching some kind of cold… plus my abortive attempt at HW “modeling”, heh. Everything else is in place, so as soon as I figure out how to get HODOR to like my subsystem meshes, I’ll be able to test/experiment.

3D modeling (and texturing) is intimidating, since I’m not too terribly artsy, but if I (we) get this working I’m thinking of trying to work up those subsystem icons and make it all fancy-polished. Maybe stars or chevrons? But first I’ve got to be able to add the tiny featureless sphere linked above, heh.

So close… but I’ve been unable to get this working – Homeworld reports an access violation when attempting to start (load) a CPU game, sometime during or after the “Universe” bit. It is entirely possible I’ve installed the mod incorrectly, though.

What I’ve done:

  • Used the cloak generator subsystem meshes for the vet_mod_rankN subsystems. Used cloak generator .subs files, too, just in case any of those lines are always required; with a few changes like “visible=0” instead of =1, and of course the addition of a veterancy multiplier (speed, to test) instead of cloaking ability.

  • Tested with torpedo frigate. I reckon <‎sShipName>, in the custom code for the .ship file, needs to be replaced with hgn_torpedofrigate in this case, but if that’s not right let me know. (I also notice that the .ship custom code refers to vet_rank_modN instead of vet_mod_rankN, so I changed that too.)

  • I’ve uploaded a zip with the files and file hierarchies HERE for your inspection.


I tried a variety of ways to install – putting script, ship, and subsystem folders in a VetMod master folder and putting it in \Data\ and using -overridebigfile (no effect), putting the three subfolders in \Data\ without the VetMod folder and using -overridebigfile (crash), putting the VetMod folder in \HomeworldRM\ and editing the scripts a bit to use the new path and using “-moddatapath VetMod” (nothing), putting the folder in \Data\ and using “-moddatapath Data\VetMod” (crash), etc.

So either the game would work fine but not include any changes (including basic ones such as changing torpedo frigate HP to 200000), or it would crash with “Access Violation” dialog box halfway through loading a skirmish.

Any ideas? (*looks at @radar3301 with hopeful eyes* save me! :stuck_out_tongue: ) I’m sure that some of the ways I tried installing it are wrong, but with the -moddatapath options I’ve managed some working, albeit simple, edits to ship values and so forth before… so I’m at a bit of a loss as to what might be causing the “Access Violation”.

I got a corrupted Archive. I’ll try downloading again when I get home from work tonight and some other errands I have to run (like 12 hours from now!).

My initial glance at your attempts suggest this though:

  • The code is looking for “vet_mod_rankN”, where N is a number from 1 to 5. (We can change this to “hgn_vetrank1” for the purposes of the test.)
  • [quote=“radar3301, post:12, topic:1245263”]
    In your ship file (replace <sShipName> with the actual ship name):
    [/quote]
  • Since you used the hgn_torpedofrigate hod, it does not contain an actual hardpoint named “Hardpoint_Veteran…”, so I would guess that’s where the Access Violation is occurring.
  • This is correct:
  • Add “-luatrace” to your command line as well.

I’m sure I might have missed responding to something else, but there’s a start. (And now I’m off to work!)

1 Like

I’ll try downloading again when I get home from work tonight and some other errands I have to run (like 12 hours from now!).

Long day! Good luck & don’t work too hard. :slight_smile: Re: the archive, I tried downloading and opening it, and it appeared intact in this case, but if necessary I can always try compressing and uploading it again (perhaps with another host, and/or an updated 7zip). (Edit: Here’s another version, updated with my attempt at adding hardpoints.)

The code is looking for “vet_mod_rankN”, where N is a number from 1 to 5. (We can change this to “hgn_vetrank1” for the purposes of the test.)

Right – if this refers to the subsystem names, I’ve arranged them like: data:subsystem\vet_mod_rank1\vet_mod_rank1.hod and .subs files; and so on up to 5.

Since you used the hgn_torpedofrigate hod, it does not contain an actual hardpoint named “Hardpoint_Veteran…”, so I would guess that’s where the Access Violation is occurring.

Aha! Well, that explains a lot, d’oh. Thanks for pointing it out! :thumbsup: Tentative solution: use “HardEd” or “CFHodEd” tool to add correctly-named hardpoints (Hardpoint_VeteranN) to each ship I want able to use the veterancy subsystems. In process now!


Edit: Dang, something’s still funky. I used CFHodEd to add hardpoints as per the instructions in an old tutorial – that is: open the torpedo frigate model in CFHodEd, go to “joints”, and add new ones with the appropriate names on Root.

I added -luatrace, but it doesn’t seem to record any error in HwRM.log at all. It tells me about the archives it loaded, then just ends like so:

 CmdLine: -overridebigfile -luatrace -dlccampaign HW2Campaign.big -campaign Ascension -moviepath DataHW2Campaign 
 12 Races Discovered 
 Race Filtering: DEATHMATCH rules - @Deathmatch 
 Starting Level: DATA:\LevelData\Multiplayer\DeathMatchHW2\2p_hostilities_end.level 
 Restoring video mode 
 Display: (0, 0, 1366, 768) - (0, 0) 
 Display: (0, 0, 100, 100) - (8, 31) 
 Display: (0, 0, 100, 100) - (8, 31) 

(I can post the rest if needed, but I didn’t want to clutter up the post and throw a lot of irrelevant data at you, heh.) The automatic error log has a bunch of hex numbers and other incomprehensible stuff recorded, but “Read from location 00000000 caused an access violation.” is the only bit I know is relevant.