//************************************************ //** ss_treas_toss ** //** ** //** This function is used to scatter the ** //** inventory of a creature or chest on the ** //** ground around it when opened or killed. ** //** ** //** 1 = toss and destroy ** //** 2 = toss and leave ** //** ** //************************************************ //**Created By: Jason Hunter (SiliconScout) ** //** ** //**Version: 1.6c ** //** ** //**Last Changed Date: July 17, 2004 ** //************************************************ location IsValidLoc(location lPoint); void main() { object oInv =OBJECT_SELF; object oArea = GetArea(oInv); object oItem = GetFirstItemInInventory(oInv); object oCreate; int iOption = GetLocalInt(OBJECT_SELF,"ss_t_toss"); vector vInv = GetPosition(oInv); vector vSpawn; float vInvX = (vInv.x); float vInvY = (vInv.y); float vInvZ = (vInv.z); float vSpawnX; float vSpawnY; float iVecAdd; location lSpawn; while (oItem != OBJECT_INVALID) { //Get a random vecor within 1 and 2.5 meters while(iVecAdd < 0.2) { iVecAdd = d100(1)*0.025; } if (d4() < 3) vSpawnX = vInvX + iVecAdd; else vSpawnX = vInvX - iVecAdd; iVecAdd=0.0; while(iVecAdd < 0.2) { iVecAdd = d100(1)*0.025; } if (d4() < 3) vSpawnY = vInvY + iVecAdd; else vSpawnY = vInvY - iVecAdd; //set vector vSpawn = Vector(vSpawnX, vSpawnY, vInvZ); //Set spawn location lSpawn = Location(oArea,vSpawn,0.0); //validate the location to drop on lSpawn = IsValidLoc(lSpawn); if (GetItemStackSize(oItem) > 1) { oCreate = CreateObject(GetObjectType(oItem),GetResRef(oItem),lSpawn,FALSE); SetItemStackSize(oCreate,GetItemStackSize(oItem)); }else { CreateObject(GetObjectType(oItem),GetResRef(oItem),lSpawn,FALSE); } DestroyObject(oItem,0.0); oItem = GetNextItemInInventory(oInv); } //Keep the chest live. if (iOption > 1) return; //if it's not then let the object die DestroyObject(oInv); } ////////////////////////////////////////////////////////////////////// // Function. Generates a Valid location to place an object // !WARNING! Make sure oArea is valid. Requires a custom creature // with Null Human appearance TAG = "Null" ResRef = "null" // nMinX, nMinY = lower left corner. nMaxX, nMaxY = Upper Right Corner // Example; location lSpawn = RanValidLoc(oArea,10,10,30,30); ////////////////////////////////////////////////////////////////////// location IsValidLoc(location lPoint) { CreateObject(OBJECT_TYPE_CREATURE,"ss_nulltoss",lPoint); object oNull = GetObjectByTag("ss_nulltoss"); if(GetIsObjectValid(oNull)) { location lSpawn = GetLocation(oNull); DestroyObject(oNull); return lSpawn; } else { return lPoint; } }