Hey so I have two Items I want the player to have before he can make coffee
function hCoffeMaker_UseInv()
{
if(player.HasInventory(iCoffee) && player.HasInventory(iCcup))
player.Say("Giddyup!");
sBrew.Play();
Wait(150);
player.Say("Oh boy, Coffee's ready!");
sPour.Play();
Wait(150);
player.LoseInventory (iCcup);
player.AddInventory(iCcupfull);
}
problem is if I use either item singularly it also makes the coffee. Want to make it so he has to have both items before he makes it
That's because you did not enclose the codes after if(...) in braces {}, so that only the "Giddyup!" line was affected by the if condition, and the remaining lines would be executed regardless of the conditions.
So:
function hCoffeMaker_UseInv()
{
if(player.HasInventory(iCoffee) && player.HasInventory(iCcup))
{
player.Say("Giddyup!");
sBrew.Play();
Wait(150);
player.Say("Oh boy, Coffee's ready!");
sPour.Play();
Wait(150);
player.LoseInventory (iCcup);
player.AddInventory(iCcupfull);
}
}
Also, right now the player could use any item to make the coffee. If you want them to only make coffee when using either the cup or the coffee on the coffeemaker, then add an extra condition:
function hCoffeMaker_UseInv()
{
if (player.ActiveInventory == iCoffee || player.ActiveInventory == ICcup) // <---
{
if(player.HasInventory(iCoffee) && player.HasInventory(iCcup))
{
player.Say("Giddyup!");
sBrew.Play();
Wait(150);
player.Say("Oh boy, Coffee's ready!");
sPour.Play();
Wait(150);
player.LoseInventory (iCcup);
player.AddInventory(iCcupfull);
}
}
}
thanks!