Array List assign to Variable
#1

Hi guys, i need some help here (the title may not make sense so please excuse me lol).

Anyways, in lay man's terms I have created an array:

pawn Код:
new DisabledCars[] = {407, 416, 425, 427, 432, 441, 447, 449, 464, 465, 476, 479, 501, 520, 537, 538, 552, 564, 569, 570, 577, 590, 591, 592, 594, 601, 606, 608, 610};
And I have made this function which is called under OnGameModeInit:
pawn Код:
LoadDefaultDisabledVehicles()
{
    for(new i = 400; i < MAX_SPAWNABLE_VEHICLES+400; i++)
    {
        CarInfo[i-400][allow] = true;
    }
    for (new x = 0; x < sizeof(DisabledCars); x++) // This bit is where I am stuck - It is obviously wrong and I tested it.
    {
        CarInfo[x][allow] = false;
    }
    printf("Disabled Vehicles Loaded!");
}
What is "supposed" to happen is basically, the variable
pawn Код:
CarInfo[DisabledCarID_GOES_HERE][allow] = true;
should be set (which is fine). But then, I need some of the arrays to be set to this:
pawn Код:
CarInfo[DisabledCarID_GOES_HERE][allow] = false;
Where I say: "DisabledCarID_GOES_HERE" I am talking about the values given in the DisabledCars[] array list. But I cannot do so. So the end result should be like this:
pawn Код:
CarInfo[407][allow] = false;
CarInfo[416][allow] = false;
CarInfo[425][allow] = false;
CarInfo[427][allow] = false;
CarInfo[432][allow] = false;
/// etc etc (from my DisabledCars[] list).

Please can someone help me, as I am stressing out trying to figure out how to do this. I hope u get what I mean, if not, i'll explain further - it's pretty simple what I am trying to achieve.

Thanks.
Reply
#2

pawn Код:
DisabledCars[x]
So:

pawn Код:
CarInfo[DisabledCars[x]][allow] = false;

But there are other (better) ways of doing it, without the need of a loop.
Reply
#3

Quote:
Originally Posted by 0rb
pawn Код:
DisabledCars[x]
So:

pawn Код:
CarInfo[DisabledCars[x]][allow] = false;

But there are other (better) ways of doing it, without the need of a loop.
So do I think, I'd rather use switch.
Reply
#4

Quote:
Originally Posted by 0rb
pawn Код:
DisabledCars[x]
So:

pawn Код:
CarInfo[DisabledCars[x]][allow] = false;

But there are other (better) ways of doing it, without the need of a loop.
So what u are saying is this?

pawn Код:
LoadDefaultDisabledVehicles()
{
    for(new i = 400; i < MAX_SPAWNABLE_VEHICLES+400; i++)
    {
        CarInfo[i-400][allow] = true;
    }
    for(new i = 400; i < MAX_SPAWNABLE_VEHICLES+400; i++)
    {
        CarInfo[DisabledCars[i-400]][allow] = false;
    }
    printf("Disabled Vehicles Loaded!");
}
And I'd rather use the simpler/faster/efficient way of doing it, What do you have in mind guys? How would i use a switch statement MenaceX?

EDIT: Just tested it, and the server/player crashes - the class selection is messed up and no response from the server.
Reply
#5

Quote:
Originally Posted by [B2K
Hustler ]
EDIT: Just tested it, and the server/player crashes - the class selection is messed up and no response from the server.
Bump, i'm still trying to figure this out. Other better solutions are welcome. Please help. Thanks.
Reply
#6

pawn Код:
for(new x = 0; x < MAX_VEHICLES; x++)
{
    switch(x)
    {
        case 407: // Set the vehicle disabled
        case 416: // Set the vehicle disabled
        case 425: // Set the vehicle disabled
    }
}
Would take some time though.

P.S.: Untested and written in a hurry, might give errors/not work.
Reply
#7

Where you spawn the vehicle or whatever just do this:

pawn Код:
stock IsDisabledVehicleModel( model )
{
  switch ( model )
  {
    case 407, 416, 425, 427, 432, 441, 447, 449, 464, 465, 476, 479, 501, 520, 537, 538, 552, 564, 569, 570, 577, 590, 591, 592, 594, 601, 606, 608, 610 : return true;
  }
  return false;
}
So you use it like:

pawn Код:
//some command
if ( !IsDisabledVehicleModel( strval( params ) ) ) CreateVehicle( strval( params ), ................ );
This is ofcourse if I understand what you are trying to do, you are trying to disable certain vehicle models being spawned ingame yes ?
Reply
#8

Thank you SpiderPork and Donny for your reply, but the problem is (which i forgot to mention ), was that I want to un-disable re-disable vehicles in-game. So right now disabled vehicles have this variable:
Код:
CarInfo[idx-400][allow] = false;
I want to be able to change this for example to:
Код:
CarInfo[idx-400][allow] = true;
It isn't possible to lock/unlock vehicles through the function you gave Donny afaik, unless you can tell me otherwise. Thanks for ur help, still waiting for a sulution.
Reply
#9

Right I'm with you now.

Well this is simple enough just do something like so:

pawn Код:
//global
new
  gDisabledVehicle[ 211 ] = { true, ... }; //all are enabled and 211 is the total model count - 400 to 611

//create a vehicle
if ( ( model - 400 ) > -1 && ( model - 400 ) < 212 )
{
  if ( !gDisabledVehicle[ ( model - 400 ) ] ) CreateVehicle( model, coords etc........ );
}

//enable a vehicle
gDisabledVehicle[ ( model - 400 ) ] = true;

//disable a vehicle
gDisabledVehicle[ ( model - 400 ) ] = false;
So if 'model' is 541 (Bullet model) then it will check the array at index 141 to see if it is flagged true or false then react accordingly, model is the param from your command or whatever.

You could use the creation as a custom function with a return:

pawn Код:
CreateEnabledVehicle( model, ...... )
{
  if ( ( model - 400 ) > -1 && ( model - 400 ) < 212 ) //OOB protection so we don't go outside the array bounds and crash the script
  {
    if ( !gDisabledVehicle[ ( model - 400 ) ] )
    {
      CreateVehicle( model, coords etc........ ); //it wasn't disabled so create it
      return true; //return a success
    }
  }
  return false; //return a failure, the vehicle was disabled or the index was invalid after subtracting 400 from it (we passed say 717 so the index was 317)
}
I haven't checked this dude, just writing it out from my head so it could have typos or little bugs which I'm not aware of but in theory it will work no problems I think (hope hehe) and now we don't require loops or whatever unless we want to do a global set for the 'gDisabledVehicle' array.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)