Page 2 of 2

Re: My usecode questions

Posted: Tue May 11, 2010 1:40 am
by Crowley
Ah, I didn't think of eggs. "Something on" and "once-only" parameters should work for my purposes. I think.

Re: My usecode questions

Posted: Thu Nov 10, 2011 3:03 pm
by Crowley
Time to dust this thread off again... I've been trying to implement Chaos Sword's functionality by giving its wielder charmed status. I would prefer to do this when combat mode is entered, but that seems to be beyond my abilities currently. So I settled for trying to make the wielder charmed when attacking with the weapon. Here's the code I have:

Code: Select all

void ChaosSword shape#(0x403) ()
{
	if (event == WEAPON)
	{
		var wielder = UI_get_container(ChaosSword);
		wielder->set_item_flag(CHARMED);
		UI_set_attack_mode(wielder, 0);
		return;
	}
}
However, the charmed status does not occur. I tried testing this with just event == READIED also, but that also failed.

Re: My usecode questions

Posted: Thu Nov 10, 2011 3:37 pm
by Crowley
Also, how do I make cursor flash "blocked"?

Re: My usecode questions

Posted: Tue May 29, 2012 4:47 pm
by Crowley
I would still appreciate input to my last couple of questions.

In the meantime, I had the thought of linking using the spellbook to replenishing the contents of the cornucopia. I put together the following code, which... doesn't work.

Code: Select all

void SpellBook shape#(0x2f9) ()
{
	if (event == DOUBLECLICK)
	{
		var HornOfPlenty = UI_find_object(PARTY,0x402,QUALITY_ANY,FRAME_ANY);
		HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,FRAME_ANY);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,0);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,1);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,2);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,3);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,4);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,5);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,6);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,7);
		SpellBook.original();
	}
}

Re: My usecode questions

Posted: Tue May 29, 2012 5:35 pm
by Wizardry Dragon
When you say it doesn't work, does it just not do anything, or does it malfunction, or..?

Cheers,
Wizardry Dragon

Re: My usecode questions

Posted: Tue May 29, 2012 7:39 pm
by marzo
By default, the spellbook does not call usecode; it instead shows a gump. So it not working is expected :-)

Re: My usecode questions

Posted: Tue May 29, 2012 10:24 pm
by Crowley
Oh yes, I had already learned that opening the gump causes the game to ignore usecode associated with the double click. Just didn't make that connection here. Silly me.

Re: My usecode questions

Posted: Wed May 30, 2012 3:56 pm
by Crowley
I did some testing with how containers work. Take all the reagents, put them into a chest and then change the chest's shape to the locked chest. Stick the chest into the Avatar's hand and try casting a spell. Result: The game does not allow using the reagents inside a locked chest you are carrying.

Next test: Uncheck the "locked" quality from a locked chest. Now the reagents can be used when the chest is in the Avatar's inventory, even though you still cannot actually open the chest. Thus in order to get the functionality I want out of the cornucopia, I should make it a container which has no gump but which is not locked either.

Now, on to the actual code issue. I tried attaching the above code to add reagents into the cornucopia to double-clicking it. Like this:

Code: Select all

void HornOfPlenty shape#(0x402) ()
{
	if (event == DOUBLECLICK)
	{	
		HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,FRAME_ANY);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,0);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,1);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,2);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,3);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,4);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,5);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,6);
		HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,7);
	}
}
I also tried disabling the remove_cont_items part, but that didn't change anything. Speaking of which, what happens if you use that function and tell it to remove more items from a container than it has?

Also, I would still like help with my above Sword of Chaos code and how to make the cursor flash the "blocked" message.

Re: My usecode questions

Posted: Wed May 30, 2012 7:45 pm
by Wizardry Dragon
The usecode will fail if the container does not have the item. However if the container selected has containers within it, it should also check those subcontainers. Ie if you tell it to remove something from a pack that has a pouch in it, unless the behaviours change in the past year, it should also check the pouch.

Cheers,
Wizardry Dragon

Re: My usecode questions

Posted: Thu May 31, 2012 8:55 am
by agentorangeguy
Crowley, look up the thread where I asked about the storm cloak code. I believe that might help you with your chaos sword, like finding the outside container to give themt he attributes of it. the cursor flashing i remember seeing somewhere in the intrinsics or one of the files... i'll check on that when i get home from work.

