Difference between revisions of "Insert Item (CMS)"
From The Official Visionaire Studio: Adventure Game Engine Wiki
m (Text replacement - "wikitable" to "ts") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By | ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By | ||
|- | |- | ||
− | | Insert Item Function || Definition || AFRLme | + | | Insert Item Function || Definition || [https://www.patreon.com/AFRLme AFRLme] |
|} | |} | ||
Line 9: | Line 9: | ||
== Instructions == | == Instructions == | ||
− | 1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/> | + | 1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br /> |
− | 2. To use this function you have to include both the names of the item you want to replace, & the item that that you will be replacing it with; item names are case & character sensitive.<br/> | + | 2. To use this function you have to include both the names of the item you want to replace, & the item that that you will be replacing it with; item names are case & character sensitive.<br /> |
2a. Example for placing ''new'' item '''before''' the initial item... | 2a. Example for placing ''new'' item '''before''' the initial item... | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="lua"> |
− | + | insertItem("nail", "hammer" false) -- place item "nail" before the hammer | |
</syntaxhighlight> | </syntaxhighlight> | ||
2b. Example for placing ''new'' item '''after''' the initial item... | 2b. Example for placing ''new'' item '''after''' the initial item... | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="lua"> |
− | + | insertItem("nail", "hammer", true) -- place item "nail" after the hammer | |
</syntaxhighlight> | </syntaxhighlight> | ||
== Main Script == | == Main Script == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="lua"> |
--[[ | --[[ | ||
Insert item function [v2] (31/05/2014) | Insert item function [v2] (31/05/2014) | ||
Written by AFRLme [Lee Clarke] | 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. | This script is donation optional. In game credit is non-negotiable. | ||
Line 58: | Line 61: | ||
if itm.nItm ~= nil then game:getLink(VGameCurrentCharacter):setValue(VCharacterItems, itm.cItm) end -- update character items | if itm.nItm ~= nil then game:getLink(VGameCurrentCharacter):setValue(VCharacterItems, itm.cItm) end -- update character items | ||
end | end | ||
− | </syntaxhighlight> | + | </syntaxhighlight>{{toc}} |
Latest revision as of 13:08, 15 September 2022
Name | Type | By |
---|---|---|
Insert Item Function | Definition | AFRLme |
This script allows you to insert & place a new item into the inventory, before or after another item.
Instructions
1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. To use this function you have to include both the names of the item you want to replace, & the item that that you will be replacing it with; item names are case & character sensitive.
2a. Example for placing new item before the initial item...
insertItem("nail", "hammer" false) -- place item "nail" before the hammer
2b. Example for placing new item after the initial item...
insertItem("nail", "hammer", true) -- place item "nail" after the hammer
Main Script
--[[
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