Author Topic: Crafting System Help  (Read 1825 times)

I've been trying to make a crafting system for my Escapists server, and made something that didn't work. I am, however, pretty sure it doesn't work due to some errors I made (NOT sytax errors) while working on it.
What it is supposed to do: Type /craftItem <itemName> <TwoOrThreeSlotNumbers>, and then it will check to see if the items in <TwoOrThreeSlotNumbers> are the required item for <ItemName>.
What it Does: Absolutely nothing.

Here's the code:
Code: [Select]
function serverCmdCraftItem (%client, %item, %item1, %item2, %item3)
{
%player = %client.player;
%item = %item@"Item";
for(%i = 1; %i < 3; %i++)
{
%slot[%i] = %item[%i];
%item[%i] = %client.player.tool[%item[%i]];
%item[%i] = %item[%i]@"Item"; //Make it so instead of showing up as "ToiletPaper" it'll show up "ToiletPaperItem";
}
%craftReq = %item.craftingRequrements;
%craftINT = %item.craftingIntRequirement;
%craftReq = strReplace(%craftReq, ",", ""); //remove commas from Crafting Requirement string.
%craftItem[0] = getWord(%craftReq, 0);
%craftItem[1] = getWord(%craftReq, 1);
%craftItem[2] = getWord(%craftReq, 2);
if(%craftItem[2] $= "")
{
%item3 = "";
}
if(%item1 $= %craftItem[0] && %item2 $= %craftItem[1] && %item3 $= "")
{
echo(%client.name@" - Crafting success!");
%currSlot = %slot[0];
%obj.tool[%currSlot] = 0;
%obj.weaponCount--;
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
serverCmdUnUseTool(%obj.client);

%currSlot = %slot[1];
%obj.tool[%currSlot] = 0;
%obj.weaponCount--;
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
serverCmdUnUseTool(%obj.client);

for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
{
%tool = %player.tool[%i];
if(%tool == 0)
{
%player.tool[%i] = %item;
%player.weaponCount++;
messageClient(%client,'MsgItemPickup','',%i,%item);
break;
}
}

}
if(%item1 $= %craftItem[0] && %item2 $= %craftItem[1] && %item3 !$= "" && %item3 $= %craftItem[2])
{
echo(%client.name@" - Crafting success!");
%currSlot = %slot[0];
%obj.tool[%currSlot] = 0;
%obj.weaponCount--;
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
serverCmdUnUseTool(%obj.client);

%currSlot = %slot[1];
%obj.tool[%currSlot] = 0;
%obj.weaponCount--;
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
serverCmdUnUseTool(%obj.client);

%currSlot = %slot[2];
%obj.tool[%currSlot] = 0;
%obj.weaponCount--;
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
serverCmdUnUseTool(%obj.client);

for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
{
%tool = %player.tool[%i];
if(%tool == 0)
{
%player.tool[%i] = %iitem;
%player.weaponCount++;
messageClient(%client,'MsgItemPickup','',%i,%item);
break;
}
}
}
}
Also, here's the code for an item to be crafted:
Code: [Select]
datablock ItemData (PaperMacheItem : EBItem)
{
uiName = "Paper Mache";
colorShiftColor = "1 1 1 1";
isContraband = true;
craftingRequirements = "ToiletPaper, SuperGlue";
};

Thanks for helping me, it would really made my Escapists server go up faster!
« Last Edit: July 24, 2015, 03:14:37 PM by EV0_ »