Re: My usecode questions

Posted: Thu May 31, 2012 2:48 pm
by Crowley
Thanks for pointing that out. It worked much better when I used this to denote the wielder:

var wearer = getOuterContainer(item);

Unfortunately, that got me to notice that unlike every other party member, a charmed Avatar will not fight the rest of the party. Dang.

Re: My usecode questions

Posted: Thu May 31, 2012 3:21 pm
by Crowley
Also, the cornucopia replenishing code worked once I changed HornOfPlenty->add_cont_items to item->add_cont_items. Regarding the remove_cont_items function, it seems to be that if I tell the game to remove 10 items of a type from a container and it has less, it will still remove all of that type from the container.

Re: My usecode questions

Posted: Thu May 31, 2012 3:59 pm
by Dominus
Avatars charmed behaviour is the same as in the original. Users can change this by using the "hard" charmed option in thein game menu.

Re: My usecode questions

Posted: Thu May 31, 2012 8:08 pm
by Crowley
Well, I have found a solution to at least one of my problems. While I could not attach refilling the cornucopia to opening spellbook in itself, I can attach it to individual spells. It's fairly simple, just time-consuming since I need to do it separately for all 64 spells which require reagents. For example, cure poison:

Code: Select all

void CurePoison object#(0x649) ()
{
	var HornOfPlenty = UI_find_object(PARTY,0x402,QUALITY_ANY,FRAME_ANY);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,0);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,1);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,2);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,3);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,4);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,5);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,6);
	HornOfPlenty->remove_cont_items(10,0x34a,QUALITY_ANY,7);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,0);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,1);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,2);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,3);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,4);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,5);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,6);
	HornOfPlenty->add_cont_items(10,0x34a,QUALITY_ANY,7);
	CurePoison.original();
}

Re: My usecode questions

Posted: Fri Jun 01, 2012 1:03 am
by Wizardry Dragon
This could be alleviated somewhat by the idea I floated some years ago about having different action "hooks" available, ie in this case one for 'casts spell'.

As far as UCC goes we've come a HUGE way from when I started obstensibly hacking stuff for the project that would become TFL, but there's still a lot of ways we could improve.

Cheers,
Peter M Dodge
aka Wizardry Dragon

Re: My usecode questions

Posted: Fri Jun 01, 2012 2:01 pm
by agentorangeguy
Crowley, I found this in the bg_externals.uc file on the flashing cursor you've been asking about: extern flashBlocked 0x8FD(var cursor);

I guess you could probably just put: flashBlocked(var cursor); and probably just the number of the 'x' cursor in it or something.

Re: My usecode questions

Posted: Fri Jun 01, 2012 7:12 pm
by Crowley
I noticed that each spell function runs through function 0x906 (if I remember the number right), which appears to check whether the current weather condition is the anti-magic mist. I did consider linking the cornucopia refill to that as a shortcut, but at least my initial attempt did not work.

Thanks for the information, agenrorangeguy. Marzo's site lists all other cursor flashes except the "blocked" one.

Now, I shall have to take a look at the usecode to see if toggling the combat status is a specific function, so I might link the Chaos Sword to that...

Re: My usecode questions

Posted: Fri Jun 01, 2012 9:04 pm
by Crowley
This is a bit odd. I tried searching for the war cries your party makes in combat, but those are nowhere to be found in the decompiled Ultima VII usecode. I tried searching for any functions which contain setting a character's schedule to combat, but those did not help either.

In other news, trying to add to function 0x906 brings up the following error message while compiling:

Function 0x906 already used for 'inMagicStorm' with 0 params.

Is there any way to attach usecode to functions which are already in use by Exult like that?

Re: My usecode questions

Posted: Sat Jun 02, 2012 12:51 pm
by Wizardry Dragon
The combat AI is hardcoded, including battlecries, IIRC. I was looking into this at one point to give gargoyles gargish battlecries but couldn't make any headway as a result.

You can redefine the function, do your stuff, and then do originalFunction.original() to add new content. One caveat: you have to do your stuff first, the caller will also be dropped when the original return()s.

(Unless that behaviour's been changed, I haven't touched UCC in a bit)

