Usecode 'events' functionality

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
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Usecode 'events' functionality

Post by Wizardry Dragon »

As mentioned in Crowley's usecode thread, I think I will make a patch for Exult that will enable the allowance for "events" in usecode.

What I'd like to ask of you is what events in the engine you think would be helpful to be able to trigger usecode on.

Once I have a better idea what people want for that, I'll take a look at the Exult code and see what I can and can't do.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Crowley
Posts: 459
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Crowley »

As I mentioned, being able to reference toggle_combat would help my project greatly. Looking through the key bindings, including "useitem " would at least streamline things (specifically it occurred to me that I could tie refilling the cornucopia to opening the spellbook).
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Its probably conceivable to run usecode for any of the keybindings and possible keybindings, but I'm unsure how feasible it would be, ie. if it would slow the engine down by any appreciable degree. Do any others stand out as helpful?

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Dominus »

It's probably one of thsoe times that when you ask about it nothing comes to anyone's mind. Only later will they remember what other uses they thought of :)
(like being in the supermarket, trying hard to think of what else you need to buy - to only remember the most important thing when you return home)
--
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!
Crowley
Posts: 459
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Crowley »

It might help a layman like me to explain a bit what exactly events are, and perhaps give a short list of examples.
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

I could conceivably add usecode hooks to any point in the game where something happens in the Exult code, in the game meaning not in the main menu. There are some points where this would obviously be determental, and if there were too many such hooks it could hamper the interpreter on slower systems, so the reason I'm asking here is to get a list of what we want so that I can prioritize what things I'll add.

In this context I'm thinking of events as in "player clicks on item x" "time of day becomes y" sort of things.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Crowley
Posts: 459
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Crowley »

Those sound like reasonable and useful things. You could have something like the bellringer in U6 announcing hours or roosters crowing at six in the morning for ambiance.
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Okay, here's what I have in my head that I want to ad to or change with UCC:

- Event functions for time of day
- Event functions for click, doubleclick, and schedule changes.
- Support for modules similar to that of Python.
- Builtin functions to determine the existance of BG and SI.
- Builtin functions to manipulate the shape and flex files.

Hopefully I'll be able to do all of this :)

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Scythifuge
Posts: 384
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Scythifuge »

I'm not sure if these are within the scope of what you are doing, due to my lack of knowledge of programming and scripting, but:

-Have checks for portraits to determine time of day and npc location, and then display different portrait frames accordingly (like in the original S.E.)

-Checks or hacks to allow more than 32 npc/pc frames. I have objects that work in E.S. in-game that have up to 90+animation frames, such as flickering torches. At the very least, a check to change shape when certain weapons are equipped, to create new frames for ranged weapons rather than have them be swung. Having characters able to sit on the ground ,indian style, or other ways would be very helpful (for mats and rafts, horse riding, etc.).

-Changes to sleeping so that one party member stands watch, while a fire is built and the other party members camp as well, like in earlier Ultimas. I have frames for logs stacking and the fire starting (W.I.P.)

I'm sure other things will come to mind over time.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by marzo »

Have checks for portraits to determine time of day and npc location
That is easily done in usecode.
Checks or hacks to allow more than 32 npc/pc frames.
That would probably be more work than is worth: the bit corresponding to 32 is used for 'rotation' flag (north to west, south to east), which would need to be reworked (current shapes with more than 32 frames do not rotate this way).
At the very least, a check to change shape when certain weapons are equipped, to create new frames for ranged weapons rather than have them be swung.
That can be done with usecode: by ticking the 'usecode events' flag, the weapon will raise usecode events when equipped/unequipped which could set new shapes for the characters in question. Setting adequate weapon-in-hand offsets, and having specially designed frames for the weapons would give the result you want. It would involve a lot of data duplication, though.
Changes to sleeping so that one party member stands watch
That can be done through usecode.
------
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]
Scythifuge
Posts: 384
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Scythifuge »

Quote:

That is easily done in usecode.

