Removing items
Posted: Sun May 04, 2008 11:27 am
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.
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.