scripting for a shop

Started by justme1212, Sun 07/03/2004 20:00:35

Previous topic - Next topic

justme1212

ok i know how to program basically in ags and can do basic visual basic but im stuck on how to create a shop where the player talks to a npc and pays for an object with money(an inventry item). If some one could give me a small basic code example il be able to work from ther myself.

cheers !

LordHart

#1
Well, you could have it so that you pick up the items, and pay for them if you have enough money. And if you try to leave without paying, then something BAD happends...

I'll do an example...

A nice little store is the setting. The main character, lets call him, EGO. The storeclerk is named STORE, and the item for purchase is MILK, while we have some MONEY.

Setting up the room, you would have the item MILK on a shelf. The door would have a REGION at the floor, so that when you leave, it would run a script checking if you are try to steal the MILK, but I'll get to that later.

So lets set up the Money... you could have it as a simple item in the inventory, such as a Wallet (inventory item 2) like in Sam & Max with unlimited money , which you find in another room.

To buy the milk (lets have it as inventory item 1), lets have it so you need to pick it up, and then talk to the clerk... so here is the part where you pick it up.

Picking up the milk will do this:
Code: ags
SetGlobalInt(69, 1);
AddInventory(1);


Buying the object by talking to the storeclerk:

Code: ags
if((character[EGO].inv[2]) && (character[EGO].inv[1])){
DisplaySpeech(EGO, "May I purchase this?");
DisplaySpeech(STORE, "Sure mate, that'll be $17...");
SetGlobalInt(69, 2);
} 
else if(character[EGO].inv[1]){
DisplaySpeech(EGO, "May I purchase this?");
DisplaySpeech(STORE, "Do you have any money?");
DisplaySpeech(EGO, "No.");
DisplaySpeech(STORE, "The hell no... come back when you have some money.");
LoseInventory(1);
}
else if(character[EGO].inv[2]){
DisplaySpeech(EGO, "May I purchase this?");
DisplaySpeech(STORE, "Unless you want to pay for your own wallet, I suggest you get something off of the shelf.");
}
else {
DisplaySpeech(EGO, "May I purchase this? I don't have any money on me, so I'll give you an IOU...");
DisplaySpeech(EGO, "An IOU for nuthin'? You weren't dropped as a baby were you?");
}


Now, setting up the part where you walk out and something bad happens... or doesn't happen.

When you WalkOntoRegion, have the following in a script:

Code: ags
if(GetGlobalScript(69) == 1) {
BAD THINGY HAPPENS HERE, COULD BE ANIMATION OF A DEATH SEQUENCE OR SOMETHING...
}
else if(GetGlobalScript(69) == 2) {
DisplaySpeech(STORE, "Thank you for your money, please come again...");
NewRoom(WHATEVER);
}
else {
DisplaySpeech(STORE, "Thanks alot you cheap bastard!");
NewRoom(WHATEVER);
}


Hopefully that helped a bit. Yeah, it's not really a small example... more like the whole thing I suppose. Anyway, you can change a few things here and there, but thats basically it.

-- OsUltimo

SMF spam blocked by CleanTalk