SA-MP Forums Archive
Empty array - 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: Empty array (/showthread.php?tid=663399)



Empty array - Cyber123 - 30.01.2019

How to check if the integer array is empty without additional variable?


Re: Empty array - Kaliber - 30.01.2019

Well, what values should it handle?

If it can handle every value, then you need a second variable.


Re: Empty array - Cyber123 - 30.01.2019

I want to handle every value in array, thanks


Re: Empty array - Pottus - 30.01.2019

Quote:
Originally Posted by Cyber123
Посмотреть сообщение
How to check if the integer array is empty without additional variable?
An array can never be empty even if all the values are zero as zero is still a value! Your question makes no sense really. Maybe you want to check if integer array is null? All values 0? How the heck is anyone supposed to know?


Re: Empty array - Mobtiesgangsa - 30.01.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
And why do you not want to use additional variables? They aren't expensive.
HAHAAHAHAHAHAHA nice joke


Re: Empty array - Cyber123 - 30.01.2019

Quote:
Originally Posted by Pottus
Посмотреть сообщение
An array can never be empty even if all the values are zero as zero is still a value! Your question makes no sense really. Maybe you want to check if integer array is null? All values 0? How the heck is anyone supposed to know?
Yes, I want to check if all values of integer array are 0...

Quote:
Originally Posted by ******
Посмотреть сообщение
And why do you not want to use additional variables? They aren't expensive.
Because i tried with additional variable and can't get what I want.


Re: Empty array - Cyber123 - 30.01.2019

PHP код:
#include <a_samp>
#include <streamer>
#include <sscanf2>
#include <ColAndreas>
#include <zcmd>
#include <YSI_Core\y_utils>
#include <YSI_Coding\y_timers>
new Timer:timer1;
new 
Grass[5];
new 
br=0;
new 
scfmString[250];
#define SCM SendClientMessage
#define SCFM(%1,%2,%3) format(scfmString,sizeof(scfmString),%3), SCM(%1,%2,scfmString)
public OnFilterScriptInit()
{
    
CA_Init();
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
CMD:as(playeridparams[], help
{
    for(new 
i=0i<5i++)
    {
        new 
Float:randx RandomFloat(109.2241-92.6121)+92.6121;   
        new 
Float:randy RandomFloat(-71.6366-(-57.7923))+57.7923;
        new 
Float:z;
        
CA_FindZ_For2DCoord(randxrandyz);
        
Grass[i] = CreatePlayerObject(playerid802randxrandyz+0.2000);
    }
    
timer1 repeat Tajmer(playerid);
    return 
1;
}
CMD:aa(playeridparams[], help
{
    
stop timer1;
    return 
1;
}
timer Tajmer[100](playerid)
{
    new 
Float:x,Float:y,Float:z;
    for(new 
i=0i<sizeof(Grass); i++)
    {
        
GetPlayerObjectPos(playeridGrass[i], xyz);
        if(
IsPlayerInRangeOfPoint(playerid1xyz))
        {
            
DestroyPlayerObject(playeridGrass[i]);
            
Grass[i] = 0;
            
br++;
        }
    }
    if(
br >= sizeof(Grass))
    {
        
SendClientMessage(playerid, -1,"No grass");
    }
    return 
1;

I have problem with this part:
PHP код:
        if(IsPlayerInRangeOfPoint(playerid1xyz))
        {
            
DestroyPlayerObject(playeridGrass[i]);
            
Grass[i] = 0;
            
br++;
        } 
Sometimes do this if object is already destroyed


Re: Empty array - Jefff - 31.01.2019

pawn Код:
if(Grass[i] != 0 && IsPlayerInRangeOfPoint(...))
or

pawn Код:
if(GetPlayerObjectPos(playerid, Grass[i], x, y, z) && IsPlayerInRangeOfPoint(...))
propably first code is better and if you want something for player it should be

Grass[playerid][i]

because if few players use /as there will be fun


Re: Empty array - Cyber123 - 31.01.2019

Thank you Jeff, I fixed it.

Quote:
Originally Posted by ******
Посмотреть сообщение
For this to be true:

br >= sizeof(Grass)

They would have to be right next to every piece of grass at the same time. Is that the case?
It gives me exactly what I want. It checks if all objects are destroyed.


Re: Empty array - Cyber123 - 31.01.2019

No they are not.