Excellent! When the time comes to create character portraits, I'll create multiple frames with different backgrounds for each character:

-Rainforest portrait (day & night)
-Village portrait (day & night)
-cave portrait

Quote:

That would probably be more work than is worth: the bit corresponding to 32 is used for 'rotation' flag (north to west, south to east), which would need to be reworked (current shapes with more than 32 frames do not rotate this way).

The dilemma is the lack of chairs for certain cultures. The Nahuatla use woven mats, except for the Emperor, who has a throne. The Nahuatla market place was to have merchants kneeling on both knees in front of mats with their goods on them. Perhaps when a mat is double-clicked, the npc/pc could change shape to kneeling, returning to normal shape upon walking away? Plus, I'm not sure how to do the raft. A deed is unrealistic unless an oar acts as a deed, and there would be no chairs on the raft.

Quote:
That can be done with usecode: by ticking the 'usecode events' flag, the weapon will raise usecode events when equipped/unequipped which could set new shapes for the characters in question. Setting adequate weapon-in-hand offsets, and having specially designed frames for the weapons would give the result you want. It would involve a lot of data duplication, though.

I can redraw ranged weapon frames at some point. This option is also good for limited "paperdolling" in-game, such as a hat or backpack. The Avatar could have multiple shapes to depict the wearing or use of various items. Could be a lot of work, but make for a more atmospheric game.

Quote:
That can be done through usecode.

That is good news! I will finish the camp fire when I get back to drawing for Eodon. There should probbaly be checks to make sure all party members have a bedroll in their inventory.


I really like this thinking outside the box with regards to E.S.!!!
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Dominus »

Plus, I'm not sure how to do the raft. A deed is unrealistic unless an oar acts as a deed, and there would be no chairs on the raft.
I really need to play SI again to say this for real, but somehow this was doable for the iceraft, so it should work for you as well.
The deed is probably not needed, just a usecode flag, once something happens in your game that sets this flag, your raft is free to use
--
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!
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Just make the shape check a usecode flag when clicked on. It's what they do for the ice barge.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Kensu

Re: Usecode 'events' functionality

Post by Kensu »

Perhaps finer granularity than time of day: how about on_hour? (onHour, do you guys use camelcase? Oddly enough, I'm never actually looked at the Exult code, though I did give the Avatar Adventures a once-over to see how UU stored its dungeon information)
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Conceivably I could add functions for every hour/minute/etc but this exacting sort of time events would best be handled by a daemon process and not events.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by marzo »

Now that I read paying some attention:
- Event functions for time of day
For all such cases (hour, minutes, ticks) you are better off using standard script blocks on a delay to call back the function -- i.e.,

Code: Select all

script AVATAR after 10 ticks { nohalt; call myFunction; }
Anything else would be duplicate functionality for little to no gain: an usecode wrapper for this is exceedingly easy to make.
- Event functions for click, doubleclick, and schedule changes.
Except for schedule changes... you can check the event and re-rout the call. If you really want to make click and double-click separate, I think that changes in UCC might be better suited to this task -- it could be made to generate the code for the re-routing automatically. Although even this could be wrapped in an usecode function...
- Support for modules similar to that of Python.
Could you elaborate? Maybe UCC can already do this, but I don't know enough about Python to be sure.
- Builtin functions to determine the existance of BG and SI.
You mean to check, from usecode, if BG and/or SI is installed to ensure copyright compliance or something? It is possible, and not that hard.
- Builtin functions to manipulate the shape and flex files.
From usecode? That is probably better not done... it would be far to easy to wreak havoc with this from usecode.
------
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]
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

"From usecode? That is probably better not done... it would be far to easy to wreak havoc with this from usecode."


It would be, but it's really up to programmers to write safe code. I'm thinking of doing it on the fly specifically to allow/deny certain content to people who do or don't have SI installed.


"Could you elaborate? Maybe UCC can already do this, but I don't know enough about Python to be sure."


