Hi
I am having trouble inplementing the below code. Its the ActiveInventory that Is giving me problems as any inv can be used. The else statement works as does the distance settings.
When a player comes to close to the main character the main character can knock them out with a knuckleduster (iduster), would also like to have the choice with baseball bat (ibat)...
Can anyone shed some light?
cheers
barefoot
function cHank_UseInv()
{
if (player.ActiveInventory == iduster)
{
}
if ((cHank.x - cEgo.x <=90 && cHank.x >= cEgo.x) || (cEgo.x - cHank.x < 90 && cEgo.x > cHank.x))
{
cHank.Say("Ouch!");
{
cEgo.Say("sorry mate");
Display("He falls down and you drag him off and hide him in the bushes");
Display("You search him and find a knife");
player.AddInventory(iknife);
SetTimer(1,0);
cHank.ChangeRoom(30);
}
}
else
{
Display("That's no good!!");
}
}
The problem is that when the ActiveInventory is set to iduster you're not doing anything:
if (player.ActiveInventory == iduster)
{
}
The next condition does not take the ActiveInventory into account at all and only compares the x co-ordinates of cEgo and cHank. The reason it's not working is because you're never using ActiveInventory to do anything. Ever. At all.
Try nesting the conditions properly:
function cHank_UseInv()
{
if (player.ActiveInventory == iduster || player.ActiveInventory == ibat)
{
// removed closing brace
if ((cHank.x - cEgo.x <=90 && cHank.x >= cEgo.x) || (cEgo.x - cHank.x < 90 && cEgo.x > cHank.x))
{
cHank.Say("Ouch!");
// removed pointless and unneeded opening brace
cEgo.Say("sorry mate");
Display("He falls down and you drag him off and hide him in the bushes");
Display("You search him and find a knife");
player.AddInventory(iknife);
SetTimer(1, 0);
cHank.ChangeRoom(30);
}
}
else
{
// ActiveInventory was NOT iduster or ibat
Display("That's no good!!");
}
}
The code is only going to do what you tell it to. It's not going to do your work for you. In short, bad logic is bad.
Many thanks Monkey
I definately need to keep my eye on my braces.. {} ;)
Yes, need logic...
cheers
barefoot
You should also keep an eye on the brace finger, it seems trigger happy or perhaps just a nervous twitch. ;D
;) YEH