Streamer, loop through objects.
#1

I'm not using regular objects (well technically I am but bleh). How do I loop through every object in streamer? It's obviously not Max_Objects. I was thinking something along this line: "for(new obj; obj < Streamer_GetMaxItems(STREAMER_TYPE_OBJECT); obj++)". Is that correct?

Basically, how are we supposed to loop through dynamic objects?

EDIT: To use GetMaxItems, you have to SetMaxItems, that is not the solution I'm going for here. I want to only loop through the objects that exist. Like maybe a foreach iterator? If iterators are my only shot at getting this right, can someone show me how to use YSI's iterator functions?
Reply
#2

This should work to loop through Dynamic Objects.
pawn Код:
for(new i = 0; i < CountDynamicObjects(); i++)
Reply
#3

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
This should work to loop through Dynamic Objects.
pawn Код:
for(new i = 0; i < CountDynamicObjects(); i++)
But that wouldn't be every correct object ID. Say some of the objects in the middle were destroyed but before they were more objects were created. The objects that were destroyed would be counted in and the ones created last would not.
Reply
#4

pawn Код:
for(new i; i<MAX_OBJECTS; i++)
{
    if(IsValidDynamicObject(i))
    {
   
    }
}
Reply
#5

Quote:
Originally Posted by Schneider
Посмотреть сообщение
pawn Код:
for(new i; i<MAX_OBJECTS; i++)
{
    if(IsValidDynamicObject(i))
    {
   
    }
}
No, that will definitely not work... -.-

MAX_OBJECTS is not even close to the right answer.





PS: To use GetMaxItems, you have to SetMaxItems, that is not the solution I'm going for here. I want to only loop through the objects that exist. Like maybe a foreach iterator? If iterators are my only shot at getting this right, can someone show me how to use YSI's iterator functions?
Reply
#6

Create include and hook to a CreateDynamicObject function, keep track of maximum object id and objects count...
You can also hook to a DestroyDynamicObject function and if destroyed object is the last one (maximal id) then loop back and check for valid objects (first one valid object is new maximal id)

EDIT: just visited streamer topic to check natives. And these came to my mind

EDIT: Noticed insane mistake i made (rush), fixed it now
pawn Код:
new objectscount = CountDynamicObjects();
new i = 0;
while(objectscount > 0)
{
    if(IsValidDynamicObject(i))
   {
        //Do what you need here, but i++ goes in the end of the IF function

        objectscount--;
    }
    i++;
}
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
Create include and hook to a CreateDynamicObject function, keep track of maximum object id and objects count...
You can also hook to a DestroyDynamicObject function and if destroyed object is the last one (maximal id) then loop back and check for valid objects (first one valid object is new maximal id)

EDIT: just visited streamer topic to check natives. And these came to my mind


pawn Код:
new objectscount = CountDynamicObjects();
new i = 0;
while(objectscount > 0)
{
    if(IsValidDynamicObject(i))
   {
        //Do what you need here, but i++ goes in the end of the IF function

        i++;
    }
}
Quote:
Originally Posted by Crayder
Посмотреть сообщение
But that wouldn't be every correct object ID. Say some of the objects in the middle were destroyed but before they were more objects were created. The objects that were destroyed would be counted in and the ones created last would not.
This is why I said iterators would be the best way. But I have never used them and I keep getting errors when I try too... XD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)