new LabelTimer[MAX_PLAYERS];
new Text3D:Label3D[MAX_PLAYERS];
stock ShowLabelToPlayer(playerid, text[], color, Float:x, Float:y, Float:z, time, Float:distance, vehicle = INVALID_VEHICLE_ID)
{
return 1;
}
if(IsValidDynamic3DTextLabel(Label3D[playerid]))
{
KillTimer(LabelTimer[playerid]);
DestroyDynamic3DTextLabel(Label3D[playerid]);
}
Label3D[playerid] = CreateDynamic3DTextLabel(text, color, x, y, z, distance, .attachedvehicle = vehicle, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid), .playerid = playerid);
LabelTimer[playerid] = SetTimerEx("TerminateLabel", (1000 * time), false, "d", playerid);
if(IsValidDynamic3DTextLabel(Label3D[playerid]))
{
KillTimer(LabelTimer[playerid]);
DestroyDynamic3DTextLabel(Label3D[playerid]);
}
forward TerminateLabel(playerid);
public TerminateLabel(playerid)
{
KillTimer(LabelTimer[playerid]);
return DestroyDynamic3DTextLabel(Label3D[playerid]);
}
// Below the #includes
new LabelTimer[MAX_PLAYERS];
new Text3D:Label3D[MAX_PLAYERS];
public OnPlayerDisconnect(playerid, reason)
{
if(IsValidDynamic3DTextLabel(Label3D[playerid]))
{
KillTimer(LabelTimer[playerid]);
DestroyDynamic3DTextLabel(Label3D[playerid]);
}
return 1;
}
stock ShowLabelToPlayer(playerid, text[], color, Float:x, Float:y, Float:z, time, Float:distance, vehicle = INVALID_VEHICLE_ID)
{
if(IsValidDynamic3DTextLabel(Label3D[playerid]))
{
KillTimer(LabelTimer[playerid]);
DestroyDynamic3DTextLabel(Label3D[playerid]);
}
Label3D[playerid] = CreateDynamic3DTextLabel(text, color, x, y, z, distance, .attachedvehicle = vehicle, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid), .playerid = playerid);
LabelTimer[playerid] = SetTimerEx("TerminateLabel", (1000 * time), false, "d", playerid);
return 1;
}
forward TerminateLabel(playerid);
public TerminateLabel(playerid)
{
KillTimer(LabelTimer[playerid]);
return DestroyDynamic3DTextLabel(Label3D[playerid]);
}
#include <a_samp>
#include <zcmd>
#include <streamer>
new Specific[MAX_PLAYERS];
new LabelTimer[MAX_PLAYERS];
new Text3D:Label3D[MAX_PLAYERS];
new LSPDVehicles[6];
// A test command that shows ShowLabelToPlayer working without the vehicle attachment.
// Sets the var Specific to ZERO/ONE (creates a label to the player's position)
CMD:test(playerid, params[])
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
switch(Specific[playerid])
{
case false:
{
Specific[playerid] = true;
ShowLabelToPlayer(playerid, "This is a test command, you have set a var to one.", 0x33AA33FF, x, y, z, 5, 10.0);
}
case true:
{
Specific[playerid] = false;
ShowLabelToPlayer(playerid, "This is a test command, you have set a var to false.", 0xFF6347FF, x, y, z, 5, 10.0);
}
}
return 1;
}
public OnFilterScriptInit()
{
// Sample vehicles.
LSPDVehicles[0] = AddStaticVehicleEx(596, 1602.5122, -1680.3663, 5.4630, 90.1200, 0, 1, -1);
LSPDVehicles[1] = AddStaticVehicleEx(596, 1602.4829, -1684.0609, 5.4630, 90.1200, 0, 1, -1);
LSPDVehicles[2] = AddStaticVehicleEx(596, 1602.5535, -1688.0438, 5.4630, 90.1200, 0, 1, -1);
LSPDVehicles[3] = AddStaticVehicleEx(596, 1602.6227, -1692.1034, 5.4630, 90.1200, 0, 1, -1);
LSPDVehicles[4] = AddStaticVehicleEx(596, 1602.4873, -1696.2058, 5.4630, 90.1200, 0, 1, -1);
LSPDVehicles[5] = AddStaticVehicleEx(596, 1602.5120, -1700.2861, 5.4630, 90.1200, 0, 1, -1);
return 1;
}
public OnPlayerConnect(playerid)
{
// Sets Specific var to ZERO.
Specific[playerid] = false;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(IsValidDynamic3DTextLabel(Label3D[playerid]))
{
KillTimer(LabelTimer[playerid]);
DestroyDynamic3DTextLabel(Label3D[playerid]);
}
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
for(new i; i < sizeof(LSPDVehicles); i++)
{
if(vehicleid == LSPDVehicles[i])
{
// If the var for Specific is set to ZERO then the player cannot enter.
if(!Specific[playerid])
{
// Claars animation after the player attempted to enter the vehicle.
ClearAnimations(playerid);
return ShowLabelToPlayer(playerid, "You are not a LSPD, cannot enter this vehicle.", 0xFF6347FF, 0.0, 0.0, 0.0, 5, 10.0, vehicleid);
// Uses the function, Attachs a label to the player's entered vehicle with the context "You are not a LSPD, cannot enter this vehicle."
// Color - Lightred, The time when the label will disappear/expire is 5 seconds (The label can be seen within 10 meters radius only)
}
}
}
return 1;
}
stock ShowLabelToPlayer(playerid, text[], color, Float:x, Float:y, Float:z, time, Float:distance, vehicle = INVALID_VEHICLE_ID)
{
if(IsValidDynamic3DTextLabel(Label3D[playerid]))
{
KillTimer(LabelTimer[playerid]);
DestroyDynamic3DTextLabel(Label3D[playerid]);
}
Label3D[playerid] = CreateDynamic3DTextLabel(text, color, x, y, z, distance, .attachedvehicle = vehicle, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid), .playerid = playerid);
LabelTimer[playerid] = SetTimerEx("TerminateLabel", (1000 * time), false, "d", playerid);
return 1;
}
forward TerminateLabel(playerid);
public TerminateLabel(playerid)
{
KillTimer(LabelTimer[playerid]);
return DestroyDynamic3DTextLabel(Label3D[playerid]);
}
Pictures? For those who seem curious but don't know what you're talking about.
|
You just had to find the most unoptimized way to do this, there's functions for this already.
https://sampwiki.blast.hk/wiki/CreatePlayer3DTextLabel |