If it does I'm unaware of the functionality. Every file in python gets divided into a module. Each module has private and public functions. Some are predefined and others aren't.

An example:

We have a file, money.uc. This makes a module "money". It might have a component class "currency" and then we could go:

filari = money.currency()
monetari = money.currency()

We could also have some helper functions, such as get_party_gold(). We could then access them through the module:

party_gold = money.get_party_gold()

In python you could then use the import keyword in a few different ways:

import money

would import all the public classes and functions of the money module for example.

In python we can use the from keyword to import only select keywords:

from money import get_party_gold

which would just import the get_party_gold function into the current script's scope.

We can even rename them if we have conflicts, again with the from keyword:

from money import get_party_gold as UI_get_party_gold

This would import the get_party_gold function, but with the name UI_get_party_gold.

It's something that's not strictly neccesary, but I find it helpful when it comes to organising the code - it also helps manage memory which isn't an issue on pcs, I suppose, but it would make the code a little easier on the phones and pocket PCs we see people porting to lately.

For me, when I see all the builtin function with UI_whatever, and I think it would be fairly helpful to organise them a little, ie, random.get_die_roll face.display face.hide and so on.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by agentorangeguy »

More than one NPC set of schedules... I remember seeing the U6 editor that someone made where you could edit NPC schedules by the day. For example, with the U6 gypsies, day one they would be in Britain, then I believe on the third day, they would be in Yew, then day six they would be in Paws, etc. You could edit what their shedule types would be on certain days.

It would be really cool to have NPC schedules editable by the day, so you could create stuff like shopkeepers availiable only on certain days, or the travelling NPC's, and NPCs who may appear in a town or shop on a certain day, but not others.
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Scythifuge
Posts: 384
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Scythifuge »

Quote:
I really need to play SI again to say this for real, but somehow this was doable for the iceraft, so it should work for you as well.
The deed is probably not needed, just a usecode flag, once something happens in your game that sets this flag, your raft is free to use

Quote:
Just make the shape check a usecode flag when clicked on. It's what they do for the ice barge.


I completely forgot about the ice raft. It has been years since I played S.I. Thanks guys! I will have to find my old raft and tweak it up. I also forgot that the magic carpet doesn't need a deed. Maybe a hot air balloon isn't out of the realm of possibility...



Quote:
It would be really cool to have NPC schedules editable by the day, so you could create stuff like shopkeepers availiable only on certain days, or the travelling NPC's, and NPCs who may appear in a town or shop on a certain day, but not others.


Traveling NPC's would be great! In fact, the S.E.T.C. will require this, as Dokray and Shamuru do travel between villages in the original. The expanded story requires neutral natives to smuggle certain goods between warring tribes. It also "forces" traveling and exploration if you need that npc, but they aren't where you expect them to be.

I truly hope to make sense of UCC someday. I think that I could, given enough examples, help, and resources.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by marzo »

Every file in python gets divided into a module.[...]
Ah, so the answer would be 'no, UCC doesn't have it'.
It would be really cool to have NPC schedules editable by the day
U7 data does not support this, it only supports a single daily schedule. But an usecode function can be used to switch schedules every day. Travelling NPCs, likewise, can be done through usecode, but will require sprinkling eggs here and there to make sure.
I truly hope to make sense of UCC someday. I think that I could, given enough examples, help, and resources.
The entire usecode and other data for Keyring and SI Fixes mods are available with the Exult source, and have a decent number of comments. Likewise, TFL usecode is also available. And there is the Exult intrinsic reference in my website, as well as some information on script blocks and commands.
------
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]
Scythifuge
Posts: 384
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Scythifuge »

Quote:
The entire usecode and other data for Keyring and SI Fixes mods are available with the Exult source, and have a decent number of comments. Likewise, TFL usecode is also available. And there is the Exult intrinsic reference in my website, as well as some information on script blocks and commands.

I don't know how to view the source, or how to add usecode to stuff while using E.S. I'm a total newb. Though, I do look at code whenever it is posted on the phorum.
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Go to the TFL sorceforge page and use the Web cvs viewer ther.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Scythifuge
Posts: 384
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Scythifuge »

