How to pull from lists in Usecode C?

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

How to pull from lists in Usecode C?

Post by agentorangeguy »

Ok I've run into a bit of a snag on Beh Lem's usecode.

In the original, apparently if your party is full of 8 people and you agree to put Beh Lem in your party, one of the non permanent members of the party interjects and says they'll return to the surface to tell everyone of your progress, giving room for Beh Lem to join. I think specifically the code i looked at from U6edit says the # 6 party member but I think just a random non permanent party member will suffice (anyone but Shamino, Iolo, Dupre).

So I figured I needed to

- pull a list of these "non-permanent members" from the party list
- randomly interject one of them to volunteer to leave from this new list

How would I go about doing this? I'm assuming its possible to pull a value from the party list with UI_get_party_list by using indexes like [5], [6], [7]?
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: How to pull from lists in Usecode C?

Post by marzo »

Lets say that you have a list with the numbers of the temporary NPCs in a variable called tempNPCs. You might create a function that gets the list and returns a random temporary NPC that looks like this:

Code: Select all

var getRandomTemporaryPartyNPC(var tempNPCs) {
	// Create an array with all temporary NPCs currently in the party.
	// It starts empty.
	var tempInParty = [];
	// For each NPC in the party...
	for (npc in UI_get_party_list()) {
		// ... if the NPC is in the list of temporary NPCs...
		var num = npc->get_npc_number();
		if (num in tempNPCs) {
			// ... then add it to the temporary array.
			tempInParty << num;
		}
	}
	// Get a random index in the temporary array.
	var random_index = UI_get_random(UI_get_array_size(tempInParty)) - 1;
	// Return the selected temporary NPC.
	return tempInParty[random_index];
}
Then call it to get one such NPC. I think the above should work, but I am a bit rusty in usecode syntax and I haven't tested it.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

Re: How to pull from lists in Usecode C?

Post by agentorangeguy »

Cool thanks! I've only used that kind of thing with python and am a bit rusty on it, but I'll try it out and see if it works!
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Locked