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.
[10:05 am]
Moose -- ya
[05:23 am]
zsnakezz -- yes
[2024-5-12. : 8:51 pm]
l)ark_ssj9kevin -- Are you excited for Homeworld 3?
[2024-5-12. : 8:44 pm]
l)ark_ssj9kevin -- Hi Brusilov
[2024-5-12. : 4:35 pm]
O)FaRTy1billion[MM] -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
my server that was hosting it died
[2024-5-10. : 8:46 pm]
NudeRaider -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
https://armoha.github.io/eud-book/
[2024-5-10. : 8:36 am]
Brusilov -- Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
[2024-5-09. : 11:31 pm]
Vrael -- :wob:
[2024-5-09. : 8:42 pm]
Ultraviolet -- :wob:
[2024-5-08. : 10:09 pm]
Ultraviolet -- let's fucking go on a madmen rage bruh
Please log in to shout.


Members Online: Kusari