Usecode on weapons

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
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Usecode on weapons

Post by Donfrow »

I've noticed that on weapons there is an option to apply usecode to it. Does anyone have any information about how this works? is it used when the weapon swings/fires, equipped, etc?

The reason I'm asking is I would like to have random weapon hits perform an additional function. For example, for every sword swing there is a 1/10 chance to deal an additional X amount of damage based on the stat like the dex or str of the wielder.

If this code is used per swing would it be as straight forward as generating a random number in the usecode, then if that random number is met, get the target of the weapons wielder?

If so, how would one go about getting the NPC target? The closest intrinsic I can see that may work for this is UI_get_oppressor which describes part of it as "It is also set whenever an NPC acquires a new target -- this NPC will be set as its target's oppressor." Would this even work if it's the Avatar?

Thanks
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Dominus »

I know nothing, but I guess the black sword has usecode on it.
--
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!
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

Good idea with the black sword, though looking at it in the editor it doesn't seem to use Usecode option on the weapon tab.
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Dominus »

Huh... I can't think of another one, right now. Did you check both games?
I'll try and get Marzo's opi ion, next time I catch him on irc
--
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!
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

I did now! I checked a few weapons, hoe of destruction, death scythe, poison dagger and magebane.

Though, when I decided to try and test it, it seems that setting it to a usecode doesn't save it to anything. If I change it to a usecode and set it to anything, apply and exit the shape it returns the usecode to 0x0, so maybe this doesn't do anything.

I also tried if event == 4, which from the old copy of events values (taken from keyring mod I think?) indicates it being "Object was wielded and 'swung' in combat" but alas, it seems to do nothing as well.

void weaponTest shape#(1493)()
{
if(event == 4)
{
AVATAR.say("PEW PEW");
}
else
{
AVATAR.say("I am non-weapon event.");
}
}

It did give a hint of possible weapons that would help this though, the smoke bombs and fishing rod. Now to figure out how to see the original usecode for those objects, like KC has been doing.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

Found an UC export KC had sent me awhile ago, it does seem to use these event == WEAPON statements to do things for things like the fishing rod, hitting Draygan with the sleep arrow and Rudyom's wand but I must be missing something as I can't seem to get event == WEAPON to ever trigger.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

I have some code I can reference when I'm home.

From https://github.com/exult/exult/blob/mas ... nstants.uc :

Code: Select all

WEAPON	= 4,	// Object was wielded and 'swung' in combat
			// This is mainly used with 'weapon-like' objects
			// - e.g. smokebombs and fishing rods - that have more
			// advanced 'attack' behaviour.
So you'd have a weapon_name.use file with:

Code: Select all

if (event == WEAPON)
With your actions.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

Check the shape type in ES, it may only work (and respect the Usecode check box) if that shape type setting is correct. Quality vs. Quality Flags does different things elsewhere, for example.

Are you using the same function number as the shape number? Or setting that manually via ES?

(Sorry for the cross-posting above. Busy at work.)
Gotcha!
Posts: 354
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Gotcha! »

Aside from the Black Sword, I guess the Magebane and Glass Sword could be examples too?
Gotcha!
Posts: 354
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Gotcha! »

Kinda funny how I just now realize how mundane 99% of the game's weapons are.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

I think that snippet you posted KC is the same thing that I ended up finding in one of the other mods, which is how I found the event == WEAPON, and the event value of 4.

My function number is the same as the shape number. In my tests my "else" statement is being matched when readied, unreadied and double clicking so I know the usecode for the shape is being triggered, except for the WEAPON event.

I also tried changing it so ELSE would trigger:

void weaponTest shape#(1493)()
{
if(event == DOUBLECLICK)
{
AVATAR.say("PEW PEW");
}
else
{
UI_close_gumps();
AVATAR.say("Everything else!");
}
}

But in combat the "Everything else!" is never triggered. So I'm a bit confused as to what event == WEAPON actually does, given the description of it.

I've tried it with both quality and quality flags on the shape, and usecode events is checked off.

It seems all of the weapons I've been looking at that have special properties, like Magebane, glass sword, etc, use check boxes in Exult Studio for their special properties. Guessing those check boxes are hard coded to execute particular usecode.

The lack of weapon diversity is what I'm looking to expand; I'm hoping to add bane weapons, weapons that are better vs certain creatures, weapons that deal random direct damage based on stats, etc, to add a bit of flavour to the game.
Gotcha!
Posts: 354
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Gotcha! »

I hope you'll succeed!
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

Put that code in [ code] blocks to keep the indentation.

I don't use the NPC.say("string") format so I'm not sure what it does. But I typically only use say in Conversation blocks.

I'd suggest using the UI_error_message to log the output directly.

Code: Select all

UI_error_message("Using weapon_name as a weapon.")
It accepts variables as well if you escape them in the string.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

The sleep arrows in SI should also be an example of this, but I am not looking at the code at the moment.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

Thanks for the info about the [ code ].

The AVATAR.say I'm using just shows the Avatar's face and says something. I'm only using it to see if the usecode is triggering or not. I tend to use it a lot when trying to get something to work in game because it's a very obvious way to show something was triggered. In this case, it's never being triggered though which is the strange thing.

I tried the UI_error_message just in case there is some sort of issue with NPC, but no luck. Tried including a UI_click_on_item like in the real SI usecode when this is event occurs on a couple different items.

Code: Select all

