SA-MP Forums Archive
Array with float and integer ? - 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: Array with float and integer ? (/showthread.php?tid=554414)



Array with float and integer ? - DiamantEspace18 - 03.01.2015

Yo , I want to do a random car spawns like that :

Код:
new Float:RandomCarSpawn[][] = 
{
    {427,2239.6694,2441.9373,3.4053,88.4534,0,1},//I know it's the same car , it's for the exemple
    {427,2239.6694,2441.9373,3.4053,88.4534,0,1},
    {427,2239.6694,2441.9373,3.4053,88.4534,0,1}
};
But the modelid and the colors of the cars are not float , How can I do it ? Because I've more than 80 vehicles and I don't want to do this : for 80 cars !

Код:
	                if (result == 0)
			{
   				AddStaticVehicle(470,1678.5349,1790.9318,10.8172,268.2018,43,0); //
			}
			if (result == 1)
			{
   				AddStaticVehicle(485,1669.7319,1564.0251,10.4399,181.8410,1,75); //
			}
			if (result == 2)
			{
                                 AddStaticVehicle(583,1274.0514,1503.6760,10.3606,179.7288,1,1); //
			}
So thanks for the future help


Re: Array with float and integer ? - Lordzy - 03.01.2015

Create a structure using enum and classify it like this:
pawn Код:
enum RandomCarSpawnStruct
{
    e_RandCarModel,
    Float:e_RandCarPos[4],
    e_RandCarCol1, //Or create it as an array.
    e_RandColCol2,
}

new
    RandomCarSpawns[MAX_RANDOM_VEHICLES][RandomCarSpawnStruct] =
{
    {model, {positionX, positionY, positionZ, angle}, col1, col2},
    {model2, {...}, col1, col2}
};



AW: Array with float and integer ? - CutX - 03.01.2015

so basically, you want an array with float & integer values?
impossible.
But can be made possible if we "cheat" a little bit

pawn Код:
#include <a_samp>

new Float:RandomCarSpawn[][] =
{
    {Float:427,2239.6694,2441.9373,3.4053,88.4534,Float:0,Float:1},
    {Float:427,2239.6694,2441.9373,3.4053,88.4534,Float:0,Float:1},
    {Float:427,2239.6694,2441.9373,3.4053,88.4534,Float:0,Float:1},
    {Float:427,2239.6694,2441.9373,3.4053,88.4534,Float:0,Float:1},
    {Float:427,2239.6694,2441.9373,3.4053,88.4534,Float:0,Float:1},
    {Float:427,2239.6694,2441.9373,3.4053,88.4534,Float:0,Float:1}
    //and so on
};

public OnFilterScriptInit()
{

    for(new i=0,x; i<80; i++)//spawn 80 cars from the list (some be spawned multiple times ofc. its jsut an example)
    {
        x = random(sizeof RandomCarSpawn);
        AddStaticVehicle(_:RandomCarSpawn[x][0],
                         RandomCarSpawn[x][1],
                         RandomCarSpawn[x][2],
                         RandomCarSpawn[x][3],
                         RandomCarSpawn[x][4],
                         _:RandomCarSpawn[x][5],
                         _:RandomCarSpawn[x][6]);
    }
   
    return 1;
}



Re : Array with float and integer ? - DiamantEspace18 - 03.01.2015

Thanks you , I think I'll take the last from CutX it will be more faster to do


Re: Array with float and integer ? - dominik523 - 03.01.2015

@CutX
Why would you add Float tag to every item in the array since you added the tag to the array's name?

OP:
You could do it like this:
pawn Код:
AddStaticVehicle(floatround(RandomCarSpawn[0][0]), RandomCarSpawn[0][1]...



Re : Array with float and integer ? - DiamantEspace18 - 03.01.2015

Okay thx


AW: Re: Array with float and integer ? - CutX - 03.01.2015

Quote:
Originally Posted by dominik523
Посмотреть сообщение
@CutX
Why would you add Float tag to every item in the array since you added the tag to the array's name?
cuz tag mismatches pop up if we don't do that.
the array has the float tag meaning that there should be floating point numbers.
but 2 ain't a float, so we're kinda "type casting" it

if i were to remove the tag from the whole array, it'd look like:
pawn Код:
new RandomCarSpawn[][] = //now we have to add the tag 4 times every row
{//instead of just three and the same goes when using it
    {427,_:2239.6694,_:2441.9373,_:3.4053,_:88.4534,0,1},
    {427,_:2239.6694,_:2441.9373,_:3.4053,_:88.4534,0,1},
    {427,_:2239.6694,_:2441.9373,_:3.4053,_:88.4534,0,1},
    {427,_:2239.6694,_:2441.9373,_:3.4053,_:88.4534,0,1},
    {427,_:2239.6694,_:2441.9373,_:3.4053,_:88.4534,0,1}
    //and so on for 80 cars
};

public OnFilterScriptInit()
{

    for(new i=0,x; i<80; i++)
    {
        x = random(sizeof RandomCarSpawn);// 4 times _: instead of just 3 LAZYNESS :P
        AddStaticVehicle(RandomCarSpawn[x][0],
                         _:RandomCarSpawn[x][1],
                         _:RandomCarSpawn[x][2],
                         _:RandomCarSpawn[x][3],
                         _:RandomCarSpawn[x][4],
                         RandomCarSpawn[x][5],
                         RandomCarSpawn[x][6]);
    }
   
    return 1;
}



Re : Array with float and integer ? - DiamantEspace18 - 03.01.2015

It will be long to do but it works and it's faster than the random with if result = ... ect
Thanks to everybody


Re: Array with float and integer ? - Mauzen - 03.01.2015

Lordzy already said that enums are the common solution for that. Just putting/removing tags as you need them is pretty dirty style. After all both variants will be compiled to the same amx code, there is no difference in speed. But enums are a logical strcuture that makes your code easier to read and understand, and its easier to spot bugs.
Overriding the tags manually with _: basically does nothing but hiding the tag mismatch warnings.

Id suggest to start directly with enums, dont mess around with bad style.


Re : Array with float and integer ? - DiamantEspace18 - 03.01.2015

I said it's faster for me to just replace "," by ",_:" and after delete bad places