Staredit Network > Forums > Modding Assistance > Topic: [SOLVED] Plugin Does Not Find Correct Unit
[SOLVED] Plugin Does Not Find Correct Unit
This topic is locked. You can no longer write replies here.
Aug 9 2012, 10:46 am
By: Sand Wraith  

Aug 9 2012, 10:46 am Sand Wraith Post #1



Using the following code, I am trying to find and get a pointer for the target unit of a spell. Unfortunately, I find the code to be highly unstable in game: either the incorrect unit will receive the HP bonus (or none at all) or it will outright crash with the puppet->mainOrderId = 0 operation (it used to be commented out, in which case it never crashed, but no unit would receive the HP bonus unless I specifically targetted a preplaced Reaver).

I'm pretty sure the problem lies somewhere in the addresses and variable types. The method I am trying to use is to find the address of unit->orderTarget (the caster's target) and match it with puppet's address. I assume that these addresses would be the same. However, I am not certain. That is the theoretical basis of my current solution.

I am fully aware that I can just flag the target unit with a specific timer number by salvaging another value. However, if I wanted to use that solution, I would not have asked for help to either fix my current method's code or look for an entirely different solution.

Code
UNIT* unit;
UNIT* puppet;
        for(int i = 0; i < 1700; i++)
        {
            unit = &unitTable[i];
            if(unit->unitId == 79
                && unit->orderSignal == 4
                && unit->orderTarget != NULL
                )
            {
                unit->orderSignal = 0;
                // find the target unit
                //UNIT* puppet;
                for(int i2 = 0; i2 < 1700; i2++)
                {
                    puppet = &unitTable[i2];
                    if(unit->orderTarget == puppet) // target unit found
                    {
                        tE[i2].others[1] = 1; // set its explode-on-death flag
                        puppet->healthPoints += 100 * 256;
                        puppet->mainOrderId = 0;
                    }
                }
                triggerCD(unit->playerId, 3, 10 * 24);
            }
        }


EDIT:

Ugh, I could have just compared puppet's coordinates and match it with orderTarget's coordinates. Problem with this is, what if two units have the same coordinates? Sure, I can check their owners and unit IDs, but what if these are the same too?

However, if any fix can be applied to the code above, it would still be nice to know what went wrong. (Or if there is another completely different approach, that would be welcome too.)

Any suggestions must be able to find the index of the target unit in the unitTable. This, specifically, is what I am looking for, so that I can take the index and apply it to my own struct array.

A fix for the above code is still the most preferred.

Post has been edited 1 time(s), last time on Aug 9 2012, 11:00 am by Sand Wraith.




Aug 9 2012, 11:49 pm Sand Wraith Post #2



Aha, never mind, I am a genius after all.

As it turns out, it was working perfectly fine. Just because of other complications, however, it appeared like the problem was here.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[2026-9-14. : 3:21 pm]
Oh_Man -- Racoon City Remastered*
[2026-9-14. : 3:21 pm]
Oh_Man -- Join the front line SEN, DEFEND MANKIND. 2030 is just a number! https://scmscx.com/map/2fHHj96p
[2026-9-14. : 3:21 pm]
Oh_Man -- from the maker of the legendary Architect RPG, the peerless Racoon City, the capitvating One Piercing Note, comes another creation minutes in the making
[2026-9-14. : 11:15 am]
Oh_Man -- heh heh thanks for the minerals suckers, now it's time to quit while i'm ahead
[2026-9-14. : 1:01 am]
Oh_Man -- Heroes of the Storm literally died and was revived before we got next SC game. Wb Loveless, u cooking any UMS for us?
[2026-9-13. : 11:35 pm]
LoveLess -- getting diablo 5 and wow 4 before starcraft ghost
[2026-9-13. : 9:22 pm]
RIVE -- To be fair, I used to post custom emotes back when I still used the forums.
[2026-9-13. : 12:54 pm]
l)ark_ssj9kevin -- RIVE
RIVE shouted: 💯
holy shit did you just use an emoji on SEN that feels illegal 🍆
[2026-9-13. : 10:24 am]
Moose -- Heinermann
Heinermann shouted: new era of SC and it's just some shooter they're gonna cancel before 2030
StarCraft 2: Ghost 2, The Reghostening
[2026-9-13. : 3:38 am]
Symmetry -- :wob:
Please log in to shout.


Members Online: DarkenedFantasies, Heinermann