Difference between revisions of "Global Command Checker (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| class="wikitable" style="width:100%"
+
{| class="ts" style="width:100%"
 
|-
 
|-
 
! 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
 
|-
 
|-
| Global Command Checker || Definition || AFRLme
+
| Global Command Checker || Definition || [https://www.patreon.com/AFRLme AFRLme]
 
|}
 
|}
  
This script allows you to check which commands can be executed on each object, item or character.
+
This script allows you to check which commands can be executed on each object, item or character. This script was made with the coin interface in mind.
 
 
'''''* The content below is a temporary placeholder *'''''
 
  
 
== 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. Add/Remove language tables to/from the '''iw''' & '''cj''' tables inside of the ''main script''; as required.<br/>
+
2. Replace the strings inside of the '''t''' table with the name of your commands; the order is not important, but the names are case sensitive.
3. Edit the string values inside of the '''iw''' table; as required. '''iw''' stands for initial word. It is the word that will be displayed before the currently held items name. The order of the strings inside of the table should reflect the integer value of the ''conjunction_class'' value. There should be a space after the word like so: '''"word "'''.
+
<syntaxhighlight lang="lua">
<syntaxhighlight>
+
local t = {"close", "examine", "give", "open", "pick_up", "pull", "push", "talk", "use"}
iw = {} -- initial word table
+
</syntaxhighlight>
iw["English"] = {"Use ", "Give ", "Show ", "Combine "}
+
3a. Inside of the '''condition''' tab of your your command interface, create a condition for each command you have created; the names should reflect the names given to the interface buttons & those of the '''t''' table.<br />
iw["French"] = {"Usage ", "Donner ", "Montrer ", "Combiner "}
+
3b. Add "_cond" prefix to the end of each of the conditions you just created; like so...
iw["German"] = {"Benutzen ", "Geben ", "Zeigen ", "Kombinieren "}
+
<pre>use_cond
iw["Spanish"] = {"Usar ", "Dar ", "Mostrar ", "Combinar "}
+
talk_cond
 +
etc...</pre>
 +
4. On mouse over for each object, item & character, create an ''execute a script'' action containing...
 +
<syntaxhighlight lang="lua">
 +
checkObjCmd()
 +
</syntaxhighlight>
 +
5. On mouse out for each object, character & item, create an ''execute a script'' action containing...
 +
<syntaxhighlight lang="lua">
 +
resetCmdCond()
 
</syntaxhighlight>
 
</syntaxhighlight>
4. Edit the string values inside of the '''cj''' table; as required. '''cj''' stands for conjunction word. It is the word that is displayed after the currently held items name. The order of the strings inside of the table should reflect the integer value of the ''conjunction_class'' value. There should be a space on both side of each word like so: '''" word "'''.
 
<syntaxhighlight>
 
cj = {} -- conjunction word table
 
cj["English"] = {" on ", " to ", " to ", " with "}
 
cj["French"] = {" en ", " à ", " à ", " avec "}
 
cj["German"] = {" auf ", " zu ", " zu ", " mit "}
 
cj["Spanish"] = {" en ", " a ", " a ", " con "}
 
</syntaxhighlight>
 
5. Create a new ''value'' in the Visionaire Studio editor & call it: '''conjunction_class'''.<br/>
 
