Must be a constant expression; assumed zero
#1

What's the matter ?

Код:
new APlanes[] =
{
	{"Andromada", 592},		{"AT400", 577}, 	     {"Beagle", 511},				{"Cargobob", 548},          // ID 0, 1, 2, 3
	{"Cropduster", 512},	        {"Dodo", 593},	      {"Hunter", 425},				{"Hydra", 520},             // ID 4, 5, 6, 7
	{"Leviathan", 417},		{"Maverick", 487},     {"Nevada", 553},				{"Police Maverick", 497},   // ID 8, 9, 10, 11
	{"Raindance", 563},		{"Rustler", 476},	       {"SAN News Maverick", 488},		{"Seasparrow", 447},        // ID 12, 13, 14, 15
	{"Shamal", 519},		        {"Skimmer", 460},	{"Sparrow", 469},			{"Stuntplane", 513}         // ID 16, 17, 18, 19
};
This is the error:

Код:
(201) : error 008: must be a constant expression; assumed zero
I am trying to make a command that spawns the given planes on the list, here is the rest of the command:

Код:
#define DIALOG_PLANE 1
//==============================================================================
CMD:vplane(playerid, params[])
{
    // Check if the player's admin-level is at least 1
    if(PlayerInfo[playerid][pVIP] >= 2)
    {
         // Make sure the player isn't inside a vehicle
         if (GetPlayerVehicleID(playerid) == 0)
         {
             // Ask which motorcycle the player wants to have
             ShowPlayerDialog(playerid, DIALOG_PLANE, DIALOG_STYLE_LIST, "Choose a plane:", APlanes, "Spawn", "Cancel");
             // Let the server know that this was a valid command
             return 1;
         }
	}
	else
	    return 0;

	// Let the server know that this was a valid command
	return 1;
}
Reply
#2

Please help ?
Reply
#3

Well your array got two dimensions so you need to define it like that
pawn Код:
new APlanes[][] =
{ // start 1. dim
    // 0 - APlanes[0][x]
    { // start 2. dim
        // 0 - APlanes[0][0]
        "Andromada",
        // 10 - APlanes[0][10] - because "Andromada" is 10 cells long
        592
    }, // end 2. dim
    // 1 - APlanes[1][x]
    { // start 2. dim
        // 0 - APlanes[1][0]
        "AT400",
        // 6 - APlanes[1][6]
        577
    }, // end 2. dim
}; // end 1 dim
But now you should get an error if you try to use it in ShowPlayerDialog

You need to format a string with your array or you use another global array with only one dimension
Reply
#4

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Well your array got two dimensions so you need to define it like that
pawn Код:
new APlanes[][] =
{ // start 1. dim
    // 0 - APlanes[0][x]
    { // start 2. dim
        // 0 - APlanes[0][0]
        "Andromada",
        // 10 - APlanes[0][10] - because "Andromada" is 10 cells long
        592
    }, // end 2. dim
    // 1 - APlanes[1][x]
    { // start 2. dim
        // 0 - APlanes[1][0]
        "AT400",
        // 6 - APlanes[1][6]
        577
    }, // end 2. dim
}; // end 1 dim
But now you should get an error if you try to use it in ShowPlayerDialog

You need to format a string with your array or you use another global array with only one dimension
Sorry my scripting skils are not that good, I din't understand a word of what I have to do :/
Reply
#5

PHP код:
#define DIALOG_PLANE 1
enum APlaneInfo
{
    
PlaneName[20],
    
PlaneID
}
new 
APlanes[20][APlaneInfo] =
{
    {
"Andromada"592},        {"AT400"577},          {"Beagle"511},                {"Cargobob"548},          // ID 0, 1, 2, 3
    
{"Cropduster"512},            {"Dodo"593},          {"Hunter"425},                {"Hydra"520},             // ID 4, 5, 6, 7
    
{"Leviathan"417},        {"Maverick"487},     {"Nevada"553},                {"Police Maverick"497},   // ID 8, 9, 10, 11
    
{"Raindance"563},        {"Rustler"476},           {"SAN News Maverick"488},        {"Seasparrow"447},        // ID 12, 13, 14, 15
    
{"Shamal"519},                {"Skimmer"460},    {"Sparrow"469},            {"Stuntplane"513}         // ID 16, 17, 18, 19
};
//==============================================================================
CMD:vplane(playeridparams[])
{
    
// Check if the player's admin-level is at least 1
    
if(PlayerInfo[playerid][pVIP] >= 2)
    {
         
// Make sure the player isn't inside a vehicle
         
if (GetPlayerVehicleID(playerid) == 0)
         {
             
// Ask which PLANE the player wants to have
             
new PMSG[1000];
             for(new 
i=0i<20i++)
             {
                
format(PMSGsizeof(PMSG), "%s%s - %i\n",PMSG,APlanes[i][PlaneName], APlanes[i][PlaneID]);
             }
             
ShowPlayerDialog(playeridDIALOG_PLANEDIALOG_STYLE_LIST"Choose a plane:"PMSG"Spawn""Cancel");
             
// Let the server know that this was a valid command
             
return 1;
         }
    }
    else
        return 
0;
    
// Let the server know that this was a valid command
    
return 1;

Usage:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_PLANE)
    {
        if(!
response// Pressed ESC or clicked cancel
        
{
            
//SendClientMessage(playerid, COLOR_GREEN, "Closed Dialog Message");
        
}
        else 
        {
            
//Pressed Spawn
            
new PMSG[128];
            
format(PMSGsizeof(PMSG), "You have spawned %s"APlanes[listitem][PlaneName]);
            
SendClientMessage(playerid, -/*W/e Color*/PMSG);
            new 
Float:PlayerPos[4];
            
GetPlayerPos(playeridPlayerPos[0], PlayerPos[1], PlayerPos[2]);
            
GetPlayerFacingAngle(playeridPlayerPos[3]);
            new 
VID CreateVehicle(APlanes[listitem][PlaneID], PlayerPos[0], PlayerPos[1], PlayerPos[2], PlayerPos[3], random(254), random(254), 0);
            
PutPlayerInVehicle(playeridVID0);
        }
        return 
1// We handled a dialog, so return 1. Just like OnPlayerCommandText.
    
}
    return 
0// You MUST return 0 here! Just like OnPlayerCommandText.

Edit: Do ask me if you have any doubt regarding how I used something and why.. Ask - Learn - Improve.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)