Item text label problem
#1

I'm working with an item system and when I spawn, the items have their text labels where they should be. However when I pick up an item, the text label stays behind and doesn't get destroyed.

pawn Код:
forward OnPlayerPickupItem(playerid);
public OnPlayerPickupItem(playerid)
{
    new string[128];
    for(new i=0; i<MAX_ITEMS; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2, Item[i][ItemPosX], Item[i][ItemPosY], Item[i][ItemPosZ]) && GetPlayerInterior(playerid) == Item[i][ItemInterior] && GetPlayerVirtualWorld(playerid) == Item[i][ItemVWorld])
        {
            Item[i][ItemPosX] = 0;
            Item[i][ItemPosY] = 0;
            Item[i][ItemPosZ] = 0;
            Item[i][ItemRotX] = 0;
            Item[i][ItemRotY] = 0;
            Item[i][ItemRotZ] = 0;
                if(Item[i][ItemModel] == 2806 && Item[i][ItemType] == 1)
            {
                Player[playerid][BrahminMeat] += Item[i][ItemAmount];
                format(string, sizeof(string), "You have picked up 'Brahmin Meat'.  Amount: %i", Item[i][ItemAmount]);
                SendClientMessage(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), " * %s has picked up something.", GetName(playerid));
                SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            }
            else if(Item[i][ItemModel] == 2806 && Item[i][ItemType] == 2)
            {
                Player[playerid][BrahminSteak] += Item[i][ItemAmount];
                format(string, sizeof(string), "You have picked up 'Brahmin Steak'.  Amount: %i", Item[i][ItemAmount]);
                SendClientMessage(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), " * %s has picked up something.", GetName(playerid));
                SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            }
            Item[i][ItemModel] = 0;
            Item[i][ItemType] = 0;
            Item[i][ItemAmount] = 0;
            DestroyObject(DropObject[i]);
            Delete3DTextLabel(ItemLabel[i]);
        }
    }
    return 1;
}
And when I drop an item, it spawns an object on the ground, but doesn't spawn a text label to accompany it.