6. On mouse enter for each object/character/item, set '''conjunction_class''' value; as required.
 
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
--[[
 
--[[
Dynamic action names for dragged items [v2] (20/02/2014)
+
Global Command Checker [v6] (17/03/2014)
 
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 46: Line 45:
  
 
-- * local variables * --
 
-- * local variables * --
local item, txt, current, lang, old, new, iw, cj, val  -- empty variables
+
local cmd -- empty variables...
  
 
-- * tables * --
 
-- * tables * --
old = {} -- table which will contain original item names
+
local t = {"close", "examine", "give", "open", "pick_up", "pull", "push", "talk", "use"} -- add command/condition names here (should both have same name)
new = {} -- table which will contain updated names
+
 
iw = {} -- initial word table
+
-- * let's create the function which will determine what type of object is currently underneath the mouse cursor * --
iw["English"] = {"Use ", "Give ", "Show ", "Combine "}
+
function checkObjCmd()
iw["French"] = {"Usage ", "Donner ", "Montrer ", "Combiner "}
+
cmd = game:getLink(VGameCurrentObject) -- store the object underneath the cursor
iw["German"] = {"Benutzen ", "Geben ", "Zeigen ", "Kombinieren "}
+
-- * --
iw["Spanish"] = {"Usar ", "Dar ", "Mostrar ", "Combinar "}
+
if not cmd:isEmpty() then
cj = {} -- conjunction word table
+
  if cmd:getId().tableId == eCharacters then cmd = cmd:getLinks(VCharacterActions) else cmd = cmd:getLinks(VObjectActions) end
cj["English"] = {" on ", " to ", " to ", " with "}
+
  for i=1, table.maxn(cmd) do getCmdCond(i) end -- for each command listed in the table check if condition exists...
cj["French"] = {" en ", " à ", " à ", " avec "}
+
end
cj["German"] = {" auf ", " zu ", " zu ", " mit "}
+
end
cj["Spanish"] = {" en ", " a ", " a ", " con "}
 
  
-- * function for udating object name with action text * --
+
-- * let's create the function which determines if command equals one of the stored conditions & sets condition accordingly * --
function itemActionName()
+
function getCmdCond(val)
item = game:getLink(VGameUsedItem) -- get currently held item
+
  for i=1, table.maxn(t) do
current = game:getLink(VGameCurrentObject) -- get current object (under cursor)
+
  if cmd[val]:getName() == "'" .. t[i] .. "' executed" or cmd[val]:getName() == "'" .. t[i] .. "' executed (immediate)" then getObject("Conditions[" .. t[i] .. "_cond]"):setValue(VConditionValue, true) end
lang = game:getLink(VGameStandardLanguage):getName() -- get current game language
+
  end
val = getObject("Values[conjunction_class]"):getInt(VValueInt) -- get conjunction class value
 
-- + --
 
  if not item:isEmpty() then -- if held item exists then...
 
  txt = item:getLink(VObjectName):getLinks(VTextAll) -- get all texts for the held item
 
  for i = 1, table.maxn(txt) do if txt[i]:getLink(VTextLanguageLanguage):getName() == lang then item = txt[i]:getStr(VTextLanguageText) end end -- store item name
 
  -- + --
 
  new = current:getLink(VObjectName):getLinks(VTextAll) -- get all texts for the object under cursor
 
  for i = 1, table.maxn(new) do table.insert(old, new[i]:getStr(VTextLanguageText))  end -- insert string names of table above
 
  -- + --
 
  for i = 1, table.maxn(new) do if new[i]:getLink(VTextLanguageLanguage):getName() == lang then new[i]:setValue(VTextLanguageText, iw[lang][val] .. item .. cj[lang][val] .. old[i]) end end -- update object name with action text (initial word, item, conjunction word, target)
 
  end
 
 
end
 
end
  
-- * function for resetting object name back to original name * --
+
-- * let's create the condition for on mouse out which checks which conditions are true & resets them back to false * --
function resetItemActionName()
+
function resetCmdCond()
  for i = 1, table.maxn(new) do new[i]:setValue(VTextLanguageText, old[i]) end -- reset all text (for each language) back to original text...
+
for i=1, table.maxn(t) do
 +
  if getObject("Conditions[" .. t[i] .."_cond]"):getBool(VConditionValue) then getObject("Conditions[" .. t[i] .. "_cond]"):setValue(VConditionValue, false) end
 +
end
 
end
 
end
</syntaxhighlight>
+
</syntaxhighlight>{{toc}}
{{i18n|Global_Command_Checker_(CMS)}}
 

Latest revision as of 13:04, 15 September 2022

Name Type By
Global Command Checker Definition AFRLme

This script allows you to check which commands can be executed on each object, item or character. This script was made with the coin interface in mind.

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Replace the strings inside of the t table with the name of your commands; the order is not important, but the names are case sensitive.

local t = {"close", "examine", "give", "open", "pick_up", "pull", "push", "talk", "use"}

3a. Inside of the condition tab of your your command interface, create a condition for each command you have created; the names should reflect the names given to the interface buttons & those of the t table.
3b. Add "_cond" prefix to the end of each of the conditions you just created; like so...

use_cond
talk_cond
etc...

4. On mouse over for each object, item & character, create an execute a script action containing...

checkObjCmd()

5. On mouse out for each object, character & item, create an execute a script action containing...

resetCmdCond()

Main Script

--[[
Global Command Checker [v6] (17/03/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.
--]]

-- * local variables * --
local cmd -- empty variables...

-- * tables * --
local t = {"close", "examine", "give", "open", "pick_up", "pull", "push", "talk", "use"} -- add command/condition names here (should both have same name)

-- * let's create the function which will determine what type of object is currently underneath the mouse cursor * --
function checkObjCmd()
 cmd = game:getLink(VGameCurrentObject) -- store the object underneath the cursor
 -- * --
 if not cmd:isEmpty() then
  if cmd:getId().tableId == eCharacters then cmd = cmd:getLinks(VCharacterActions) else cmd = cmd:getLinks(VObjectActions) end
  for i=1, table.maxn(cmd) do getCmdCond(i) end -- for each command listed in the table check if condition exists...
 end 
end

-- * let's create the function which determines if command equals one of the stored conditions & sets condition accordingly * --
function getCmdCond(val)
 for i=1, table.maxn(t) do
  if cmd[val]:getName() == "'" .. t[i] .. "' executed" or cmd[val]:getName() == "'" .. t[i] .. "' executed (immediate)" then getObject("Conditions[" .. t[i] .. "_cond]"):setValue(VConditionValue, true) end
 end
end

-- * let's create the condition for on mouse out which checks which conditions are true & resets them back to false * --
function resetCmdCond()
 for i=1, table.maxn(t) do
  if getObject("Conditions[" .. t[i] .."_cond]"):getBool(VConditionValue) then getObject("Conditions[" .. t[i] .. "_cond]"):setValue(VConditionValue, false) end
 end
end