SA-MP Forums Archive
array help 3D/2D - 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 help 3D/2D (/showthread.php?tid=496914)



array help 3D/2D - Pillhead2007 - 24.02.2014

hi im trying to make an array for vehicles information ie. name petrol petrol id and it keeps giving me the name of the car for the second string please help?
PHP код:
new Text:VehicleInformation[MAX_PLAYERS], EngineSystemsType[][] = {
{
"Landstalker","Diesel",0}, {"Bravura","Petrol",1}, {"Buffalo",,"Petrol",1}};
public 
OnPlayerStateChange(playeridnewstateoldstate)
{
  if(
newstate == && oldstate == 1)
  {
    new 
string[128];
    
format(string,sizeof(string),"%s %s"EngineSystemsType[GetVehicleModel(GetPlayerVehicleID(playerid))-400],EngineSystemsType[GetVehicleModel(GetPlayerVehicleID(playerid))-400][1]);
    
TextDrawSetString(VehicleInformation[playerid],string);
    
TextDrawShowForPlayer(playerid,VehicleInformation[playerid]);
  }
  if(
newstate == && oldstate == 2)
  {
    
TextDrawHideForPlayer(playeridVehicleInformation[playerid]);
  }
  return 
1;




Re: array help 3D/2D - Misiur - 24.02.2014

You need 3d array because strings are arrays as well. However you don't want single-cell organisms (such as your last item in each array) to be defined as strings, so you need to create an enumerated array.

pawn Код:
enum E_VI {
    evName[32],
    evFuel[32],
    evSomething
}

new
    Text:VehicleInformation[MAX_PLAYERS],
    EngineSystemsType[][E_VI] = {
      {"Landstalker","Diesel",0},
      {"Bravura","Petrol",1},
      {"Buffalo","Petrol",1}
  }
;

#define GetPlayerVIndex(%0) (GetVehicleModel(GetPlayerVehicleID(%0)) - 400)

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2 && oldstate == 1)
    {
        new
            string[128],
            vindex = GetPlayerVIndex(playerid)
        ;

        format(string,sizeof(string),"%s %s", EngineSystemsType[vindex][evName], EngineSystemsType[vindex][evFuel]);
        TextDrawSetString(VehicleInformation[playerid],string);
        TextDrawShowForPlayer(playerid,VehicleInformation[playerid]);
    }
    if(newstate == 1 && oldstate == 2)
    {
        TextDrawHideForPlayer(playerid, VehicleInformation[playerid]);
    }
    return 1;
}



Re: array help 3D/2D - Pillhead2007 - 26.02.2014

thanks buddy