Global Variable - Inventory items

Started by Cyberion, Thu 16/09/2004 22:04:19

Previous topic - Next topic

Cyberion

Well, as i'm very very bad at programming, i would ask your help guys.

I want to make the following thing:

whenever player uses any inventory item where he shouldn't it will say to him that he can't use it. Preferable 3-4 random phrases. But whenever the right item is used, it won't display the global message, but will perform the task that is given when this item is used, so can anyone help me with the code?

in other words, player uses the inventory items on a hotspot/object, but it says that it can't be used. Something like the phrase "it won't work". But when he uses the inventory item that is supposed to be used, everything goes as it was coded, without displaying this global message of course :)


I know in general how it can be done, through global variables i guess, but i do not have any idea of how to perform this :(

Scorpiorus

#1
Take a look for a unhandled_event function in the manual. It is function that automates these "can't do" things:

//main global script

function DisplayRandomMessage() {

int randomValue = Random(2);

if (randomValue==0) Display("you can't do that!");
else if (randomValue==1) Display("nah, try something else");
else if (randomValue==2) Display("what are you trying to do?");

}

function unhandled_event (int what, int type) {

Ã,  Ã,  if (what == 1 ) {
Ã,  Ã,  Ã,  Ã,  // Use inventory on hotspot
Ã,  Ã,  Ã,  Ã,  if (type == 3) {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisplayRandomMessage();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }

}

See about what and type parameters to react differently depending on thier values. ;)



EDIT: And if it's about to use the right item you can have:

on use inv on hotspot:

int itemToUse = character[GetPlayerCharacter()].activeinv;

if (itemToUse == ITEM_NUMBER) {
Ã,  Ã,  //do something
}
else {
Ã,  Ã,  int randomValue = Random(2);

Ã,  Ã,  if (randomValue==0) Display("you can't do that!");
Ã,  Ã,  else if (randomValue==1) Display("nah, try something else");
Ã,  Ã,  else if (randomValue==2) Display("what are you trying to do?");

}

Cyberion


SMF spam blocked by CleanTalk