3D Text Label
#1

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:

PHP код:
new Text3D:player_label[MAX_PLAYERS];
new 
Text3D:vehicle_label[MAX_VEHICLES];
public 
OnPlayerConnect(playerid)
{
    
player_label[playerid] = Create3DTextLabel("_"0xFFFFFF000003001);
    
Attach3DTextLabelToPlayer(player_label[playerid], playerid000.4);
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    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(playeridparams[])
{
    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(playeridCOLOR_YELLOW"You are not logged in.");
    if(
User[playerid][ownedvehicle] == 0) return SendClientMessage(playeridCOLOR_RED"You do not own a vehicle.");
    if(!
IsPlayerSpawn(playerid)) return SendClientMessage(playeridCOLOR_RED"You must be spawned to use this command.");
    if(
User[playerid][account_Objective] == true) return SendClientMessage(playeridCOLOR_RED"You must be out of objective info screen first.");
    if(
User[playerid][SpecType] != ADMIN_SPEC_TYPE_NONE) return SendClientMessage(playeridCOLOR_RED"You must not be on spectate mode to use this command.");
    if(
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridCOLOR_RED"You are already in a vehicle.");
    if(
User[playerid][ownedvehicle_id]) return SendClientMessage(playeridCOLOR_RED"You have already spawned your personal vehicle.");
    
Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
    
DestroyVehicle(User[playerid][ownedvehicle_id]);
    new 
Float:xFloat:yFloat:zFloat:astring[128];
    
GetPlayerPos(playeridxyz);
    
GetPlayerFacingAngle(playerida);
    
    
User[playerid][ownedvehicle_id] = CreateVehicle(User[playerid][ownedvehicle_model], xyz+1aUser[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(playeridUser[playerid][ownedvehicle_id], 0);
    
format(stringsizeof 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, -10008001);
    
Attach3DTextLabelToVehicle(vehicle_label[User[playerid][ownedvehicle_id]], User[playerid][ownedvehicle_id], 0.00.00.0);
    
    
SendClientMessage(playeridCOLOR_YELLOW"* You have spawned your personal vehicle.");
    return 
1;
}
CMD:destroyvehicle(playeridparams[])
{
    if(
User[playerid][accountLogged] == false) return SendClientMessage(playeridCOLOR_YELLOW"You are not logged in.");
    if(
User[playerid][ownedvehicle] == 0) return SendClientMessage(playeridCOLOR_RED"You do not own a personal vehicle.");
    if(
GetPVarInt(playerid"destroy_vehicle"))
    {
        
SendClientMessage(playeridCOLOR_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(playeridCOLOR_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] >= && User[i][accountVip] == 1)
    {
        
Update3DTextLabelText(player_label[i], COLOR_RED"Admin"white"/{28BA9A}VIP");
    }
    else if(
User[i][accountAdmin] >= && User[i][accountVip] == 0)
    {
        
Update3DTextLabelText(player_label[i], COLOR_RED"Admin Staff");
    }
    else if(
User[i][accountAdmin] == && User[i][accountVip] == 1)
    {
        
Update3DTextLabelText(player_label[i], 0x28BA9AFF"VIP Member");
    }
    else if(
User[i][accountAdmin] == && User[i][accountVip] == 0)
    {
        
Update3DTextLabelText(player_label[i], 0xFFFFFF00"_");
    }
    return 
1;

These Text3D labels are conflicting on each other?? If so, how can i fix it.
Reply
#2

pawn Код:
Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
Before deleting, you must check if it is existing or not, because it may destroy the one with the value stored in that array.

Here you can do that by checking for vehicle instead (in your command: spawnvehicle)
pawn Код:
if (IsValidVehicle(User[playerid][ownedvehicle_id]))
{
    Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
    DestroyVehicle(User[playerid][ownedvehicle_id]);
}
Just for your future updating, maximum 3D text limit is 1024. (use streamer and you won't need to get into too much hassle like in this)
Reply
#3

Quote:
Originally Posted by Gammix
Посмотреть сообщение
pawn Код:
Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
Before deleting, you must check if it is existing or not, because it may destroy the one with the value stored in that array.

Here you can do that by checking for vehicle instead (in your command: spawnvehicle)
pawn Код:
if (IsValidVehicle(User[playerid][ownedvehicle_id]))
{
    Delete3DTextLabel(vehicle_label[User[playerid][ownedvehicle_id]]);
    DestroyVehicle(User[playerid][ownedvehicle_id]);
}
Just for your future updating, maximum 3D text limit is 1024. (use streamer and you won't need to get into too much hassle like in this)
Well i am pretty sure it has nothing to do with the Delete3DTextLabel.
It's just that, the LabelUpdate updates the vehicle_label, instead of player_label.

By the way, thank you for letting me know.

Edit: IsValidVehicle doesn't exist.
Reply
#4

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
Edit: IsValidVehicle doesn't exist.
Quote:

This function exists within the SA-MP server, but it has not been defined within the include files. To use this function, you must first declare the appropriate native at the top of your script:

'native IsValidVehicle(vehicleid);'. It is recommended you place this under the inclusion of a_samp.inc

https://sampwiki.blast.hk/wiki/IsValidVehicle
Reply
#5

This is an alternative to IsValidVehicle.

pawn Код:
stock VEH_IsValidVehicle(vehicleid)
{
    return (400 <= GetVehicleModel(vehicleid) <= 611) ? true : false;
}
#if defined _ALS_IsValidVehicle
    #undef IsValidVehicle
#else
    #define _ALS_IsValidVehicle
#endif
#define IsValidVehicle VEH_IsValidVehicle
Refrence
Reply
#6

Aight i got the IsValidVehicle thing working, however the situation is still the same, LabelUpdate affects the vehicle label instead of the player label.
Reply
#7

Try debugging the values stored in both the arrays, under LabelUpdate.

pawn Код:
printf("player_label: %i | vehicle_label: %i", _:player_label[playerid], _:vehicle_label[User[playerid][ownedvehicle_id]]);
Reply
#8

The results are both 0. That explains why the text label conflicts, How can i increase the Text3D ID for vehicle_label?
Reply
#9

I managed to fix it by using streamer.
The default 3D Text Label has well known issues on conflicting Text3D ids if i am not wrong.

Thank you jlalt and Gammix for helping me out in the problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)