20.06.2016, 17:21
PHP код:
#define MAX_LABELS 1000 // Change this to the limit of labels that can be created. Since you are using a streamer, there is no actual limit (I guess).
#define LABEL_FILE "labels.ini" // Label file name.
new Text3D:CreatedLabels[MAX_LABELS] = { Text3D:INVALID_3DTEXT_ID, ...};
public OnGameModeInit()
{
LoadSavedLabels(); // Loads every label from the labels file.
return 1;
}
CMD:tlabel(playerid, params[])
{
new
Str[110];
if(sscanf(params, "s[110]", Str)) return SendClientMessage(playerid, -1, "Usage: /tlabel <text>");
else
{
new idx;
for(idx = 0; idx < MAX_LABELS; ++idx)
{
if(CreatedLabels[idx] == Text3D:INVALID_3DTEXT_ID) break; // We find an empty ID.
}
if(idx == MAX_LABELS - 1) return SendClientMessage(playerid, -1, "Limit of labels reached."); // Limit reached.
new
Float:PosX,
Float:PosY,
Float:PosZ,
data[144]
;
GetPlayerPos(playerid, PosX, PosY, PosZ);
CreatedLabels[idx] = CreateDynamic3DTextLabel(Str, COLOR_RED, PosX, PosY, PosZ, 40.0);
new File:fLabels = fopen(LABEL_FILE, io_append);
if(fLabels)
{
format(data, sizeof(data), "%f|%f|%f|%s\r\n", PosX, PosY, PosZ, Str);
fwrite(fLabels, data);
fclose(fLabels);
format(Str, 110, ">> Label ID %d has been created successfully.", idx);
SendClientMessage(playerid, -1, Str);
}else return SendClientMessage(playerid, -1, "There has been an error while saving the label.");
}
return 1;
}
LoadSavedLabels() // Function that loads the data.
{
new File:fHandle = fopen(LABEL_FILE, io_read),
Data[144];
if(fHandle)
{
new idx, Str[128], Float:lX, Float:lY, Float:lZ;
while(fread(fHandle, Data))
{
sscanf(Data, "p<|>fffs[144]", lX, lY, lZ, Str); // Split the data using sscanf.
CreatedLabels[idx] = CreateDynamic3DTextLabel(Str, COLOR_RED, lX, lY, lZ, 40.0); // Creates the label.
++idx;
}
fclose(fHandle);
printf("Total of labels created: %d", idx); // Debug.
}
else
{
new File:uFile = fopen(LABEL_FILE, io_write); fclose(uFile);
print("The file \""LABEL_FILE"\" does not exists, or can't be opened. File has been created by the system.");
}
return 1;
}