public NWArea CreateAreaInstance(NWPlayer owner, string areaResref, string areaName, string entranceWaypointTag) { string tag = Guid.NewGuid().ToString(); NWArea instance = _.CreateArea(areaResref, tag, areaName); instance.SetLocalString("INSTANCE_OWNER", owner.GlobalID.ToString()); instance.SetLocalString("ORIGINAL_RESREF", areaResref); instance.SetLocalInt("IS_AREA_INSTANCE", TRUE); instance.Data["BASE_SERVICE_STRUCTURES"] = new List <AreaStructure>(); NWObject searchByObject = _.GetFirstObjectInArea(instance); NWObject entranceWP; if (searchByObject.Tag == entranceWaypointTag) { entranceWP = searchByObject; } else { entranceWP = _.GetNearestObjectByTag(entranceWaypointTag, searchByObject); } if (!entranceWP.IsValid) { owner.SendMessage("ERROR: Couldn't locate entrance waypoint with tag '" + entranceWaypointTag + "'. Notify an admin."); return(new NWN.Object()); } instance.SetLocalLocation("INSTANCE_ENTRANCE", entranceWP.Location); entranceWP.Destroy(); // Destroy it so we don't get dupes. _spawn.InitializeAreaSpawns(instance); string spawnScript = instance.GetLocalString("INSTANCE_ON_SPAWN"); if (!string.IsNullOrWhiteSpace(spawnScript)) { App.ResolveByInterface <IAreaInstance>("AreaInstance." + spawnScript, s => { s.Run(instance); }); } return(instance); }