Iterate units

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

User avatar
misiek1294
Junior Member
Paladin
Posts: 168
Joined: Mon Dec 29, 2014 3:58 pm
Poland

Iterate units

Post by misiek1294 » Tue Oct 25, 2016 6:50 pm

Hey guys, i need to find all unit's on level not room and i can't find way to get this.
Atm i use this loop but it's work for player current room.

Code: Select all

for (Room1* pRoom = pUnit->pPath->pRoom1; pRoom; pRoom = pRoom->pRoomNext)
{
for (UnitAny* pMonster = pRoom->pUnitFirst; pMonster; pMonster = pMonster->pListNext)
{
some code here
}
}
Thanks

User avatar
kidpaddle94
Forum Legend
Principality
Posts: 2057
Joined: Thu Aug 13, 2009 2:54 pm
Location: localhost
Canada

Re: Iterate units

Post by kidpaddle94 » Fri Oct 28, 2016 12:49 am

Why are you using `pMonster = pMonster->pListNext` in your for loop? You should be using pRoomNext (pUnit + 0xE8)
Also are you calling this from the client? Because the client only see units on a radius of something like 2 1/2 screens

User avatar
misiek1294
Junior Member
Paladin
Posts: 168
Joined: Mon Dec 29, 2014 3:58 pm
Poland

Re: Iterate units

Post by misiek1294 » Fri Oct 28, 2016 10:45 am

I using this on server-side code.Yeah you have right here will be pRoomNext my fail with this but still works for some radius not all in room.

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Iterate units

Post by devurandom » Thu Jul 13, 2017 4:42 am

Can be tricky.. if your hook is placed before the room is fully populated.
That was my mistake..... :-|
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

Return to “Code Editing”