I will Wizardry Dragon. Many thanks! Are there any basic tutorials out there? For example, "to create a conversation tree that sets flags, follow these steps..." I used tutorials like that when messing with Morrowind, such as creating a script that made deer run away from the player when the player got too close.
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Ucc.doc has some good basic information though it is a bit dated - I wrote it when UCC first was developed!

Wizardry Dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

The ucc docs I mentioned, by the way, are here:

http://u7feudallands.cvs.sourceforge.ne ... vision=1.5

Man, I first wrote that in 2004. How time flies...

The root directory for usecode source in the web viewer is http://u7feudallands.cvs.sourceforge.ne ... s/tfl/src/

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Crowley
Posts: 459
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Crowley »

Sorry to be digging up an earlier post a bit.
Now that I read paying some attention:
- Event functions for time of day
For all such cases (hour, minutes, ticks) you are better off using standard script blocks on a delay to call back the function -- i.e.,

script AVATAR after 10 ticks { nohalt; call myFunction; }


Anything else would be duplicate functionality for little to no gain: an usecode wrapper for this is exceedingly easy to make.
Maybe I understood this functionality wrong, but from what I can see, the standard delay causes things to happen after a certain amount of time has passed from starting the script, whereas the proposed function would cause stuff to happen at a certain time of day, and not in relation to anything else. I do not quite understand how that could be set up using delay, since that would be relative to the point in time the script is started.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by marzo »

You delay it by exactly the amount of time needed for the script to happen at the time of day you want. For example:

Code: Select all

/*
 *	Sets a function to be called at the given hour:minute.
 *	If the current time is after the given time, the function
 *	will be called a day later.
 *	If you want to absolutely ensure that the function gets called,
 *	the object supplied should be the avatar; otherwise, the object
 *	or NPC in question may be deleted or set to dormancy (respectivelly)
 *	if the avatar gets far enough away.
 */
void scheduleFunction (var obj, var function, var hour, var minute)
{
	// Validate input:
	if (hour  23)
		hour = 23;
	if (minute  59)
		minute = 59;

	// Get current time:
	var ch = UI_game_hour();
	var cm = UI_game_minute();

	// Determine delay:
	var deltah = hour - ch;
	var deltam = minute - cm;
	// We need to wait a negative number of minutes:
	if (deltam < 0)
	{
		// Wait another 60 minutes, but reduce the number
		// of hours to wait by 1:
		deltam += 60;
		deltah -= 1;
	}
	// We need to wait a negative number of hours:
	if (deltah < 0)
		deltah += 24;		// Add a whole day.
		
	// Schedule the function:
	script obj
	{
		nohalt;
		wait deltah hours;
		wait deltam minutes;
		call function;
	}
}
------
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]
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Out of curiosity, will delayed actions for "dormant" NPCs recur at a later time or are they simply discarded?

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by marzo »

They are discarded. If the script has a 'finish' command, though, it will execute all remeining commands instantaneously instead of finishing.
------
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]
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Hrm. It would be nice to have surviving NPC scripts without having to tack them all onto the Avatar.

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Wizardry Dragon »

Not directly related to the events, but as regards the module functions I mentioned before, I put down my thoughts in that regards in the TFL fora for those interested:

http://www.thefeudallands.ca/fora/topic.php?id=5#post-5

Wizardry dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Donfrow »

Would it be possible to create an event for when a NPC is attacked in combat? So on top of having an event for double clicking when not in combat, have an event for double clicking when in combat.

Would something like this mess up the the way combat works if that event wasn't present in each NPC's usecode?
Crowley
Posts: 459
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by Crowley »

IN MANI CORP!

Has there been progress with this? I got around to dusting off my Exult modding projects, and as stated earlier, this stuff would help with that.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode 'events' functionality

Post by marzo »

Nope, no progress.
------
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]
Locked