pawn Код:
// /drop command
CMD:drop(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    new string[128], item[24], itemamount, Float: x, Float: y, Float: z;
    if(sscanf(params, "s[24]i", item, itemamount)) return SendClientMessage(playerid, COLOR_GREY, "[Server Command]: /drop [item (use /itemslist)] [amount]");
    GetPlayerPos(playerid, x, y, z);
    if(!strcmp(item, "BrahminMeat") || !strcmp(item, "brahminmeat"))
    {
        if(itemamount <= Player[playerid][BrahminMeat])
        {
            format(string, sizeof(string), " * %s has dropped something.", GetName(playerid));
            DropItem(2806, itemamount, 1, x, y, z, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
            Player[playerid][BrahminMeat] -= itemamount;
            SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
            SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            LoadItemVisual();
        }
        else return SendClientMessage(playerid, COLOR_GREY, "You don't have that much Brahmin Meat.");
    }
    else if(!strcmp(item, "BrahminSteak") || !strcmp(item, "brahminsteak"))
    {
        if(itemamount <= Player[playerid][BrahminSteak])
        {
            format(string, sizeof(string), " * %s has dropped something.", GetName(playerid));
            DropItem(2806, itemamount, 2, x, y, z, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
            Player[playerid][BrahminSteak] -= itemamount;
            SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
            SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            LoadItemVisual();
        }
        else return SendClientMessage(playerid, COLOR_GREY, "You don't have that much Brahmin Steak.");
    }
    return 1;
}

//DropItem function
stock DropItem(model, amount, type, Float:X, Float:Y, Float:Z, world, interior)
{
    if(model != 0)
    {
        for(new i=0; i<MAX_ITEMS; i++)
        {
            if(Item[i][ItemPosX] == 0 && Item[i][ItemPosY] == 0 && Item[i][ItemPosZ] == 0)
            {
                Item[i][ItemModel] = model;
                Item[i][ItemAmount] = amount;
                Item[i][ItemType] = type;
                Item[i][ItemPosX] = X;
                Item[i][ItemPosY] = Y;
                Item[i][ItemPosZ] = Z;
                Item[i][ItemVWorld] = world;
                Item[i][ItemInterior] = interior;
                //ItemLabel[i] = Create3DTextLabel("ItemName", COLOR_BLUE, X, Y, Z, 5, world, 0);
                DropObject[i] = CreateObject(model, X, Y, Z-1, 0, 0, 0, world);
                LoadItemVisual();
                break;
            }
        }
    }
    return 1;
}

//LoadItemVisual function
stock LoadItemVisual()
{
    for(new i=0; i<MAX_ITEMS; i++)
    {
        if(Item[i][ItemModel] == 0) Delete3DTextLabel(ItemLabel[i]);
        if(Item[i][ItemModel] == 2806 && Item[i][ItemType] == 1)
        {
            ItemLabel[i] = Create3DTextLabel("Brahmin Meat", COLOR_BLUE, Item[i][ItemPosX], Item[i][ItemPosY], Item[i][ItemPosZ], 7, Item[i][ItemVWorld]);
        }
        if(Item[i][ItemModel] == 2806 && Item[i][ItemType] == 2)
        {
            ItemLabel[i] = Create3DTextLabel("Brahmin Steak", COLOR_BLUE, Item[i][ItemPosX], Item[i][ItemPosY], Item[i][ItemPosZ], 7, Item[i][ItemVWorld]);
        }
    }
    return 1;
}
Again, not sure what I'm doing wrong here, but I'm also sure I'm overlooking the issue, so any help is appreciated

EDIT: I managed to fix the second problem with the text label not showing up after dropping an item, but the text label still stays behind when I pick an item up.
Reply
#2

Hello!

What is printing here if you enter a pickup.
PHP код:
forward OnPlayerPickupItem(playerid);
public 
OnPlayerPickupItem(playerid)
{
    new 
string[128];
    for(new 
i=0i<MAX_ITEMSi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid2Item[i][ItemPosX], Item[i][ItemPosY], Item[i][ItemPosZ]) && GetPlayerInterior(playerid) == Item[i][ItemInterior] && GetPlayerVirtualWorld(playerid) == Item[i][ItemVWorld])
        {
            
printf("i: %d | ItemLabel[%d]: %d",i,i,ItemLabel[i]);
            
Item[i][ItemPosX] = 0;
            
Item[i][ItemPosY] = 0;
            
Item[i][ItemPosZ] = 0;
            
Item[i][ItemRotX] = 0;
            
Item[i][ItemRotY] = 0;
            
Item[i][ItemRotZ] = 0;
                if(
Item[i][ItemModel] == 2806 && Item[i][ItemType] == 1)
            {
                
Player[playerid][BrahminMeat] += Item[i][ItemAmount];
                
format(stringsizeof(string), "You have picked up 'Brahmin Meat'.  Amount: %i"Item[i][ItemAmount]);
                
SendClientMessage(playeridCOLOR_WHITEstring);
                
format(stringsizeof(string), " * %s has picked up something."GetName(playerid));
                
SetPlayerChatBubble(playeridstringCOLOR_LIGHTPURPLE107000);
                
SendClientMessage(playeridCOLOR_LIGHTPURPLEstring);
            }
            else if(
Item[i][ItemModel] == 2806 && Item[i][ItemType] == 2)
            {
                
Player[playerid][BrahminSteak] += Item[i][ItemAmount];
                
format(stringsizeof(string), "You have picked up 'Brahmin Steak'.  Amount: %i"Item[i][ItemAmount]);
                
SendClientMessage(playeridCOLOR_WHITEstring);
                
format(stringsizeof(string), " * %s has picked up something."GetName(playerid));
                
SetPlayerChatBubble(playeridstringCOLOR_LIGHTPURPLE107000);
                
SendClientMessage(playeridCOLOR_LIGHTPURPLEstring);
            }
            
Item[i][ItemModel] = 0;
            
Item[i][ItemType] = 0;
            
Item[i][ItemAmount] = 0;
            
DestroyObject(DropObject[i]);
            
Delete3DTextLabel(ItemLabel[i]);
            
printf("ItemLabel[%d]: %d",i,ItemLabel[i]);
        }
    }
    return 
1;

Mencent
Reply
#3

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

What is printing here if you enter a pickup.
PHP код:
forward OnPlayerPickupItem(playerid);
public 
OnPlayerPickupItem(playerid)
{
    new 
string[128];
    for(new 
i=0i<MAX_ITEMSi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid2Item[i][ItemPosX], Item[i][ItemPosY], Item[i][ItemPosZ]) && GetPlayerInterior(playerid) == Item[i][ItemInterior] && GetPlayerVirtualWorld(playerid) == Item[i][ItemVWorld])
        {
            
printf("i: %d | ItemLabel[%d]: %d",i,i,ItemLabel[i]);
            
Item[i][ItemPosX] = 0;
            
Item[i][ItemPosY] = 0;
            
Item[i][ItemPosZ] = 0;
            
Item[i][ItemRotX] = 0;
            
Item[i][ItemRotY] = 0;
            
Item[i][ItemRotZ] = 0;
                if(
Item[i][ItemModel] == 2806 && Item[i][ItemType] == 1)
            {
                
Player[playerid][BrahminMeat] += Item[i][ItemAmount];
                
format(stringsizeof(string), "You have picked up 'Brahmin Meat'.  Amount: %i"Item[i][ItemAmount]);
                
SendClientMessage(playeridCOLOR_WHITEstring);
                
format(stringsizeof(string), " * %s has picked up something."GetName(playerid));
                
SetPlayerChatBubble(playeridstringCOLOR_LIGHTPURPLE107000);
                
SendClientMessage(playeridCOLOR_LIGHTPURPLEstring);
            }
            else if(
Item[i][ItemModel] == 2806 && Item[i][ItemType] == 2)
            {
                
Player[playerid][BrahminSteak] += Item[i][ItemAmount];
                
format(stringsizeof(string), "You have picked up 'Brahmin Steak'.  Amount: %i"Item[i][ItemAmount]);
                
SendClientMessage(playeridCOLOR_WHITEstring);
                
format(stringsizeof(string), " * %s has picked up something."GetName(playerid));
                
SetPlayerChatBubble(playeridstringCOLOR_LIGHTPURPLE107000);
                
SendClientMessage(playeridCOLOR_LIGHTPURPLEstring);
            }
            
Item[i][ItemModel] = 0;
            
Item[i][ItemType] = 0;
            
Item[i][ItemAmount] = 0;
            
DestroyObject(DropObject[i]);
            
Delete3DTextLabel(ItemLabel[i]);
            
printf("ItemLabel[%d]: %d",i,ItemLabel[i]);
        }
    }
    return 
