Event (equipped, unequipped)

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

Event (equipped, unequipped)

Post by Donfrow »

Just curious, does the events such as equipped and unequipped work for cloaks, helms, etc, or is it just weapons and rings?

I'm trying something with a cloak to trigger something when equipped and unequipped and I'm not sure if it's not working due to event triggers not being for the cloak spot.

Thanks
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by marzo »

It should work for all objects that have "usecode events" checked in ES.
------
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]
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by Donfrow »

That would be it. Didn't have the usecode events checked.

Now, based on my understanding of my old thread about what stats do, I'm trying to make this cloak add 1 to the max mana when equipped by the Avatar.

It should be a simple as below correct? MAX_MANA being equal to 6

mana_cloak shape#(1440)()
{
if(event == READIED)
{
var current_max_mana = UI_get_npc_prop(AVATAR, MAX_MANA);
UI_set_npc_prop(AVATAR, MAX_MANA, current_max_mana+1);
}
else if (event == UNREADIED)
{
var current_max_mana = UI_get_npc_prop(AVATAR, MAX_MANA);
UI_set_npc_prop(AVATAR, MAX_MANA, current_max_mana-1);
}

}

Currently have Avatar's "Max. Mana" set to 15. Upon equipping the cloak it puts "Max. Mana" to 30. Removing the cloak keeps "Max. Mana" at 30. Am I missing another glaringly obvious issue?

Much appreciated.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by Malignant Manor »

set_npc_prop isn't setup very nicely. It adjusts by adding what is put in place of "int delta". So you were telling it to add 16 when putting on the cloak and add 15 when taking off the cloak. The adjustment should have been this.

ready:
UI_set_npc_prop(AVATAR, MAX_MANA, 1);

unready:
UI_set_npc_prop(AVATAR, MAX_MANA, - 1);


This following code should exclude other NPCs from giving the Avatar a boost if they wear the cloak. (of course you need to substitute information I don't have.

(I could fill in frame with get_item_frame (), but it if it is only one frame that will activate the usecode, then putting the frame number is probably better.)

if(event == READIED && UI_is_readied(AVATAR, int spot, 1440, int frame))

else if (event == UNREADIED && UI_is_readied(AVATAR, int spot, 1440, int frame))



One potential problem I can see is the fact that the Avatar's previous max mana isn't stored. If 30 is the max for mana (for having information saved or hardcapped), then the Avatar could potentially lose a point if he was maxed out to begin with. I'm not sure if the axe in SS was a class object that stored the user's previous stat level for combat. Doing something similar can avoid this problem.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by Malignant Manor »

add 15 should be add 14 (oh, well. I miss edits.)

You could also put:

if !(UI_is_readied(AVATAR, int spot, 1440, int frame)
return;


at the beginning to exclude others as well.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by Donfrow »

I see what you mean. Not sure why I thought I needed the current_mana_level. Thanks for clearing up my error.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by marzo »

I would also recommend keeping track of whether or not the cloak added anything to magic (for example, if the avatar has 30 magic, putting on the cloak and taking it off could reduce magic to 29).
------
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]
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by marzo »

set_npc_prop isn't setup very nicely. It adjusts by adding what is put in place of "int delta".
Ah, yes; the problem with [url=file:///D:/AmazingDocs/Misc/HomePage/V4%20PHP/Exult_intrinsics.html]documentation[/url] is that nobody reads it :-)

From that page:

Code: Select all

UI_set_npc_prop(actor npc, int prop, int delta)
UI_set_npc_prop(actor npc, string prop, int delta)
npc->set_npc_prop(int prop, int delta)
npc->set_npc_prop(string prop, int delta)

Increases property 'prop' of 'npc' by 'delta'. If 'delta' is negative,
the property is decreased. Just to be clear: 'delta' is the
[b]change[/b] in property 'prop'.[...]
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by Malignant Manor »

I would also recommend keeping track of whether or not the cloak added anything to magic (for example, if the avatar has 30 magic, putting on the cloak and taking it off could reduce magic to 29).
Since this only changes the stat by one, it could probably easily be added with something like this under the "readied" section.

If (UI_get_npc_prop(AVATAR, MAX_MANA) == 30)
{
gflags[30Magic] = true;
return;
}


and this under "unreadied":

if (gflags[30Magic])
return;


You might possibly want to have unreadied set the flag to false in case other things can give a temporary boost to magic (although multiple boosts from different items could be problematic).
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Event (equipped, unequipped)

Post by Donfrow »

Very good point about the max mana already being 30. I hadn't thought of that occurrence happening.

I think the reason I messed up the way I did was I used some older code I wrote to heal the difference between current hit point level and max hit point level, so when I started this item I blended the two together in my mind and made the frankenstein code I presented.

As always, much thanks!
Locked