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.
[04:49 pm]
Ultraviolet -- SEN membership is like the supreme court, we're here for life baby
[04:13 am]
O)FaRTy1billion[MM] -- ya
[02:46 am]
slayer766 -- wtf farty you around still hahaah
[2024-11-09. : 4:24 pm]
Oh_Man -- da real donwano
da real donwano shouted: Who can crack into an old protected map & remove the trigger for insta-defeat for playing solo?
me
[2024-11-09. : 12:48 am]
RIVE -- j
[2024-11-08. : 10:41 pm]
lil-Inferno -- p
[2024-11-07. : 7:38 pm]
Zoan -- M
[2024-11-07. : 11:26 am]
Zycorax -- F
[2024-11-06. : 7:31 pm]
O)FaRTy1billion[MM] -- L
[2024-11-06. : 9:45 am]
TF- -- Blumph win :wob:
Please log in to shout.


Members Online: jjf28