Log in

View Full Version : Item lists



foxtacles
03-31-2013, 06:26 PM
Void VAULTSCRIPT OnServerInit() noexcept
{
auto containers = Container::GetList();

for (const auto& container : containers)
AddItemList(container, static_cast<ID>(0));
}

Item lists can be created / modified with a script. They can be added to a container (effectively adding all the items on the list to the container). The above code initializes all containers in the game world with their default item lists, which have the ID zero and are made up of the same items which can be found in singleplayer by default.

foxtacles
04-04-2013, 02:16 AM
Void VAULTSCRIPT OnServerInit() noexcept
{
auto containers = Container::GetList();

for (const auto& container : containers)
{
auto list = ItemList::Create(GetBase(container));
RemoveItem(list, ALCH::NukaCola, UINT_MAX);
AddItemList(container, list);
DestroyObject(list);
}
}

All container operations (plus actor equip / unequip) work on item lists. Item lists can be constructed from a container or item list (copy). Item lists can be added to a container or other item lists. This code is the same as above, except it removes all Nuka Cola's from the default contents.

You can, for example, build static item lists which can be added as needed to a player by just using AddItemList.

foxtacles
04-04-2013, 02:48 AM
Initializer lists:

Void VAULTSCRIPT OnSpawn(ID object) noexcept
{
Player player(object);

if (player)
{
player.UIMessage("Hello, " + player.GetBaseName() + "!");

auto ID = ItemList::Create({
{ALCH::NukaCola, 100}, // 100x Nuka Cola
{WEAP::Weap32CaliberPistol, 1, 80.0, True, True}, // .32 pistol, 80% health, equipped
{AMMO::Ammo32Caliber, 300}, // 300x .32 ammo
});

player.AddItemList(ID);
DestroyObject(ID);
}
}

foxtacles
04-04-2013, 06:59 PM
Void VAULTSCRIPT OnSpawn(ID object) noexcept
{
Player player(object);

if (player)
{
player.UIMessage("Hello, " + player.GetBaseName() + "!");

player.AddItem({
{ALCH::NukaCola, 100}, // 100x Nuka Cola
{WEAP::Weap32CaliberPistol, 1, 80.0, True, True}, // .32 pistol, 80% health, equipped
{AMMO::Ammo32Caliber, 300}, // 300x .32 ammo
});
}
}

Works as well