sellItems function

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

sellItems function

Post by agentorangeguy »

I was playing around with this "sellItems" function that was in either the keyring / TFL mod or maybe both.

Code: Select all

void sellItems (var options, var shapes, var frames, var price, var quantity, var articles, var quantity_text, var quantity_tokens, var dialog)
{
	var choice_index;
	var msg;
	var sell_result;
	var total_price;
	var isplural;
	
	//Present the options to the player:
	choice_index = chooseFromMenu2(options);
	
	//Keep doing this until the player choses not to buy anything else:
	while (!(choice_index==1))
	{
		total_price = price[choice_index] * quantity[choice_index];
		
		if (quantity[choice_index] > 1)
			isplural = true;
		else
			isplural = false;
			
		//Inform price to player:
		say("@^",
			makeSellPriceString(articles[choice_index], options[choice_index],
						isplural, price[choice_index],
						quantity_text[choice_index]),
			dialog[1]);

		//See if player agrees with price:
		if (askYesNo())
		{
			//Ask for quantity:
			say(dialog[2], quantity_tokens[choice_index], dialog[3]);
			
			//Sell everything to the party:
			sell_result = sellAmountToParty(shapes[choice_index], frames[choice_index], quantity[choice_index], price[choice_index], 32, 1, true);
			
			if (sell_result == 1)
				msg = dialog[4]; //can't carry?
			else if (sell_result == 2) 
				msg = dialog[5];
			else if (sell_result == 3)
				msg = dialog[6];
			else
				msg = dialog[7]; //not agreeable - answered no?
			
			//Inform the player if the buy was successful:
			say(msg);
		}
		
		else
			say(dialog[8]);
		
		//Present the menu again:
		choice_index = chooseFromMenu2(options);
	}
	
	say(dialog[9]);
}
I couldn't quite find out what some of these variables mean. Specifically, what do the "var articles" and "var quantity_tokens" mean and how are they used? I couldn't find any examples but maybe I was looking in the wrong place.

Also, the return dialog[0] thru dialog[9] in this function, could someone explain when each of those dialog lines are triggered? I found some of them I believe, like "not enough gold" or "not enough room" lines, but some of them I couldn't figure out where they show up. Let me know and if there are good examples of this function being used, I think it would clean up a lot of code , thanks!
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: sellItems function

Post by Dominus »

As Marzo and KnightCaptain didn't step up, I took a look at the BG Keyring code.

Look at https://github.com/exult/exult/blob/mas ... og.uc#L105
and
https://github.com/exult/exult/blob/mas ... log.uc#L29

I think this clears it up, you add all those variables yourself in the NPC code.

I have no idea what the Quantity Tokens are but if you play around with that you might get an idea.
--
Read the documentation and the FAQ! There is no excuse for not reading them! RTFM
Read the Rules!
We do not support Piracy/Abandonware/Warez!
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

Re: sellItems function

Post by agentorangeguy »

Thanks! I knew there was something like this somewhere I just couldn't remember which file it was or where to look. I was also trying to make a function to sell spells in a streamlined way like this but had no luck.
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: sellItems function

Post by Dominus »

Yeah, no luck in getting a good example of selling spells :(
--
Read the documentation and the FAQ! There is no excuse for not reading them! RTFM
Read the Rules!
We do not support Piracy/Abandonware/Warez!
Locked