Have a look at this:
That's my attempt to remove all the player's equipment, then put it back again later, e.g. if it's taken from you while you're in prison and then returned later when you leave. (At present your weapons are unequipped and then you're prevented from re-equipping, then you just have to not look at the "Inventory" screen and pretend that all your stuff isn't still there.)
'TempRemoveItems' works perfectly, as confirmed by a 'DumpAttributes'. But 'RestoreTempRemovedItems' crashes the game, leaving nothing suspicious in "compile.log" or "system.log" and no "error.log" at all. A mass of 'trace' statements (literally one after almost every command) shows that it crashes while trying to 'CopyAtttibutes'. That's probably because "dstRef" is defined as pointing to "_refCharacter.items", which has just been deleted so "dstRef" is no longer pointing at anything. I moved the 'DeleteAttributes' up to before both the 'aref' declarations and the function worked.
Now look at this in "quests.c":
It's no coincidence that these are almost identical to my functions. I didn't know about 'CopyAttributes' but guessed that something of the sort must be at the heart of 'ExchangeCharacterShip', which I did know, so I went looking for the definition of 'ExchangeCharacterShip' to see how it worked and found the above two functions, which do exactly what I want except they do it to ships instead of items. So I simply copied them and replaced "Ship" with "items".
Those two functions aren't used anywhere, despite being in "quests.c" ever since the stock game, and as 'RestoreTempRemovedShip' is near identical to my original 'RestoreTempRemovedItems' then it will probably crash the game for the same reason. And my guess is that's why, when you lose your ship in the standard storyline after falling overboard in a storm, you do so by an 'ExchangeCharacterShip' with a dummy character created specifically for that purpose. Moving the 'DeleteAttribute(_refCharacter,"Ship")' up to before the two 'aref' lines would probably make this function work as well.
Code:
bool TempRemoveItems(ref _refCharacter)
{
if( CheckAttribute(_refCharacter,"TmpItemHolder") ) return false;
if( !CheckAttribute(_refCharacter,"items") ) return false;
aref dstRef; makearef(dstRef, _refCharacter.TmpItemHolder);
aref srcRef; makearef(srcRef, _refCharacter.items);
CopyAttributes(dstRef,srcRef);
DeleteAttribute(_refCharacter,"items");
return true;
}
bool RestoreTempRemovedItems(ref _refCharacter)
{
if( !CheckAttribute(_refCharacter,"TmpItemHolder") ) return false;
aref dstRef; makearef(dstRef, _refCharacter.items);
aref srcRef; makearef(srcRef, _refCharacter.TmpItemHolder);
DeleteAttribute(_refCharacter,"items");
CopyAttributes(dstRef,srcRef);
DeleteAttribute(_refCharacter,"TmpItemHolder");
return true;
}
'TempRemoveItems' works perfectly, as confirmed by a 'DumpAttributes'. But 'RestoreTempRemovedItems' crashes the game, leaving nothing suspicious in "compile.log" or "system.log" and no "error.log" at all. A mass of 'trace' statements (literally one after almost every command) shows that it crashes while trying to 'CopyAtttibutes'. That's probably because "dstRef" is defined as pointing to "_refCharacter.items", which has just been deleted so "dstRef" is no longer pointing at anything. I moved the 'DeleteAttributes' up to before both the 'aref' declarations and the function worked.
Now look at this in "quests.c":
Code:
bool ShipTempRemove(ref _refCharacter)
{
if( CheckAttribute(_refCharacter,"TmpShipHolder") ) return false;
if( !CheckAttribute(_refCharacter,"Ship") ) return false;
aref dstRef; makearef(dstRef, _refCharacter.TmpShipHolder);
aref srcRef; makearef(srcRef, _refCharacter.Ship);
CopyAttributes(dstRef,srcRef);
return true;
}
// Âîññòàíîâèòü äàííûå î íàøåì ñòàðîì êîðàáëå èç ïàìÿòè
//------------------------------------------------------
bool RestoreTempRemovedShip(ref _refCharacter)
{
if( !CheckAttribute(_refCharacter,"TmpShipHolder") ) return false;
aref dstRef; makearef(dstRef, _refCharacter.Ship);
aref srcRef; makearef(srcRef, _refCharacter.TmpShipHolder);
DeleteAttribute(_refCharacter,"Ship");
CopyAttributes(dstRef,srcRef);
DeleteAttribute(_refCharacter,"TmpShipHolder");
return true;
}
Those two functions aren't used anywhere, despite being in "quests.c" ever since the stock game, and as 'RestoreTempRemovedShip' is near identical to my original 'RestoreTempRemovedItems' then it will probably crash the game for the same reason. And my guess is that's why, when you lose your ship in the standard storyline after falling overboard in a storm, you do so by an 'ExchangeCharacterShip' with a dummy character created specifically for that purpose. Moving the 'DeleteAttribute(_refCharacter,"Ship")' up to before the two 'aref' lines would probably make this function work as well.