Name Typ Von
Funktion „Element einfügen“. Definition AFRLme

Mit diesem Skript fügst du ein neues Item vor oder hinter einem anderen Item ins Inventar ein.

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 neuen Items und den Namen des Items, an dem es eingefügt werden soll; die Namen müssen exakt stimmen, auch in Groß-/Kleinschreibung und Sonderzeichen.
2a. Beispiel, um das neue Item vor dem vorhandenen Item einzufügen ...

insertItem("nail", "hammer" false) -- place item "nail" before the hammer

2b. Beispiel für die Platzierung neu Artikel danach der erste Artikel...

insertItem("nail", "hammer", true) -- place item "nail" after the hammer


Hauptskript

--[[
Insert item function [v2] (31/05/2014)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
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 inserting an item before or after another item * --
function insertItem( new, init, sta )
 itm["gItm"] = game:getLinks(VGameItems) -- get all game items & store them in a table
 itm["cItm"] = game:getLink(VGameCurrentCharacter):getLinks(VCharacterItems) -- get all character items & store them in a table
 itm["nItm"] = nil -- default value of new item
 itm["val"] = 1 -- default value of item slot
 -- + --
 for i = 1, #(itm.gItm) do -- run a check to see if new item exists in game item table & if so, store item link in variable
  if itm.gItm[i]:getName() == new then itm.nItm = getObject("Game.GameItems[" .. new .. "]") break end
 end
 -- + --
 for j = 1, #(itm.cItm) do -- if initial item exists and nItm is not empty then add new item before or after initial item
  if itm.cItm[j]:getName() == init and itm.nItm ~= nil then
   if sta then itm.val = (j + 1) else itm.val = j end -- if true then add after else add before initial item
   table.insert(itm.cItm, itm["val"], itm.nItm) -- insert new item into table
  break -- kill the for loop
  end
 end
 if itm.nItm ~= nil then game:getLink(VGameCurrentCharacter):setValue(VCharacterItems, itm.cItm) end -- update character items
end