Thread: [Solved] loop entitys
View Single Post
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 11-16-2022 , 20:33   Re: loop entitys
Reply With Quote #10

Quote:
Originally Posted by MrPickles View Post
it is more simple to set 100, thats all, more operations are saved
in a loop the simpler is better, think that each time you will be checking and obtaining the length of the array (-1), instead with 100, it only checks if it is the cell contain 100
1. I disagree with this
What if the number of loop is smaller, for example, only 10 is required.
But it have to run 100 times every single time because you hardcode it to 100
Isn't that worse?
Not to mention, you are using a giantic array2D with the size of 3100+ (100 entity x 31 clients) so that would cost much more performen than that small check in for-loop is

2. The anwser code feel really weird to me.
Tell me if I am wrong:
With this as example
PHP Code:
removeTransEntsClient, {0,1,2,100} ); 
You are trying to remove any entity at the index contain inside __int_Entitys[]
=> you want to get this
  • __int_TransEnts[Client][0]
  • __int_TransEnts[Client][1]
  • __int_TransEnts[Client][2]
  • __int_TransEnts[Client][100]

If that the case, what you want to loop is __int_Entitys[]'s size NOT the value insde it.

The code can change it into this
PHP Code:
removeTransEnts(Client__int_Entitys[], max sizeof __int_Entitys)  
{
        for( new 
0maxi++)
        { 
              if(
is_valid_ent(__int_TransEnts[Client][__int_Entitys[i]]))
              {
                    
remove_entity__int_TransEnts[Client][__int_Entitys[i]] );
                    
__int_TransEnts[Client][__int_Entitys[i]] = 0;
                    
client_printClientprint_chat"Entity Removed = [Client][%d]"__int_Entitys[i] );

              }
              
client_printClientprint_chat"Entity Checked = [Client][%d]"__int_Entitys[i] );             
        }

__________________
My plugin:

Last edited by Celena Luna; 11-16-2022 at 20:52.
Celena Luna is offline