31.10.2015, 05:08
Previously, I have made a topic about the Player Labels.
I figured it out on scripting it, and eventually the script works properly.
I am creating a vehicle system and everything works fine so far but!
I have noticed something between the player_label and vehicle_label Text3D.
For example, When i spawn my personal vehicle it displays
"This Bike is owned by FFG.JaKe(0)"
I am in a spawn protection, and once that spawn protection expires, LabelUpdate gets called.
When the LabelUpdate is called, the vehicle_label is affected instead of the player_label.
"This Bike is owned by FFG.JaKe(0)" is then changed to "Admin/VIP"
Below are the codes showing how i manage/work with these labels:
These Text3D labels are conflicting on each other?? If so, how can i fix it.
I figured it out on scripting it, and eventually the script works properly.
I am creating a vehicle system and everything works fine so far but!
I have noticed something between the player_label and vehicle_label Text3D.
For example, When i spawn my personal vehicle it displays
"This Bike is owned by FFG.JaKe(0)"
I am in a spawn protection, and once that spawn protection expires, LabelUpdate gets called.
When the LabelUpdate is called, the vehicle_label is affected instead of the player_label.
"This Bike is owned by FFG.JaKe(0)" is then changed to "Admin/VIP"
Below are the codes showing how i manage/work with these labels:
PHP код:
new Text3D:player_label[MAX_PLAYERS];
new Text3D:vehicle_label[MAX_VEHICLES];
public OnPlayerConnect(playerid)
{
player_label[playerid] = Create3DTextLabel("_", 0xFFFFFF00, 0, 0, 0, 30, 0, 1);
Attach3DTextLabelToPlayer(player_label[playerid], playerid, 0, 0, 0.4);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(User[playerid][ownedvehicle_id])
{
Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
DestroyVehicle(User[playerid][ownedvehicle_id]);
}
Delete3DTextLabel(player_label[playerid]);
return 1;
}
CMD:spawnvehicle(playerid, params[])
{
if(mode == MINIGUN_ID || mode == FREIGHTER_ID || mode == AREA51_ID || mode == STREET_ID || mode == ZOMBIE_ID || mode == AIL_ID || mode == HI_ID || mode == CP_ID)
return SendClientMessage(playerid, -1, "You cannot spawn your personal vehicle during this game round.");
if(User[playerid][accountLogged] == false) return SendClientMessage(playerid, COLOR_YELLOW, "You are not logged in.");
if(User[playerid][ownedvehicle] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not own a vehicle.");
if(!IsPlayerSpawn(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must be spawned to use this command.");
if(User[playerid][account_Objective] == true) return SendClientMessage(playerid, COLOR_RED, "You must be out of objective info screen first.");
if(User[playerid][SpecType] != ADMIN_SPEC_TYPE_NONE) return SendClientMessage(playerid, COLOR_RED, "You must not be on spectate mode to use this command.");
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are already in a vehicle.");
if(User[playerid][ownedvehicle_id]) return SendClientMessage(playerid, COLOR_RED, "You have already spawned your personal vehicle.");
Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
DestroyVehicle(User[playerid][ownedvehicle_id]);
new Float:x, Float:y, Float:z, Float:a, string[128];
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
User[playerid][ownedvehicle_id] = CreateVehicle(User[playerid][ownedvehicle_model], x, y, z+1, a, User[playerid][ownedvehicle_color][0], User[playerid][ownedvehicle_color][1], -1);
LinkVehicleToInterior(User[playerid][ownedvehicle_id], GetPlayerInterior(playerid));
SetVehicleVirtualWorld(User[playerid][ownedvehicle_id], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, User[playerid][ownedvehicle_id], 0);
format(string, sizeof string, "This %s is owned by %s(%d).", VehicleNames[User[playerid][ownedvehicle_model]-400], GetName(playerid), playerid);
vehicle_label[User[playerid][ownedvehicle_id]] = Create3DTextLabel(string, -1, 0, 0, 0, 80, 0, 1);
Attach3DTextLabelToVehicle(vehicle_label[User[playerid][ownedvehicle_id]], User[playerid][ownedvehicle_id], 0.0, 0.0, 0.0);
SendClientMessage(playerid, COLOR_YELLOW, "* You have spawned your personal vehicle.");
return 1;
}
CMD:destroyvehicle(playerid, params[])
{
if(User[playerid][accountLogged] == false) return SendClientMessage(playerid, COLOR_YELLOW, "You are not logged in.");
if(User[playerid][ownedvehicle] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not own a personal vehicle.");
if(GetPVarInt(playerid, "destroy_vehicle"))
{
SendClientMessage(playerid, COLOR_YELLOW, "* Your vehicle has been destroyed.");
SendClientMessage(playerid, -1, "You may own a new one.");
if(User[playerid][ownedvehicle_id])
{
Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
DestroyVehicle(User[playerid][ownedvehicle_id]);
User[playerid][ownedvehicle_id] = 0;
}
//
User[playerid][ownedvehicle] = 0;
User[playerid][ownedvehicle_model] = 0;
User[playerid][ownedvehicle_color][0] = 0;
User[playerid][ownedvehicle_color][1] = 0;
//
DeletePVar(playerid, "destroy_vehicle");
}
else
{
SendClientMessage(playerid, -1, "You are about to delete your "red"personal vehicle"white".");
SendClientMessage(playerid, COLOR_YELLOW, "Type /destroyvehicle for the second time if you wanted to delete your personal vehicle.");
SetPVarInt(playerid, "destroy_vehicle", 1);
}
return 1;
}
// Below are the function LabelUpdate, I am not gonna post down the codes where this function is called in but let me give you a hint. This function is called when player gets promoted/demoted from admin,vip, Spawn Protection, Login.
stock LabelUpdate(i)
{
if(Spawn_Kill[i] == true)
{
Update3DTextLabelText(player_label[i], 0x28BA9AFF, "Spawn Protection");
return 1;
}
if(User[i][accountDuty] == 1)
{
Update3DTextLabelText(player_label[i], COLOR_GREEN, "Admin On Duty");
return 1;
}
if(User[i][accountAdmin] >= 1 && User[i][accountVip] == 1)
{
Update3DTextLabelText(player_label[i], COLOR_RED, "Admin"white"/{28BA9A}VIP");
}
else if(User[i][accountAdmin] >= 1 && User[i][accountVip] == 0)
{
Update3DTextLabelText(player_label[i], COLOR_RED, "Admin Staff");
}
else if(User[i][accountAdmin] == 0 && User[i][accountVip] == 1)
{
Update3DTextLabelText(player_label[i], 0x28BA9AFF, "VIP Member");
}
else if(User[i][accountAdmin] == 0 && User[i][accountVip] == 0)
{
Update3DTextLabelText(player_label[i], 0xFFFFFF00, "_");
}
return 1;
}