Quote:
Originally Posted by OKStyle
For ex:
map1.inc
map2.inc
map3.inc
Array:
pawn Код:
static maps[][] = {"map1.inc", "map2.inc", "map3.inc"};
CMD:
pawn Код:
cmd:map(playerid, params[]) { if(sscanf(params, "d", params[0])) return SendClientMessage(playerid, -1, "/map [mapid]"); for(new i; i < MAX_OBJECTS; i++) DestroyObject(i); new string[14]; format(string, sizeof(string), "../%s", maps[params[0]]); #include string return 1; }
Or without array:
pawn Код:
cmd:map(playerid, params[]) { if(sscanf(params, "d", params[0])) return SendClientMessage(playerid, -1, "/map [mapid]"); for(new i; i < MAX_OBJECTS; i++) DestroyObject(i); new string[14]; format(string, sizeof(string), "../map%d.inc", params[0]); #include string return 1; }
|
You do know that string is a variable, and including happens at compile time?
What you attempt here is to include the file "string", not the content of the array since that isn't known at compile time, and even if it was known it wouldn't work because you try to include additional code after the compiling is done (at runtime).
The filename for the #include directive must be a constant.
If you tried to compile it, yes it does compile, but only because "string" is a valid include name from the SAMP Server package (string.inc). No errors because it's already included.
Good idea but don't post code when drunk!
You could however make a function which switches through or checks for a given value and executes the code from the includes:
PHP код:
LoadMap(id)
{
switch(id)
{
case 0:
{
#include "map1.inc"
}
case 1:
{
#include "map2.inc"
}
}
}
But I'm pretty sure OP is talking about map (.map or whatever) files in the scriptfiles folder. That's better anyway, since hardcoded maps need a GMX for any changes you want to make. With files (or a database) you can also change the map names, add/remove names etc without touching the script.