Very strange bug in saving/loading items.
#1

I have a problem with loading saved items.
All items get loaded correctly, but some of them cannot be picked up after server restart.
for example if there are 2 dropped items saved, one of em will be available to pickup.
The other item is there, just like other items, but when picking it up, it simply doesn't do anything.
If i pick up the item i can pick up, and then restart the server, i can pick up the item which i couldnt pickup before.
It seems that only 1 item will be available to pickup.
What is causing this?

code:
Код:
//==============================================================================
stock DropItem(Float:X, Float:Y, Float:Z, world,interior,modelid)
{
        for(new i = 0; i < sizeof(ItemInfo); i++)
        {
            if(ItemInfo[i][ItemPosX] == 0.0 && ItemInfo[i][ItemPosY] == 0.0 && ItemInfo[i][ItemPosZ] == 0.0)
            {
                new string[128];
                ItemInfo[i][ItemPosX] = X;
                ItemInfo[i][ItemPosY] = Y;
                ItemInfo[i][ItemPosZ] = Z;
                ItemInfo[i][ItemVWorld] = world;
                ItemInfo[i][ItemInterior] = interior;
				ItemInfo[i][ItemModelID] = modelid;
    			format(string,sizeof(string),"%s (Press 'H' to pick up)",GetItemName(modelid));
                Label2[i] = Create3DTextLabel(string, COLOR_YELLOW,X,Y,Z, 3.0,world, 0);
                Item[i] = CreateDynamicObject(modelid, X, Y, Z,272,0,0, world);
                new file[64];
				format(file, sizeof(file), "Loot/item%d.ini", i);
				if(!fexist(file)) { INI_Create(file); }
				ItemInfo[i][ItemID] = i;
				INI_IntSet(file,"ItemPosX", floatround(ItemInfo[i][ItemPosX]));
				INI_IntSet(file,"ItemPosY", floatround(ItemInfo[i][ItemPosY]));
				INI_IntSet(file,"ItemPosZ", floatround(ItemInfo[i][ItemPosZ]));
				INI_IntSet(file,"ItemVWorld", ItemInfo[i][ItemVWorld]);
				INI_IntSet(file,"ItemInterior", ItemInfo[i][ItemInterior]);
				INI_IntSet(file,"ItemModelID", ItemInfo[i][ItemModelID]);
                INI_IntSet(file,"ItemID", ItemInfo[i][ItemID]);
				return 0;
            }
        }
		return 1;
}
//==============================================================================
LoadDroppedItems(lootid)
{
    for(new i=0; i < MAX_DROP_ITEMS; i++)
    {
		new string[128], Float:X, Float:Y, Float:Z, world,modelid;
        if(!fexist(LootPath(lootid)))return 0;
		ItemInfo[i][ItemPosX]=INI_Int(LootPath(lootid),"ItemPosX");
        ItemInfo[i][ItemPosY]=INI_Int(LootPath(lootid),"ItemPosY");
        ItemInfo[i][ItemPosZ]=INI_Int(LootPath(lootid),"ItemPosZ");
        ItemInfo[i][ItemVWorld]=INI_Int(LootPath(lootid),"ItemVWorld");
		ItemInfo[i][ItemInterior]=INI_Int(LootPath(lootid),"ItemInterior");
		ItemInfo[i][ItemModelID]=INI_Int(LootPath(lootid),"ItemModelID");
		ItemInfo[i][ItemID]=INI_Int(LootPath(lootid),"ItemID");
        X = ItemInfo[i][ItemPosX];
        Y = ItemInfo[i][ItemPosY];
        Z = ItemInfo[i][ItemPosZ];
        world = ItemInfo[i][ItemVWorld];
		modelid = ItemInfo[i][ItemModelID];
		format(string,sizeof(string),"%s (Press 'H' to pick up)",GetItemName(modelid));
        Label2[i] = Create3DTextLabel(string, COLOR_YELLOW,X,Y,Z, 3.0,world, 0);
        Item[i] = CreateDynamicObject(modelid, X, Y, Z,272,0,0, world);
        return 1;
    }
	return 1;
}