1;

Mencent
I'm not sure if I understand what you mean, but if I do, this isn't under OnPlayerPickupPickup, it has nothing to do with pickups at all. If that's not what you mean, then I'm not sure what you added would help me with.
Reply
#4

If you enter your pickups, which called this callback:
PHP код:
public OnPlayerPickupItem(playerid
the callback is printing two prints. Try this.

Mencent
Reply
#5

Quote:
Originally Posted by Mencent
Посмотреть сообщение
If you enter your pickups, which called this callback:
PHP код:
public OnPlayerPickupItem(playerid
the callback is printing two prints. Try this.

Mencent
But my problem has nothing to do with pickups as no pickups are involved with my problem I'm having.

I tried it anyways and didn't really give me much light into what the problem is.
Reply
#6

What exactly is your problem?

Mencent
Reply
#7

Make sur that you have new 3dtext:ItemLabel[MAX_ITEMS];
Reply
#8

Quote:
Originally Posted by Azula
Посмотреть сообщение
Make sur that you have new 3dtext:ItemLabel[MAX_ITEMS];
lol, if I didn't, I'd already be getting errors throughout the script before of it.
Reply
#9

PHP код:
new Text3D:mylabel;
    
mylabel Create3DTextLabel("I'm at the coordinates:\n30.0,40.0,50.0",0x008080FF,30.0,40.0,50.0,40.0,0); 
source ^^
https://sampwiki.blast.hk/wiki/Update3DTextLabelText
Reply
#10

L&A, figured out the problem.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)