void weaponTest shape#(1493)()
{
	if(event == DOUBLECLICK)
	{
			UI_error_message("Double clicked on weapon.");
	}
	else if (event == WEAPON)
	{
			var temp = UI_click_on_item();
			UI_error_message("Event weapon triggered. Temp value is ", temp);
	}
	else
	{
		UI_error_message("Else statement for weapon reached.");
	}
}
But alas, it never hit my event == WEAPON. I equipped the weapon and it did trigger the else clause:

Opening digital SFX's file: "/sqsfxsi.flx"
Gamedat identity SILVER SEED
Reading usecode file.
Loading /exult_si.flx...
Loading default keybindings
Opened socket for Exult Server on port 51480
Cheats enabled.
Else statement for weapon reached.

I did look at one function for sleep arrows, it was sleepArrowDraygan which has it triggered and use a UI_click_on_item call. It's also used in the test of purity as well.

It's bizarre to me since no matter what I do I can't get that event to trigger. If you get a chance and are so kind to look at the real code maybe you can spot some key item I may be missing to trigger this.

Thanks everyone!
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

What's the shape's class in ES?
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

In that particular example it was quality, but the result is the same if it's quality flags.

Switched it back to quality flags to the same result though.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

Interesting that READIED and UNREADIED appear to do nothing either, with no relevant log entry.

I'd have to dig into ES a bit to see what's different about the generic SI dagger (my test case) as opposed to Erinon's Axe or similar on/off switch items.

Dominus, do you know if/where the shape classification is used in relation to Usecode? As mentioned previously my Usecode for the burners in SI did not work as expected until I changed the shape's class and I couldn't find any documentation that was relevant. I had to stumble upon the solution.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

I believe some of the special actions for things like the MageBane are hard coded.
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Dominus »

Some stuff was de-hardcoded into https://github.com/exult/exult/blob/mas ... o.txt#L219
The file might be able to be overriden by one in patch or mod folder. You need to ttest
--
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!
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

So I am guessing that we'd need to update that file via ES or by hand? I'll have to try that.
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Dominus »

By hand, but it might be "patchable" so if you have it in the patch or mod folder it will override the one in the flx files.
--
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!
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

KC, it sounds like you tried a test using READIED and UNREADIED? I tried it with my weaponTest and it logged into stdout for those events.

As to the conversation about the shapes file, I'm at a bit of a loss as to what this conversation means. Sounds like the shape_info is defining what shapes can trigger usecode events?
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Dominus »

Yes, that is my takeaway from the shapesfile
--
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!
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

That is mine as well. I imagine it lines up with the "Has Usecode" check box or similar setting in ES.

Using your code, I merely tried to equip and unequip the dagger. Since that is how the SS items work, I was hoping to see the logging of that. So it's just another data point of what doesn't work.

I wish I could do all my settings edits in text files rather than in binaries.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

Checking the flag box for "Usecode event" seems to modify the shape_info.txt in my patch folder. If it's checked it puts the shape as 1, and if unchecked it sets it as 0. This is under the header %%section usecode_events. In my case, the entry is

:1493/0 - When Usecode event is unchecked
:1493/1 - When Usecode event is checked

The shape number doesn't seem to be in this list unless the checkbox was set at least once.

So it seems ES does do this automatically in the shape_info file in the patch folder.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

It also seems that event == DOUBLECLICK does not the require Usecode event flag to trigger.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

That's strange READIED and UNREADIED didn't log for you KC. I tried that myself and it logged without issue.

Code: Select all

void weaponTest shape#(1493)()
{
	if(event == DOUBLECLICK)
	{
			UI_error_message("Double clicked on weapon.");
	}
	else if (event == WEAPON)
	{
			var temp = UI_click_on_item();
			UI_error_message("Event weapon triggered. Temp value is ", temp);
	}
	else if (event == READIED)
	{
		UI_error_message("Weapon Readied");
	}
	else if (event == UNREADIED)
	{
		UI_error_message("Weapon Unreadied");
	}	
	else
	{
		UI_error_message("Else statement for weapon reached.");
	}
}
Which logged it:

Game paused
NPC write
Game resumed
Weapon Unreadied
Weapon Readied
Game paused

I'm using an older build though as I use the scrolling so much, so maybe something changed in one of the later builds.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

I didn't set the flag on the dagger though. I'd be curious if that changes the logging if you uncheck Usecode Event.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

I did have Usecode event checked.

Unchecking it does disable the log entries, with the exception of DOUBLECLICK. That box seems to set the usecode events to true/false in shape_info, 1 (checked) and 0 (unchecked), so it seems to make sense that it wouldn't log when unchecked.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

Event == WEAPON still not working though?
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

That's correct, the events I've used (DOUBLECLICK, READIED, UNREADIED) are good and I can trigger. WEAPON I can never get to trigger.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

Is this a thrown weapon, missile, or arrow? Or good old hack-and-slash weapon?

I'm feeling like we need Marzo's knowledge on this bit.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

Good old hack-and-slash. If this ever works with that I may branch out to that but for now I'm just trying to start with the basics.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

I wonder if you have to hit an NPC for it to work?
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

I've been testing it in combat and seeing the red outline on the NPC so I've been landing hits so unfortunately it doesn't seem to be that either.

Even using god mode enabled and killing the NPC so I know the hits are dealing damage and no log entries :(
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Knight Captain »

I tried this with Erinon's Axe this evening, by adding this before the end of the file:

Code: Select all

else if (event == WEAPON)
		UI_error_message("Weapon event called!");
Still no luck.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode on weapons

Post by Donfrow »

I tried putting the event on the usecode of an NPC as well thinking maybe it would make a difference. It did not. An else statement of that clause didn't trigger as well, so I guess an event like that doesn't trigger at all on an NPC.
Locked