Cheers,
Peter M Dodge
aka Wizardry Dragon

Re: My usecode questions

Posted: Sat Jun 02, 2012 3:30 pm
by Crowley
I guess I'll wait and hope that those action hooks will some day allow me to have custom usecode triggered by toggling combat. My plan was to have the wielder of the Chaos Sword charmed when combat mode switches on, and pass out when it's switched off. Admittedly it's (at least currently) a lot of work for such a useless item.

I believe I tried redefining the function exactly as you explain, but still got the error message. Like this:

Code: Select all

void AntiMagic object#(0x906) ()
{
	
	AntiMagic.original();
}
Doing something like that appears to conflict with this line in bg_externals.uc:

extern var inMagicStorm 0x906();

Finally, I tried applying flashBlocked(var cursor); but didn't manage to do anything more with it than as an alternative to UI_flash_mouse(int cursor). I have no idea how the get the "blocked" message out of that.

Re: My usecode questions

Posted: Sat Jun 02, 2012 4:10 pm
by Wizardry Dragon
Yes, when you declare an extern, the way that UC does this, assume it's basically like a php require() statement where it attempts to import the code of the named function wholesale. So essentially you have two definitions of the same function twice in your code, by having both that and your own.

Cheers,
Peter M Dodge
aka Wizardry Dragon

Re: My usecode questions

Posted: Sat Jun 02, 2012 5:04 pm
by Crowley
Sorry for being thick, but I still do not understand how to go about in practice solving this conflict of having two definitions for the same function.

Re: My usecode questions

Posted: Sat Jun 02, 2012 5:13 pm
by Wizardry Dragon
It's fine :) As to a fix, try commenting out the extern reference and see if your other function works.

Cheers,
Peter M Dodge
aka Wizardry Dragon

Re: My usecode questions

Posted: Sat Jun 02, 2012 9:48 pm
by Crowley
I just found the part of Exult Studio which lists usecode entries, and it shows CombatToggle as 0x6AC. However, attaching my usecode to that does not seem to do anything when the party does combat. Maybe that's for when NPCs enter combat mode or something.

Re: My usecode questions

Posted: Sat Jun 02, 2012 10:49 pm
by Wizardry Dragon
What are you trying to do exactly, re: that? There might be a workaround.

Cheers,
Peter M Dodge
aka Wizardry Dragon

Re: My usecode questions

Posted: Sun Jun 03, 2012 12:53 am
by Crowley
I was hoping to have it work like this: When combat begins, the wielder of the Chaos Sword is charmed. When combat ends, the wielder falls down asleep. That seems like a close enough adaptation of how the sword functioned in Ultima V.

Re: My usecode questions

Posted: Sun Jun 03, 2012 12:59 am
by Wizardry Dragon
Hmm. I THINK the combat toggle code is hardcoded into the engine, which is why the usecode isnt really doing much. A workaround might be to attach usecode to the avatar/party members to check if it's equipped on occassion. That would involve a lot of overhead however. I'm not sure, other than that. Marzo may have a better solution.

Cheers,
Peter M Dodge
aka Wizardry Dragon

Re: My usecode questions

Posted: Sun Jun 03, 2012 1:38 pm
by Crowley
I did consider implementing this by a constantly running code which holds two variables, and runs something like this at each tick:

Variable 2 = Variable 1.
Variable 1 = current schedule of the wielder.
If Variable 1 is "in combat" and Variable 2 is "follow Avatar", then set the wielder to charmed. If vice versa, put the wielder to sleep.

Having that running all the time seems excessive. I guess I could attach it to begin and end on READIED and UNREADIED events with the sword.

Re: My usecode questions

Posted: Wed Jun 20, 2012 1:53 am
by Crowley
I got to thinking of disabling the backpack slot for Beh Lem by way of an invisible and immovable item. First, how do you get an item to disappear from the inventory of a character upon death like the NPC spell items do?

Re: My usecode questions

Posted: Wed Jun 20, 2012 11:20 am
by Malignant Manor
Could add the following event to the character's usecode.

if (event == DEATH)

Then add removal code. You would then need scripting to restore the item upon resurrection though and resurrection is done through various functions.

Fatal: Not able to open ./cache/production/data_global.php