Author Topic: Check if there is X amount of Y, and if so, give the player Z  (Read 1209 times)


Well I don't really want to write out all the code for you. But here's how I would go about it. What I would do is copy the fxDtsBrick::canCookRecipe function and name it something like, fxDtsBrick::cookRecipe and inside the for loop, instead of:

if(%this.ingredient[%ingName] < %ingAmount)
{
   return false;
}


Just simply do %this.ingredient[%ingName] -= %ingAmount; We can do this since the brick has already passed the fxDtsBrick::canCookRecipe check. Then you can get the remaining amount (if any) by simply referencing the variable %this.ingredient[%ingName] inside of that for loop. From there you can determine the extra ingredients that the brick contains and add health based on that to a specified client, or whatever other variables are involved. Tell me if you understand or not :D.

ok i am back
what would i do if i wanted to put in multiple recipe checks without having a too many lines of code?

what's the purpose of this? list all possible recipes+number to make with your current ingredients?

there really isn't any other way than just run every recipe check on the player, but it shouldn't lag up the server too much. you can schedule the checks out if there really is a ton.

Some pseudo code you can look at. I'd write a function and put this inside.. respectively...



//make sure this is defined somewhere..
%brick = brickObject;

//assuming these three recipes were defined..
%rc=-1;
%recipe[%rc++] = "Fruit Salad";
%recipe[%rc++] = "Chocolate Cake";
%recipe[%rc++] = "Banana Bread";
%rc++;

for(%i=0;%i<%rc;%i++)
{
   %recipe = %recipe[%i];
   if(!%brick.canCookRecipe(%recipe))
   {
      //return the function as false..
      return false;
   }
}

//We passed the for loop so we were able to cook all of the recipes..
return true;




If this doesn't help at all, I may actually write out a function for it to show you.