function serverCmdCraftItem (%client, %item, %item1, %item2, %item3)
{
   %player = %client.player; - Might cause issues if you don't check to see if the player exists.
   %item = %item@"Item";
   for(%i = 0; %i < 3; %i++)
   {
      %slot[%i] = %item[%i]; - Where the hell is the %item array defined besides shortly after?
      %item[%i] = %client.player.tool[%item[%i]]; - Why not just use %player. Also, %item[] still doesn't exist yet so you're trying to pull air out of air and it's getting away from you.
      %item[%i] = %item[%i]@"Item"; //Make it so instead of showing up as "ToiletPaper" it'll show up "ToiletPaperItem"; - If you name ToiletPaperItem as such in its datablock name, pulling it out of %player.tool[] would ultimately give you ToiletPaperItem instead of having to do it here. If you already have ToiletPaperItem named as such, this is causing it to be named ToiletPaperItemItem
   }
   %craftReq = %item.craftingRequrements;
   %craftINT = %item.craftingIntRequirement;
   %craftReq = strReplace(%craftReq, ",", ""); //remove commas from Crafting Requirement string.
   %craftItem[0] = getWord(%craftReq, 0);
   %craftItem[1] = getWord(%craftReq, 1);
   %craftItem[2] = getWord(%craftReq, 2);
   if(%craftItem[2] $= "")
   {
      %item3 = "";
   }
   if(%item1 $= %craftItem[0] && %item2 $= %craftItem[1] && %item3 $= "") - Might cause potential issue for the player as they always have to list the items in the specific order you've given
   {
      echo(%client.name@" - Crafting success!");
      %currSlot = %slot[0]; - As defined from above, %slot[] is not filled with integers but rather blank strings.
      %obj.tool[%currSlot] = 0; - %obj doesn't exist, %player does and it seems to be ignored even after being defined at the top.
      %obj.weaponCount--;
      messageClient(%obj.client,'MsgItemPickup','',%currSlot,0); - Why not just use %client.
      serverCmdUnUseTool(%obj.client); - Why not just use %client.
      
      %currSlot = %slot[1]; - As defined from above, %slot[] is not filled with integers but rather blank strings.
      %obj.tool[%currSlot] = 0;
      %obj.weaponCount--;
      messageClient(%obj.client,'MsgItemPickup','',%currSlot,0); - Why not just use %client.
      serverCmdUnUseTool(%obj.client); - Why not just use %client.

      for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
      {
         %tool = %player.tool[%i];
         if(%tool == 0)
         {
            %player.tool[%i] = %item; - Would do %item.getID(); just to be a bit on the safer side and to point out errors that occur here in the console.
            %player.weaponCount++;
            messageClient(%client,'MsgItemPickup','',%i,%item);
            break;
         }
      }

   }
   - This snippet had all the issues above so I cut it out
}

Here are all the glaring issues I could find from just looking through it.
You're code is all over the place in terms in consistency, my guess is that you didn't make it all (Not that it's a bad thing), try to examine other code more closely before trying to repurpose it for yourself.
Lastly, please provide a console.log these things are really useful.
« Last Edit: July 24, 2015, 12:34:57 PM by Alphadin »

"Where the hell is the %item array defined besides shortly after?"
In the arguments, however the first iteration won't work because it isn't named %item0.

"Where the hell is the %item array defined besides shortly after?"
In the arguments, however the first iteration won't work because it isn't named %item0.
Arrays could be used in that way?
Aka a bunch of variables named %word# could be accessed by %word[ # ]?

"Where the hell is the %item array defined besides shortly after?"
In the arguments, however the first iteration won't work because it isn't named %item0.
Nvm fixed it.

Arrays could be used in that way?
Aka a bunch of variables named %word# could be accessed by %word[ # ]?
Not by any logic I can think of at all, so 99% sure no.

Not by any logic I can think of at all, so 99% sure no.
So did Ipquarx make the mistake or did we...

%x = 0;
%word0 = 1;
%word0 == %word[0] == %word[%x]

arrays are actually just variables with a slightly modified name
which makes for some interesting logic and coding

%var[a, b, c, d, ...] ends up being %vara_b_c_d_... and so on

Really? That's really interesting.

arrays are actually just variables with a slightly modified name
which makes for some interesting logic and coding

%var[a, b, c, d, ...] ends up being %vara_b_c_d_... and so on
Yes, I saw Port (I think it was Port?) on a free coding server with restrictions, for example, you couldn't do isAdmin, Pref, etc. and he bypassed that by doing Pre["f"] instead of just Pref.

So did Ipquarx make the mistake or did we...
%x = 0;
%word0 = 1;
%word0 == %word[0] == %word[%x]

-things-
Yeah I saw the post below me, the reiteration was nice but unnecessary :/

This still isn't helping this work.

This still isn't helping this work.
Refer to my post for the issues, or provide a console log if you've already addressed them. And rename the argument %item at the top to %item0
« Last Edit: July 26, 2015, 12:50:21 AM by Alphadin »