SA-MP Forums Archive
[Include] iCOO - CountOriginalObjects - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] iCOO - CountOriginalObjects (/showthread.php?tid=400197)



iCOO - CountOriginalObjects - iWhite - 17.12.2012

iCOO

iCOO - only one function, to count your CreateObject objects.

Function:
CountOriginalObjects();
Returns how many original objects are created.

Include it under #include <a_samp> line

Pastebin: http://pastebin.com/ge17bNFG


Re: iCOO - CountOriginalObjects - FUNExtreme - 17.12.2012

You don't take into account that objects can be destroyed at any time.

Just make a function that loops through all id's from 1 to 1000. Check with 'IsValidObject(objectid)' and up the variable by one each time the statement is true.

Important note: this method will give an incorrect value when using a streamer.

EDIT: Fixed mistake pointed out by ******.


Re: iCOO - CountOriginalObjects - FUNExtreme - 17.12.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
That method will almost always give an incorrect value! If you create 5, destroy the first 2, then create a new one there's nothing stopping the system reusing the first ID meaning that looping to it will only return "1".
In that case you have to check from id 1 to 1000.


Re: iCOO - CountOriginalObjects - iWhite - 17.12.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
What about when you've already hooked CreateObject? Or DestryObject? Or objects that don't get created for some reason? Or filterscripts? Or streamer objects?
Yep, you're right. I've never thought about that, because i haven't hooked CreateObject


Re: iCOO - CountOriginalObjects - Kreatyve - 17.12.2012

stock CountCreatedObjects() {
- new Objects = 0;
-
- for(new objectid = 0; objectid < MAX_OBJECTS; objectid++) {
- - if(IsValidObject(objectid)) Objects++;
- }
-
- return Objects;
}
Note: Every - is an indent.

Something like that... I guess.


Re: iCOO - CountOriginalObjects - Lorenc_ - 17.12.2012

In my honest opinion, hooking > looping. This should of been posted in the useful functions thread anyway


Re: iCOO - CountOriginalObjects - hustrine - 10.01.2013

Nice job iWhiti.