Blockland Forums > Modification Help

Swapping Inventories Problem

Pages: (1/3) > >>

The Russian:

Okay so I've been stuck on this piece of code for a very long time and I can't figure out what's wrong. This is supposed to switch two people's inventories based on how many inventory slots they both have (must have the same amount) and it's been derping.

--- Code: ---//%client and %user are two client objects

%client.player.naToolCount = 0;
while(%client.player.naToolCount < %client.player.getDataBlock().maxtools)
{
%client.player.BDtool = %client.player.tool[%client.player.naToolCount];
%user.player.BDtool = %user.player.tool[client.player.naToolCount];
%client.player.tool[%client.player.naToolCount] = %user.player.BDtool;
%user.player.tool[%client.player.naToolCount] = %client.player.BDtool;
messageClient(%client, 'MsgItemPickup', '', %client.player.naToolCount, %client.player.tool[%client.player.naToolCount]);
messageClient(%user, 'MsgItemPickup', '', %client.player.naToolCount, %user.player.tool[%client.player.naToolCount]);
%client.player.naToolCount++;
}

%client.player.BDtool = "";
%user.player.BDtool = "";
%client.player.naToolCount = "";
--- End code ---
The problem is that, after it executes, the fields storing the ID of the item on %user's player are completely gone (according to dump();) and the %client still has his but can't see them (he's not being messaged about them properly). Can anybody shed some light on this for me?

Ipquarx:

I can see that you have %client.player.naToolCount in both messageclients, but I havn't heard of the properties BDtool or NAtoolcount before.

elm:

There are a few errors in here. For example you have client....stuff instead of %client....stuff. Anyways, this may help you.

i haven't tested this, nor does it have proper checks, but this should help you.


function switchTools(%client1,%client2)
{
   //I think the variable to check a datablocks max tools is
   //datablock.maxTools , but we'll use 5 because I'm doing
   //this off of memory
   
   for(%i=0;%i<5;%i++)
   {
      %t[%client1,%i] = %client1.player.tool[%i];
      %t[%client2,%i] = %client2.player.tool[%i];
      
      %client1.player.tool[%i] = %t[%client2,%i];
      messageClient(%client1, 'MsgItemPickup', '', %i, %t[%client2,%i]);
      
      %client2.player.tool[%i] = %t[%client1,%i];
      messageClient(%client2, 'MsgItemPickup', '', %i, %t[%client1,%i]);
   }
}




The Russian:


--- Quote from: Ipquarx on June 05, 2012, 09:58:29 PM ---I can see that you have %client.player.naToolCount in both messageclients, but I havn't heard of the properties BDtool or NAtoolcount before.

--- End quote ---
Those are two I created. BDTool stored the tools' ID temporarily and NAToolCount was used to determine which tool to update every time the loop ran.

--- Quote from: elm on June 05, 2012, 10:09:10 PM ---There are a few errors in here. For example you have client....stuff instead of %client....stuff. Anyways, this may help you.

i haven't tested this, nor does it have proper checks, but this should help you.


-snip-

--- End quote ---
Thanks, I'll look over it in a bit. Also the datablock field was a bit derpy when I tried using it so I found that getDatablock().maxtools works better. Can you elaborate a little bit more on the the example error you gave?

elm:

You just forgot a % on the fourth line from the while loop inside of the array.

Pages: (1/3) > >>

Go to full version