Removing items

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

Removing items

Post by Donfrow »

Sorry for yet another question, but I'm trying to figure out how to remove items based on whether or not they were clicked on from the inventory or from sitting on the ground.

An existing example of this is when you have multiple heal potions in the inventory, and click one not in the inventory, how the game knows to remove it from the non-inventory spot instead of the inventory.

So what I'm actually trying to do is make it so that you can disenchant magic weapons using a disenchanting stone, but if you click on the stone from some place on the ground it will not remove it from your inventory in the event the player has multiple disenchanting stones, or remove the disenchantment target from the inventory if you clicked on one not in the inventory. But here is where I run into problems.

I have coding as such:

disenchanting_stone shape#(1434)()
{
var stone_loc = get_object_position();

var stone_x = stone_loc[1];
var stone_y = stone_loc[2];
var stone_z = stone_loc[3];

var avatar_loc = UI_get_object_position(AVATAR);

var avatar_x = avatar_loc[1];
var avatar_y = avatar_loc[2];
var avatar_z = avatar_loc[3];

if(event == DOUBLECLICK)
{

var target = UI_click_on_item();
var target_shape = UI_get_item_shape(target[1]);
var target_x = target[2];
var target_y = target[3];
var target_z = target[4];

if(target_shape == LIGHTNING_WHIP)
{
if(stone_x == avatar_x && stone_y == avatar_y) // stone was in inventory
{
if(target_x == avatar_x && target_y == avatar_y) // whip is in inventory too
{
AVATAR.say("Hitting the if");
UI_remove_party_items(1, LIGHTNING_WHIP, ANY, ANY);
UI_remove_party_items(1, DISENCHANTING_STONE, ANY, ANY);
}
else // whip was not in inventory
{
AVATAR.say("Target x equals ", target_x, " and avatar x equals ", avatar_x);
AVATAR.say("Target y equals ", target_y, " and avatar y equals ", avatar_y);
}
}
}
}
}

What I am trying to accomplish is if the first double clicked item (the stone) is the same location as the avatar it's in the inventory, and then it checks if the second clicked item (the lightning whip) is in same location as the avatar to check if it's in the inventory.

It works as expected up to checking if the whip is the same location as the Avatar. At this point it never equals and always hits the else (where I have the actual values stated). The thing is, target_x and target_y constantly change values, even if I don't move the Avatar.

Example being target_x will equal 1297, 1277, 1283, 1287, 1292, 1278, etc all while the Avatar stays put and the avatar_x is always 1292.

Am I missing something as to how get_object_position works when it's in the inventory, or is there another way to check if the item is on the ground vs in the inventory when it is clicked on?

Thanks again for taking the time to help me.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Removing items

Post by Malignant Manor »

I think you are trying to make it too complicated. I'm tired, but this should work. When you double click on the stone, it singles that stone out and allows "remove_item()" to remove it. "UI_remove_item(UI_click_on_item())" will remove the target you select after double clicking on the stone. It needs an "if" statement to make sure it selects the proper item. I'm sure Marzo can explain more about Usecode than what little knowledge and time I have at the moment.


disenchanting_stone shape#(1434)()
{
if (event==doubleclick)
{
var target = UI_click_on_item();
var target_shape = UI_get_item_shape(target[1]);
if (target_shape==LIGHTNING_WHIP)
{
remove_item();//removes the stone
UI_remove_item(target);//removes the lightning whip
}
}
}


I'm kind of wondering the purpose of the stone other than to ruin a perfectly good item. I'm also wondering why you don't change the shape of the lightning whip into the shape of a normal whip and possibly having a used up stone replace the previously unused disenchantment stone, but I guess it and the stone go poof with the current coding. (not really nitpicking but giving suggestions and trying to understand what all you want the item to do)
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Removing items

Post by Donfrow »

Ohh using UI_remove_item makes it much simpler and gets rid of a bunch of if's... I missed that intrinsic entirely. Oops.

What I'm actually doing is when you disenchant the item it will replace it with a regular item (whip for lightning whip, sword for fire sword, etc) and some reagents.

Thanks a lot for the help MM!
Locked