Here's a cleaned-up version of the first function, with some comments indicating potential problem spots that might explain dysfunction:
/////////////////////////////////////////////////////
// ATS_CreateItemOnPlayer //
// Wrapper for CreateItemOnObject() so it can //
// be used with DelayCommand() //
// Returns: None //
// Check local object variable: //
// "ats_returnvalue_created_item" for the //
// created object //
// Fix courtesy of Helimar on the ATS Forums //
/////////////////////////////////////////////////////
void ATS_CreateItemOnPlayer(string sItemTag,object oPlayer, int iStackSize = 1, int iDropToFloor = FALSE) {
string sItemResRef = GetStringLowerCase(GetStringLeft(sTag, 16));
string sCheck = GetStringLowercase(GetStringRight(sItemTag, 3));
if (sCheck == "dar")
iStackSzie = 20;
else if (sCheck == "bol")
iStackSize = 10;
else if (sCheck == "arr")
iStackSize = 10;
else {
object oCreatedItem = CreateItemOnObject(sItemResRef, oPlayer, iStackSize);
if (iDropToFloor && GetItemPossessor(oCreatedItem) == OBJECT_INVALID) {/* FKY: reordered and cleaned up - put booleans first to cut runtimes*/
// stacked items do not have the possessor set correctly even if they were
// created correctly if the new items were added to an existing partial stack
/*FKY: I assume the above is what you're trying to address? I'm not familiar with ths issue, but...*/
object chk = GetObjectByTag(GetStringUpperCase(sItemTag)); /*FKY: This is a bad idea, since tags are case-sensitive, and since, if memory serves, GOBT goes by most recently added AREA, not item */
/*if(iStackSize==1) // if it's not we assume it's a stackable - FKY: removed bc redundant - it must be 1 here as written*/
if(GetNumStackedItems(chk)<=1)
/*FKY: What's the purpose of this? Will return 0 for invalid items, so you might as well just check if
GetIsObjectValid(chk). Dropped items already head to the ground, unless you have other scripts to prevent it*/
// check the size of the first object found by GetObjectByTag,
// which should have more than 1 if stackable, especially since
// 1 was just added to a partial stack in the previous create.
// If not, assume it's a non-stackable and create it on the ground
oCreatedItem = CreateObject(OBJECT_TYPE_ITEM, sItemResRef, GetLocation(oPlayer));
}
SetLocalObject(oPlayer, "ats_returnvalue_created_item", oCreatedItem);/*FKY: did you intend for the remainder only to fire if stacksize = 1? At present, this is what it does, so if so, move this stuff outside this bracket, down.*/
SetLocalObject(oCreatedItem, "ats_obj_possessor", GetItemPossessor(oCreatedItem));
if (GetItemHasItemProperty(oCreatedItem, ITEM_PROPERTY_CAST_SPELL))
SetLocalInt(oCreatedItem, "ats_charges_fix", TRUE);
}
}
Funky
Modifié par FunkySwerve, 29 janvier 2013 - 05:18 .