//pickup up item - onplayerkey
for(new i = 0; i < sizeof(ItemInfo); i++)
{
	if (IsPlayerInRangeOfPoint(playerid, 2.0,ItemInfo[i][ItemPosX],ItemInfo[i][ItemPosY],ItemInfo[i][ItemPosZ]))
	{
    	if(GetPlayerVirtualWorld(playerid) == ItemInfo[i][ItemVWorld] && GetPlayerInterior(playerid) == ItemInfo[i][ItemInterior])
    	{
			if(ItemInfo[i][Toggled] == 0)
			{
				if(Inventory[playerid][InvBag] == 0)
				{
					if(Inventory[playerid][InvSlots] > 19) return SendClientMessage(playerid,RED,"Your inventory is full, purchase a bag to obtain more slots.");
				}
				if(Inventory[playerid][InvBag] >= 1)
				{
					if(Inventory[playerid][InvSlots] > 39) return SendClientMessage(playerid,RED,"Your inventory is full.");
				}
				new modelid = ItemInfo[i][ItemModelID];
				new lootid = ItemInfo[i][ItemID];
            	new str[128];
            	new x,y,z,w,in,m;
            	x = 0;
            	y = 0;
            	z = 0;
            	w = 0;
            	in = 0;
            	m = 0;
				INI_IntSet(LootPath(lootid),"ItemPosX", x);
				INI_IntSet(LootPath(lootid),"ItemPosY", y);
				INI_IntSet(LootPath(lootid),"ItemPosZ", z);
				INI_IntSet(LootPath(lootid),"ItemVWorld", w);
				INI_IntSet(LootPath(lootid),"ItemInterior", in);
				INI_IntSet(LootPath(lootid),"ItemModelID", m);
				fremove(LootPath(lootid));
            	ApplyAnimation(playerid, "CARRY", "putdwn",4.1,0,1,1,0,0);
            	PickupItemTimer(playerid);
				format(str,sizeof(str),"%s(%i) has picked up %s from their surroundings. Item ID %d has been removed.",PlayerName(playerid),playerid,GetItemName(modelid),lootid);
				SendNearbyMessage(playerid,30.0,str,ORANGE);
				AddItem(playerid,modelid);
				ItemInfo[i][Toggled] = 1;
				Delete3DTextLabel(Label2[i]);
				DestroyDynamicObject(Item[i]);
				NoCheat[playerid] = 1;
				Crouch[playerid] = 1;
				SaveInventory(playerid);
				Inventory[playerid][InvSlots] += 1;
				return 1;
			}
		}else return 0;
	}
}
Thanks in advance
Reply
#2

Bump
Reply
#3

Bump
Reply
#4

This could be caused by incorrectly using OnPlayerKeystateChange.
Reply
#5

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
This could be caused by incorrectly using OnPlayerKeystateChange.
Unfortunately it does not. I Did try to execute picking up the item with a command and that didnt work either.
Reply
#6

Did it actually ever work? And what did you do around when you started noticing it?
Reply
#7

Thanks for your help . Of course, dropping and picking up items works petfectly, but when i restart the server all the items get loaded, But only one of the items is available to pick-up. Could the problem be at loading items? Maybe this loop? for(new i=0; i < MAX_DROP_ITEMS; i++)
Reply
#8

Bump
Reply
#9

pawn Код:
for(new i = 0; i < sizeof(ItemInfo); i++)
{
    if (IsPlayerInRangeOfPoint(playerid, 2.0,ItemInfo[i][ItemPosX],ItemInfo[i][ItemPosY],ItemInfo[i][ItemPosZ]))
    {
        if(GetPlayerVirtualWorld(playerid) == ItemInfo[i][ItemVWorld] && GetPlayerInterior(playerid) == ItemInfo[i][ItemInterior])
        {
            if(ItemInfo[i][Toggled] == 0)
            {
                // (...)
                return 1;
            }
        }else return 0; // <-- This little shit
    }
}
Get rid of the return 0, otherwise other items won't even get looped over

#e: Hm, this is problematic, but might not be the root cause. Either way, check it first
Reply
#10

Quote:
Originally Posted by Misiur
Посмотреть сообщение
pawn Код:
for(new i = 0; i < sizeof(ItemInfo); i++)
{
    if (IsPlayerInRangeOfPoint(playerid, 2.0,ItemInfo[i][ItemPosX],ItemInfo[i][ItemPosY],ItemInfo[i][ItemPosZ]))
    {
        if(GetPlayerVirtualWorld(playerid) == ItemInfo[i][ItemVWorld] && GetPlayerInterior(playerid) == ItemInfo[i][ItemInterior])
        {
            if(ItemInfo[i][Toggled] == 0)
            {
                // (...)
                return 1;
            }
        }else return 0; // <-- This little shit
    }
}
Get rid of the return 0, otherwise other items won't even get looped over

#e: Hm, this is problematic, but might not be the root cause. Either way, check it first
Thanks for the help, the problem was with saving, some items didnt get their coords saved in the enum. ( found out by using debug msges)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)