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

she/her

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

she/her

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.
[03:29 am]
DarkenedFantasies -- Probably just didn't care. For example, at some point before release, they've updated the graphics of some of the Protoss buildings (Forge, CyberCore, Citadel, Observatory, Arbiter Tribunal), but instead of properly re-rendering them with edited 3D models, they did crappy copy-paste jobs on the rendered graphics.
[2026-6-22. : 8:35 pm]
Ultraviolet -- :wob:
[2026-6-21. : 11:38 pm]
Symmetry -- :wob:
[2026-6-21. : 4:56 am]
Ultraviolet -- I suppose we'll likely never know, but my guess would be that they already saw it operating successfully and there was no monetary incentive to finish the original work. And the dev cycle in old school Blizzard was so hectic, it's possible it just got forgotten about after the original game got released. Plus there's an element of existing MPQ files that were packaged with the original discs becoming outdated if they updated it. And it's not like they remade the original MPQs, they just made new ones for BW specifically
[2026-6-21. : 4:26 am]
Oh_Man -- so that makes me think maybe the theory they are unfinished is not true and its a deliberate design decision, coz why not finish them wen ur making brood war?
[2026-6-21. : 4:25 am]
Oh_Man -- the thing is thos buildings are from classic. that means they went ahead and made brood war without ever finishing the 'unfinished' buildings
[2026-6-20. : 6:15 pm]
Ultraviolet -- Yeah he's talked about a lot of that stuff in his casts before. It seems plausible. Especially knowing how Blizzard of yesteryear operated.
[2026-6-20. : 3:47 pm]
NudeRaider -- to clarify: couldn't recall the behavior for every single Protoss building but I was aware the disparity exists.
[2026-6-20. : 3:43 pm]
NudeRaider -- Contained nothing new for me. Didn't know all building's behavior, but very much all unit's. Also Terran balance whine - also nothing new :lol:
[2026-6-19. : 9:57 am]
Oh_Man -- makes me wonder if SEN knows anything about the topic
Please log in to shout.


Members Online: Vrael, NudeRaider