SA-MP Forums Archive
Possible? - Streamer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Possible? - Streamer (/showthread.php?tid=574849)



Possible? - Streamer - Deathlane - 21.05.2015

Is it possible to loop through all streamer objects and get whether that object is in world x?

I'm trying to loop through all objects in one world and destroy it after a few minutes without having to add 'Objects[i]' on every streamer create object.

Thanks in advance!


Re: Possible? - Streamer - Vince - 21.05.2015

There is Streamer_CountItems and Streamer_GetIntData, although I have no idea if objects are numbered sequentially and if objectids are reused.


Re: Possible? - Streamer - Deathlane - 21.05.2015

This is what I found in the topic:

Code:
native Streamer_GetIntData(type, {Text3D,_}:id, data);
native Streamer_CountItems(type, serverwide = 1);
Any ideas on how I can implement it on a simple CreateDynamicObject?

Also, I found this:

Code:
native Streamer_DestroyAllItems(type, serverwide = 1);
Does this native function the way I wanted it to function?


Re: Possible? - Streamer - Whizion - 21.05.2015

So you would like to destroy all objects that are in virtual world X?

Code:
// Looping through all of the objects on the server.
for(new i = 0; i < Streamer_CountItems(STREAMER_TYPE_OBJECT, 1); i++)
{
    // Getting the virtual world of the object.
    new virtual_world = Streamer_GetIntData(STREAMER_TYPE_OBJECT, i, E_STREAMER_WORLD_ID);
    
    // For example let's say we want to destroy all the objects in virtual world 777.
    if(virtual_world == 777) { DestroyDynamicObject(i); }
}
I haven't tested this but i'm 90% sure that this should work.


Re: Possible? - Streamer - Deathlane - 21.05.2015

It gives me this error:

Code:
*** Streamer_GetIntData: Invalid data specified
using this:

Code:
for(new i = 0; i < Streamer_CountItems(STREAMER_TYPE_OBJECT, 1); i++)
{
    new World = Streamer_GetIntData(STREAMER_TYPE_OBJECT, i, E_STREAMER_WORLD_ID);
	    
    if(World == WORLD_CSDM) DestroyDynamicObject(i);
}
Any ideas? I have reviewed the code using the the topic for streamer but I can't see anything wrong.

EDIT: Also, the server freezes for 5 seconds when using that snippet


Re: Possible? - Streamer - Gammix - 21.05.2015

pawn Code:
for(new i = 0; i < CountDynamicObjects(); i++)
{
    new World = Streamer_GetIntData(STREAMER_TYPE_OBJECT, i, E_STREAMER_WORLD_ID);
       
    if(World == WORLD_CSDM) DestroyDynamicObject(i);
}
If the objects are sequentially numbered, than this could help you.


Re: Possible? - Streamer - ball - 21.05.2015

Quote:

Also, the server freezes for 5 seconds when using that snippet

If you have a lot of objects then looping them all may take some time. Codes above are valid, message about invalid data is probably caused by trying to get non-exist object's world, so before getting world check if object is valid.


Re: Possible? - Streamer - Deathlane - 21.05.2015

My code atm:

Code:
for(new i = 0; i < CountDynamicObjects(); i++)
{
    if(!IsValidDynamicObject(i)) continue;
    if(Streamer_GetIntData(STREAMER_TYPE_OBJECT, i, E_STREAMER_WORLD_ID) != WORLD_CSDM) continue;
	    
    DestroyDynamicObject(i);
}
I tried to optimize it a little bit. Still doesn't work, still lags.. Should I just give up this idea?


Re: Possible? - Streamer - ball - 21.05.2015

For me this code works

Code:
public OnGameModeInit()
{
	CreateDynamicObject(3534, 2105.08276, 1003.17114, 45.41970, 0.0, 0.0, 0.0, 0, 0, -1); //objectid: 1
	CreateDynamicObject(3534, 2110.11450, 1003.30292, 45.41975, 0.0, 0.0, 0.0, 0, 0, -1); //objectid: 2
	CreateDynamicObject(3534, 2109.27148, 1001.49146, 45.41970, 0.0, 0.0, 0.0, 1, 0, -1); //remove this || objectid: 3
	CreateDynamicObject(3534, 2106.31641, 1001.41577, 45.41970, 0.0, 0.0, 0.0, 0, 0, -1); //objectid: 4
	CreateDynamicObject(3534, 2109.27148, 1004.59882, 45.41970, 0.0, 0.0, 0.0, 1, 0, -1); //remove this || objectid: 5
	CreateDynamicObject(3534, 2106.31641, 1004.71191, 45.41970, 0.0, 0.0, 0.0, 0, 0, -1); //objectid: 6
	return SetTimer("deleteMe", 1000, 0);
}

forward deleteMe();
public deleteMe()
{
	for(new objectid = 1, j = Streamer_CountItems(STREAMER_TYPE_OBJECT, 1); objectid != j; objectid++)
	{
		if(!IsValidDynamicObject(objectid) || Streamer_GetIntData(STREAMER_TYPE_OBJECT, objectid, E_STREAMER_WORLD_ID) != 1)
		{
			continue;
		}
		printf("DestroyDynamicObject(%d)", objectid);
		DestroyDynamicObject(objectid);
	}
	return 1;
}