Name Typ
Funktion „Element ersetzen“. Definition AFRLme

Mit diesem Skript ersetzt du ein Item durch ein anderes, ohne dass sich seine Position im Inventar ändert. Das ist besonders nützlich, wenn ein Item verändert wird, etwa ein leerer Eimer, der gerade mit Wasser gefüllt wurde. Standardmäßig hängt Visionaire Studio das neue Item ans Ende des Inventars. Das Skript setzt Visionaire Studio 5.x oder neuer voraus.

Anweisungen

1. Füge das Hauptskript im Skripteditor von Visionaire Studio hinzu und lege es als Definitionsskript fest.
2. Übergib der Funktion den Namen des Items, das ersetzt werden soll, und den Namen des neuen Items; die Namen müssen exakt stimmen, auch in Groß-/Kleinschreibung und Sonderzeichen.

replaceItem("empty_bucket", "bucket_of_water")

Hauptskript

--[[
Replace item function [v2] (15/09/2022)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com-
ko-fi: https://ko-fi.com/afrlme 
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * tables * --
local itm = {} -- creates an empty table
itm["_temporary_"] = "" -- set the table as temporary (we don't want it to store any data in the save files)

-- * function for swapping 2 items while keeping the position of the current item * --
function replaceItem( init, repl )
 itm["gItm"] = game.Items -- get all game items & store them in a table
 itm["cItm"] = game.CurrentCharacter.Items -- get all character items & store them in a table
 itm["rItm"] = nil
 -- + --
 for i = 1, #(itm.gItm) do -- run a check to see if replacement item exists in game item table & if so, store item link in variable
  if itm.gItm[i]:getName() == repl then itm["rItm"] = game.Items[repl]; break end
 end
 -- + --
 for j = 1, #(itm.cItm) do -- if initial item exists and rItm is not empty then replace init item with replacement item
  if itm.cItm[j]:getName() == init and itm.rItm ~= nil then itm.cItm[j] = itm.rItm; break end
 end
 -- + --
 if itm.rItm ~= nil then game.CurrentCharacter.Items = itm.cItm end -- update character items
end