Howdy folks, I need some assitance from a script guru.
I am creating a small module right now and want to have a simplified achlemy system (NPC vendor based), the player will be able to "pick" certain environmental items up and use them to get potions/healing kits/etc.
Here is an example, in a cave there are patches of mushrooms (Brown Mushrooms, Large Group), I first tried to give them an inventory and have the item (Brown Toadstool) be in there - the pathing tried to take the PC to the center of the patch though and never opened up the inventory.
I then hit on the idea for using the Click event, this worked but you could be across the map and I wanted the PC to be right next to it so I added a distance check - the problem now is that clicking on it will have the PC run up to it and stop, it has to be clicked again (Sometimes more than once) in order for the script to fire.
Here is the code (Placed in the OnClick object event):
void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
float fPCDistance = GetDistanceToObject(oPC);
float fMaxDistance = IntToFloat(4);
if (fPCDistance <= fMaxDistance)
{
SendMessageToPC(oPC, "You gather a toadstool");
CreateItemOnObject("greentoadstool", oPC, 1);
DestroyObject(OBJECT_SELF);
}
}
I have it destroying itself so that it is like you picked the mushroom (and it avoids the need for having a local variable for each patch ). [oh, and ignore the blueprint resref saying "green".. >.> I made a mistake when creating the item.
I know I am likely missing something obvious and would really appreciate some help.
(Also, I want to display a small bit of text above the patch when picked so that there is on screen feedback, other than the message sent to the PC, about the action - the FloatingText function doesn't seem to be what I need (according to the reference) but I think I am wrong.. any insight?)