This Forum is inactive - Feel free to join our Discord

By now, our community has mostly migrated to Discord. This forum mainly serves as an archive nowadays, and isn't actively supervised anymore.
Feel free to head over to our Discord for a more active community. You're much more likely to get fast replies and support there than here.
Inzwischen ist unsere Community größtenteils auf unserem Discord-Server zu finden. Dieses Forum dient hauptsächlich noch als Archiv und wird nicht mehr aktiv betreut.
Schau gerne auf unserem Discord-Server vorbei - Dort findest Du die aktive Community und wirst viel wahrscheinlicher schnelle Antworten oder Unterstützung erhalten, als hier.

Spawn and de-spawn hero on tech level / multiplayer g-campaign

02 Nov 2015 02:11 #76287 von Imperial
As I said, it wont work if you insert a Squadron type unit in the Valid_Units list because the script requires the single units from that squad. You'd need to despawn all fighters of this squad one by one using a for loop.

You didnt specified that this is important to be saved longer then over 1 skirmish battle.

Well, I wrote an other script that upgrades 4x via ability, which hides the actual hero and spawns the new one.

After that match the original hero is still there, but saving the new hero would indeed require some fancy .xml scripting.

I can both offer you that script to modify it for your own purposes, and if you prefere to add the lines that hide the original unit as neutral unit on the map to the script I already covered here.

Bitte Anmelden um der Konversation beizutreten.

  • Locutus
  • Locutuss Avatar
  • Offline
  • Administrator
  • Administrator
  • [SGMG] Project Co-Lead, Lead Coder, 3D-Artist
02 Nov 2015 02:43 #76290 von Locutus

Imperial schrieb: BUUT, please dont use Squadron or HeroCompanys, because these are groups of Objects (containers) and the script would not detect them, instead use the actual SpaceUnits, or UniqueUnits, or Infantry .. what ever of these Squadrons/Teams so the script can detect them on the map and replace them.

There's a simple fix for that:
local unit_parent = unit.Get_Parent_Object()
	if TestValid(unit_parent) then
		unit = unit_parent

Bitte Anmelden um der Konversation beizutreten.

02 Nov 2015 19:44 #76309 von vlnikolic
Hello : )

So although quite versatile lua is able to help only in space-battle that involves SB of adequate tech-level, and the only hope for solving this problem is advanced XML that only few of us know
; )

There's a simple fix for that:

The only thing that we (mortals) can do now is to have faith in the force

0: )

Bitte Anmelden um der Konversation beizutreten.

03 Nov 2015 19:16 #76332 von Imperial
Ok I worked abit further on this script.
The good news is, the version in this post can hide all squad units and spawn one or more upgrade units to replace them.
It triggers for each Hero of this type and upgrades them. It also uses Register_Death_Event to cause the hidden units to make Harakiri after their upgrades were destroyed, so the Unit wont survive if their upgrade dies.

The bad news is it has drawbacks and glitches: If your Level 1 Unit is a Hero, and is limited to 1 - then the player can rebuild him after he hides, except if you set him to be <Build_Limit_Lifetime_Per_Player> 1, but then if the Harakiri function triggers to kill Level 1 after Level 2 was destroyed I fear the player wont be able to build a new one within the whole GC!

And if that hero has its icon dispayed I it isnt possible to hide that icon, the units will be hidden, but the icon will stay.

More bad news: There is a goddamn bug that always causes the game to crash after loading a savegame with hidden Units, it is a very critical bug, and I know it is caused by this line (it is used 2x)


Usually Change owner shouldnt cause a crash between the savegames, but sometimes it does because of the context with other code.
I already tried to put it into another context, even into an other sate.. messed 4 hours with it, without any result ... so I gave up on this.

I could exit the script after 1 Upgrade, that would solve the loadcrash bug. But then the script wouldnt continue checking for the harakiri event to kill the Lv1 version, so that would always survive. Further the continous check is needed to make sure the Units stay hidden after reloading the savegames (usually but for this scirpit loading wont work anyway).

I also updated the other version of this script in the last post, it is able to handle squadrons now (actually it was even before, tiny changes). It will destroy the original hero and he wont stay for the GC and have to be rebuilt, but it works without crashing the game after each reload.
The only thing what you have to make sure is:
If your hero squadron has 1 leader unit and all other fighters are generic, put the hero into slot 1 of the table Valid_Units, the upgrde unit to spawn in slot 2, and the generic fighters into slot 3. I only marked the Spawn_Unit line to not spawn another unit for the other type of figher, you can use this principle to do it for as many fighter types you like.

@Locutus: Thank you for the code above, for my tests it didnt worked in the context of this script.

So now you can choose between these versions, here's the buggy one that hides:
Warnung: Spoiler! [ Zum Anzeigen klicken ]

Bitte Anmelden um der Konversation beizutreten.

05 Nov 2015 21:48 #76394 von vlnikolic

Imperial, thank you very much for your time and energy about this.

It seems that this issue will have to wait more (probably forever) for clean solution.

: )

Bitte Anmelden um der Konversation beizutreten.

Ladezeit der Seite: 0.422 Sekunden