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.
[2024-4-14. : 9:21 pm]
O)FaRTy1billion[MM] -- there are some real members mixed in those latter pages, but the *vast* majority are spam accounts
[2024-4-14. : 9:21 pm]
O)FaRTy1billion[MM] -- there are almost 3k pages
[2024-4-14. : 9:21 pm]
O)FaRTy1billion[MM] -- the real members stop around page 250
[2024-4-14. : 9:20 pm]
O)FaRTy1billion[MM] -- look at the members list
[2024-4-12. : 12:52 pm]
Oh_Man -- da real donwano
da real donwano shouted: This is the first time I've seen spam bots like this on SEN. But then again, for the last 15 years I haven't been very active.
it's pretty common
[2024-4-11. : 9:53 pm]
da real donwano -- This is the first time I've seen spam bots like this on SEN. But then again, for the last 15 years I haven't been very active.
[2024-4-11. : 4:18 pm]
IlyaSnopchenko -- still better than "Pakistani hookers in Sharjah" that I've seen advertised in another forum
[2024-4-11. : 4:07 pm]
Ultraviolet -- These guys are hella persistent
[2024-4-11. : 3:29 pm]
Vrael -- You know, the outdoors is overrated. Got any indoor gym and fitness equipment?
[2024-4-10. : 8:11 am]
Sylph-Of-Space -- Hello!
Please log in to shout.


Members Online: Roy, jun3hong