Staredit Network > Forums > Modding Assistance > Topic: Cloak unit when switching into siege mode
Cloak unit when switching into siege mode
Aug 22 2020, 7:43 am
By: Netbek  

Aug 22 2020, 7:43 am Netbek Post #1



I want to create a 'sneak mode' ability, which makes a unit cloaked but slower & unable to attack.
I figured I'd base it on siege mode instead of cloak, because I want a transition animation, and I also want to be able to give the sneaking unit a different walk animation.
I modified 'siege_transform.cpp' from the general-plugin-template-project to set/unset UnitStatus::Cloaked, UnitStatus::RequiresDetection, and UnitStatus::CloakingForFree after the unit is replaced via replaceUnitWithType().

It works, BUT only after switching back and forth one time. So the first transform does NOT cloak the unit as intended, but all following do. Another problem is that the unit becomes invisible instantly upon hitting its 'siege mode' form, but I would prefer if it became cloaked at the end of the transform anim.

Attachment: Modified 'siege_transform.cpp'

Attachments:
siege_transform.cpp
Hits: 3 Size: 7.65kb




Aug 22 2020, 11:49 am UndeadStar Post #2



Based on recent research and Arbiter cloaking code, I think you need to set the CloakingForFree status on the unit (based on observing the Arbiter effect), and give OrderId::Cloak as secondaryOrderId to the unit (because the Arbiter force surrounding units to execute the content of that order), so that the unit cloak by itself.
Logically it should work like that, unless there's something that can turn the cloaking off somewhere.

edit: whoops, thinking back on that, decloaking may not be that simple if using that method...though it may seems to work at first.

edit2: somehow, to decloak, just setting secondaryOrderId to OrderId::Decloak should work, I guess most cloaking effects are actually cleared on every frame, which is why they are renewed either by the "cloak nearby" order of the arbiter, or the secondary order of the unit cloaking by itself.

edit3: I was rereading your code, what start the invisibility is in TankMode, and what remove it is in SiegeMode, you may have it backward?

Post has been edited 3 time(s), last time on Aug 22 2020, 12:05 pm by UndeadStar.




Aug 23 2020, 9:47 pm Netbek Post #3



Thank you, it has worked! :thumbup:
I ended up changing "game_hooks.cpp" instead of "siege_transform.cpp".
Here is the code I put in "game_hooks.cpp":
Code
//Loop through all visible units in the game.
for (CUnit *unit = *firstVisibleUnit; unit; unit = unit->link.next) {
    if(unit->id == UnitId::siege_tank_s) {
        if(unit->sprite->mainGraphic->animation == IscriptAnimation::SpecialState2) {
                unit->setSecondaryOrder(OrderId::Decloak);
        }
        if(unit->sprite->mainGraphic->animation == IscriptAnimation::Init) {
            if(unit->sprite->mainGraphic->frameIndex == 5) {
                unit->status |= UnitStatus::CloakingForFree;
                unit->setSecondaryOrder(OrderId::Cloak);
            }
        }
    }
}

Here's a video showing the result. The video shows the code in the beginning. The description also contains a detailed step-by-step for future searchers:
https://www.bitchute.com/video/TbEiYzbT3wVc/
It works exactly the way I want, even with the delay before cloak when entering siege mode. The Code is based on stuff Voyager taught me here (and on what you just told me ofc).

Post has been edited 1 time(s), last time on Aug 24 2020, 12:28 pm by Netbek.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
[2024-4-17. : 3:26 am]
O)FaRTy1billion[MM] -- i have to ask for minerals first tho cuz i don't have enough to send
[2024-4-17. : 1:53 am]
Vrael -- bet u'll ask for my minerals first and then just send me some lousy vespene gas instead
[2024-4-17. : 1:52 am]
Vrael -- hah do you think I was born yesterday?
[2024-4-17. : 1:08 am]
O)FaRTy1billion[MM] -- i'll trade you mineral counts
[2024-4-16. : 5:05 pm]
Vrael -- Its simple, just send all minerals to Vrael until you have 0 minerals then your account is gone
[2024-4-16. : 4:31 pm]
Zoan -- where's the option to delete my account
[2024-4-16. : 4:30 pm]
Zoan -- goodbye forever
Please log in to shout.


Members Online: Roy, Judcfrffvf