Difference between revisions of "Cycle Inventory Items (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{| class="ts" style="width:100%"
 
{| class="ts" style="width:100%"
 
|-
 
|-
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By {{lee_PP}}
+
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| Cycle Inventory Items || Definition || AFRLme
+
| Cycle Inventory Items || 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. Edit the '''slots = 0''' value inside of the script to the amount of inventory slots you added to your interface.<br/>
+
2. Edit the '''slots = 0''' value inside of the script to the amount of inventory slots you added to your interface.<br />
 
3. By default the script will only allow you to cycle the inventory items when the amount of items in the inventory equals the same or greater than the amount of inventory slots. You can toggle between the default mode & always cycle by creating an ''execute a script'' action containing:
 
3. By default the script will only allow you to cycle the inventory items when the amount of items in the inventory equals the same or greater than the amount of inventory slots. You can toggle between the default mode & always cycle by creating an ''execute a script'' action containing:
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
toggleCycleMode()
 
toggleCycleMode()
 
</syntaxhighlight>
 
</syntaxhighlight>
 
4. To cycle inventory items forward (ascending) you should create an ''execute a script'' action containing:
 
4. To cycle inventory items forward (ascending) you should create an ''execute a script'' action containing:
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
cycleItems(true)
 
cycleItems(true)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
5. To cycle inventory items backwards (descending) you should create an ''execute a script'' action containing:
 
5. To cycle inventory items backwards (descending) you should create an ''execute a script'' action containing:
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
cycleItems(false)
 
cycleItems(false)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<html><button class="copybtn" onclick="CopyToClipboard('main_script')"></button></html>
 +
<syntaxhighlight lang="lua" id="main_script">
 
--[[
 
--[[
Cycle inventory items by ascending or descending order [v2] (12/02/2014)
+
Cycle inventory items by ascending or descending order [v2.1] (15/09/2022)
 
Written by AFRLme [Lee Clarke]
 
Written by AFRLme [Lee Clarke]
 
-- + --
 
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
+
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 49: Line 53:
 
-- * function for cycling through the inventory items * --
 
-- * function for cycling through the inventory items * --
 
function cycleItems(asc)
 
function cycleItems(asc)
  char = game:getLink(VGameCurrentCharacter) -- store current character
+
  char = game.CurrentCharacter -- store current character
  items = char:getLinks(VCharacterItems) -- store inventory items into a table
+
  items = char.Items -- store inventory items into a table
  amt = table.maxn(items) -- get index number of last item
+
  amt = #items -- get index number of last item
 
  if cycle or amt >= slots then
 
  if cycle or amt >= slots then
   if asc then item = items[amt]; table.remove(items, amt); table.insert(items, 1, item) else item = items[1]; table.remove(items, 1); table.insert(items, (table.maxn(items)+1), item) end
+
   if asc then item = items[amt]; table.remove(items, amt); table.insert(items, 1, item) else item = items[1]; table.remove(items, 1); table.insert(items, item) end
   char:setValue(VCharacterItems, items) -- update the inventory
+
   game.CurrentCharacter.Items = items -- update the inventory
 
  end
 
  end
 
end
 
end
 
</syntaxhighlight>{{toc}}
 
</syntaxhighlight>{{toc}}

Latest revision as of 12:39, 15 September 2022

Name Type By
Cycle Inventory Items Definition AFRLme

This script allows you to cycle through the items in your inventory system.

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Edit the slots = 0 value inside of the script to the amount of inventory slots you added to your interface.
3. By default the script will only allow you to cycle the inventory items when the amount of items in the inventory equals the same or greater than the amount of inventory slots. You can toggle between the default mode & always cycle by creating an execute a script action containing:

toggleCycleMode()

4. To cycle inventory items forward (ascending) you should create an execute a script action containing:

cycleItems(true)

5. To cycle inventory items backwards (descending) you should create an execute a script action containing:

cycleItems(false)

Main Script

--[[
Cycle inventory items by ascending or descending order [v2.1] (15/09/2022)
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.
--]]

-- * local variables * --
local char, items, item, amt -- empty variables
local slots = 0 -- define inventory slot amount here
local cycle = false -- false = only cycle inventory when item amount equals same as or more than inventory slots. true = always cycle

-- * function for changing cycle mode * --
function toggleCycleMode()
 if cycle then cycle = false else cycle = true end
end

-- * function for cycling through the inventory items * --
function cycleItems(asc)
 char = game.CurrentCharacter -- store current character
 items = char.Items -- store inventory items into a table
 amt = #items -- get index number of last item
 if cycle or amt >= slots then
  if asc then item = items[amt]; table.remove(items, amt); table.insert(items, 1, item) else item = items[1]; table.remove(items, 1); table.insert(items, item) end
  game.CurrentCharacter.Items = items -- update the inventory
 end
end