Could do something like this which has pretty much everything you do want:
#include "x2_inc_switches"
void MakeDirt(object oPC, location lLoc)
{
object oDirt = CreateObject(OBJECT_TYPE_PLACEABLE, "x3_plc_sand004", lLoc);
DelayCommand(2.0, FloatingTextStringOnCreature("I've found nothing here.", oPC));
DestroyObject(oDirt, 10.0);
}
void MakeTreasure(object oPC, location lLoc, string sTag)
{
object oTreasure = CreateObject(OBJECT_TYPE_PLACEABLE, sTag, lLoc);
DelayCommand(2.0, FloatingTextStringOnCreature("Eureeka! A treasure chest!", oPC));
//DestroyObject(oTreasure, 60.0);
}
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
if (nEvent != X2_ITEM_EVENT_ACTIVATE) return;
object oPC = GetItemActivator();
location lLoc = GetLocation(oPC);
string sArea = GetName(GetArea(oPC));
AssignCommand(oPC, PlaySound("as_cv_mineshovl1"));
AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 5.0));
if (GetItemPossessedBy(oPC, "TREASURE_MAP_1") != OBJECT_INVALID &&
GetDistanceBetween(oPC, GetWaypointByTag("TREASURE_WP_1")) <= 1.0)
{
DelayCommand(6.0, MakeTreasure(oPC, lLoc, "nw_plc_chestburd"));
DestroyObject(GetItemPossessedBy(oPC, "TREASURE_MAP_1"));
return;
}
if (GetItemPossessedBy(oPC, "TAG OF MAP2") != OBJECT_INVALID &&
GetDistanceBetween(oPC, GetWaypointByTag("TAG OF WAYPOINT2")) <= 1.0)
{
DelayCommand(6.0, MakeTreasure(oPC, lLoc, "TAG OF TREASURE CHEST HERE"));
DestroyObject(GetItemPossessedBy(oPC, "TAG OF MAP2"));
return;
}
//if (etc...
else
{
DelayCommand(6.0, MakeDirt(oPC, lLoc));
}
}
This runs off the activated item event/tag based script (you use the shovel, unlimited uses).
Can change it up though depending on how you want the treasures laid out in your world though. One in each area? Several in each area? One area with several? etc...
The one other thing you might need is a custom "OnClosed" script for the treasure chest to destroy itself. Or could uncomment the line in the MakeTreasure function to destroy it after a delay too, but then the player might not have looted it before it disappears.
Just a simple, working example. Hope it helps.