20.04.2015, 17:17
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.
And when I drop an item, it spawns an object on the ground, but doesn't spawn a text label to accompany it.
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.
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;
}
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;
}
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.