18.06.2016, 07:36
Hi I am looking to find a command or system that creates 3dtext labels in game instead of me having to add them in the script can anyone help me as I can't seem to find one...
CMD:createtext(playerid,params[]) {
new text[64], Float:x, Float:y,Float:z, Float:distance, VW, LOS;
if(sscanf(params,"s[64]ffffii",text,x,y,z,distance,VW,LOS))
return SendClientMessage(playerid,COLOR_RED,"Usage: /createtext [text] x y z distance World LOS"
Create3DTextLabel(text, 0xFFFFFF, x,y,z,distance, VW, LOS);
return 1;
}
CMD:tlabel(playerid,params[]) { new text[64]; new Float:plocx,Float:plocy,Float:plocz; GetPlayerPos(playerid, plocx, plocy, plocz); if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command."); if(sscanf(params,"s[64]",text)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tlabel [text]"); CreateDynamic3DTextLabel(text, COLOR_RED, plocy, plocx, plocz, 40); SendClientMessage(playerid, COLOR_WHITE, "You've created a new text label"); return 1; }
#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;
}