pawn Код:
#include "a_samp"
#include "sscanf"
#include "zcmd"
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
#define MAX_LABELS 10
enum _labels
{
Text3D: label_ID,
label_time,
label_text[128],
Float: label_pos[3]
}
new
gLabels[MAX_LABELS][_labels];
public OnGameModeInit()
{
for(new i = 0; i < MAX_LABELS; i++)
{
gLabels[i][label_ID] = Text3D: INVALID_3DTEXT_ID;
}
SetTimer("DeleteTimers", 1000, true);
AddPlayerClass(4, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
return 1;
}
CMD:3d(playerid, params[])
{
new ltext[128], time;
if(sscanf(params, "ds[128]", time, ltext))
return SendClientMessage(playerid, -1, "Usage: /3d < time to auto-delete(in seconds.. put -1 in seconds to never delete) > < label text >");
new Float: pos[3];
new world = GetPlayerVirtualWorld(playerid);
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
new id = GetEmptyLabelID();
gLabels[id][label_ID] = Create3DTextLabel(ltext, -1, pos[0], pos[1], pos[2], 20.0, world, 1);
strcpy(gLabels[id][label_text], ltext, 128);
gLabels[id][label_pos][0] = pos[0];
gLabels[id][label_pos][1] = pos[1];
gLabels[id][label_pos][2] = pos[2];
gLabels[id][label_time] = gettime() + time;
new str[128];
format(str, sizeof(str), "Successfully created label id: %d with text: %s. It auto-deletes in: %d sec", id, ltext, time);
SendClientMessage(playerid, -1, str);
return 1;
}
CMD:delete3d(playerid, params[])
{
for(new i = 0; i < MAX_LABELS; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5, gLabels[i][label_pos][0], gLabels[i][label_pos][1], gLabels[i][label_pos][2]))
{
new str[128];
format(str, sizeof(str), "You've successfully deleted label id: %d. Text: %s", i, gLabels[i][label_text]);
SendClientMessage(playerid, -1, str);
ClearLabel(i);
return 1;
}
}
SendClientMessage(playerid, -1, "No labels are in range to delete!");
return 1;
}
stock GetEmptyLabelID()
{
new id;
for(new i = 0; i < MAX_LABELS; i++)
{
if(gLabels[i][label_ID] == Text3D: INVALID_3DTEXT_ID)
{
id = i;
break;
}
}
if(id == INVALID_3DTEXT_ID)
id = 0;
return id;
}
forward DeleteTimers();
public DeleteTimers()
{
print("Tick");
for(new i = 0; i < MAX_LABELS; i++)
{
if(gLabels[i][label_ID] != Text3D: INVALID_3DTEXT_ID && gLabels[i][label_time] != -1)
{
if((gLabels[i][label_time] - gettime()) == 0)
{
new str[128];
format(str, sizeof(str), "Label id: %d has been auto-deleted! (Text: %s)", i, gLabels[i][label_text]);
SendClientMessageToAll(-1, str);
ClearLabel(i);
}
}
}
return 1;
}
stock ClearLabel(labelid)
{
if(labelid == INVALID_3DTEXT_ID)
return 0;
Delete3DTextLabel(gLabels[labelid][label_ID]);
gLabels[labelid][label_ID] = Text3D: INVALID_3DTEXT_ID;
gLabels[labelid][label_pos][0] = 0.0;
gLabels[labelid][label_pos][1] = 0.0;
gLabels[labelid][label_pos][2] = 0.0;
gLabels[labelid][label_text][0] = EOS;
gLabels[labelid][label_time] = 0;
return 1;
}