Lua scripting: Difference between revisions

From Bonfire by Hogswild Prasetto
bonfire-wiki>Sonic260
Lua Functions: Adds getclosespureorc() and walktoorc() commands from the genieagent.lua file
bonfire-wiki>Hogswild
Added advanced lua execution stuff for the upcoming version
Line 185: Line 185:
|
|
|}
|}
== Stepping up: Advanced Lua execution (for 0.36.0) ==
So far we've read on how to use Lua from within a macro or dialogue structure. However, if your wish is to directly use Lua and advanced iterators without needing to wrap everything using an old school macro and timed console tricks, a more advanced implementation is available.
=== <u>Inventory injection</u> ===
Raw Lua scripts written and saved in the game's ''%appdata%/Prasetto/Bonfire//Mods/lua'' can be directly injected into the console @target character's inventory as an item that will be saved within their data, much like the classic macros, using the following command:
<pre>oluainj luaScriptName</pre>
...where "luaScriptName" is the name of the script file that is saved on the aforementioned %appdata% location in your computer. The name has to be provided as is, without a directory path nor a file extension. If successful, a new item in the form of a Lua parchment will be visible on the character's inventory. It will attempt to initialize and execute any code in your script that isn't wrapped inside a function scope upon first injection.
Iterated execution
Once a Lua script is injected, it will remain in the character's inventory and active process memory for actual execution. The idea is to allow you to either call any of the script's functions directly at any given time, or to create a timed iterator that will execute any of its functions repeatedly for a given amount of time.
Immediate and single execution of an injected Lua script function can be achieved by writing:
<pre>oluacf luaScriptName,functionName</pre>
While iterated execution can be achieved by writing:
<pre>oluaiifr luaScriptName,functionName,executionTime</pre>
Additionally, if you wish to stop execution of any previously invoked function iterators from a script, use:
<pre>oluaria luaScriptName,functionName</pre>
...Or simply write "oluaria" with no commands and it will remove all iterators currently running in the character.
Invoked iterators will also create an inventory entry on the character that represents their ongoing process, meaning that they save with the character and will automatically resume their process upon spawning on the scene. Iterators will also remember their elapsed execution time, unless they were set to run for an "Infinity" amount of seconds, in which case they will last forever unless manually removed.

Revision as of 19:27, 6 October 2019

Article under construction

Lua scripts and proceses are similar to that of macros and dialogue conditionals, where a series of operations and checks are made in order to allow players to essentially mod the game by adding new gameplay mechanics.

The feature is wrapped inside classic macros and dialogue trees in the form of two main dialogue actions:

OrcLuaScript

This action will inject a lua script into your orc. Normally, the injection only initializes the script and keeps it in memory, so that no further injections are necessary. A good use of this action would be to place it at the very beginning of your macro and have its code nested under handy functions that we call later using a different action. Further executions of the same action on the same macro line will not re-inject the code when an instance of the same lua script with the same ID name already exists, so you can safely loop through your macro as usual without having it re-interpret your action's script.

Here is an example of a lua script to be injected:

function start ()

    if orc.game.sceneis ('Outback1') then

        -- give him the pipe from the start

        orc.game.consolecommand ('asset bopipe')

        if orc.game.consoleasset == nil then

            orc.consolecommand ('batch target @self;asset World/Items/Pipe1;assetnameset bopipe;hrattachca;assetpos -0.0289,0.0571,-0.0238,-21.348,-118.294,217.56,true;assetscalereset')

        else

            orc.consolecommand ('batch target @self;hrattachca;assetpos -0.0289,0.0571,-0.0238,-21.348,-118.294,217.56,true;assetscalereset')

        end

        orc.consolecommand ('forceanim Idle SmokePipe1')

    end

end

This code injects only one function named start that does a series of setup adjustments to the character Bo, in order to have him hold his pipe. Remember that this code is not being executed upon injection; only later on we will call this and any other function that your script contains. Please note that right now it is not possible to include function parameters within the parentheses.

OrcLuaScriptFunction

This action will let you execute any of the functions contained in a lua script that were previously injected using the OrcLuaScript action. It will ask for the ID name of the script that was injected, and the name of the function that you want to execute (for example, the start function from above). Note: functions only need their name provided, without the end parentheses.

Lua commands

Your script can use the following commands and variables in order to build behaviours and mechanics. Commands are always preceded by the "orc." variable, which represents the actual orc carrying the script instance. Below is a list of commands that can be used within your scripts:

Function name Usage Description
consolecommand consolecommand(command) Will execute a classic console command. Make sure you use quotation marks, preferably single. Example:

consolecommand('barafylite @playername,1,60,0')

ifitemflag ifitemflag(name,data) Checks if the orc has the specified flag of given name and data. Both parameters are strings.
setitemflag setitemflag(flagname, flagdata) Sets or changes a flag of given flagname with given flagdata
orcobjset orcobjset(name) Will set this orc's "objective" target to the orc specified as name . The variable can be a direct orc name, or any of the arguments used by the console, such as "@target", "@playername", etc. Once set, the objective can be manipulated using any of the lua commands by using the variable orc.orcobjective instead of orc. as a prefix. (Make sure you do nil checks on that variable before use)
fapstart fapstart() Begins fap
fapstop fapstop() Stops fap
sexanal1

sexanal2

sexanal1() or

sexanal2()

Engages into anal with objective
endsex endsex() Ends sex
getclosestpureorc orc.getclosestpureorc()
walktoorc orc.walktoorc()

Lua variables

These can be used to check against "if" conditionals or directly set parameters.

Variable name Type Description
istheplayer bool Returns true if the instance is the player.
canseeorcobjective bool Returns true if objective can be seen.
canseeinterest bool "Interest" is like a lighter version of "objective", being the character our instance is looking at, but not necessarily targeting. This returns true if they are still in view to our instance.
distancetoobjective float Returns the distance to objective.
busywalking bool Returns true if the instance is busy walking to a destination
onatask bool Returns true if the instance is busy doing some task like casting a spell or sexing.
isairborne bool Returns true if the instance is floating in mid air
istalking bool ...true if the instance is in a dialogue.
corruption float Returns the instance's level of corruption. Goes from 0.0 to 3.0, 1.0 being the cap before turning into a genie.
immutable bool ...true if this instance is either a ghost or a special character that cannot be altered by transformation spells nor corruption.
isgeniefragment bool ...true if this instance is an NPC genie fragment (different from a cursed genie)
isghost bool ...true if this instance is a ghost.
isbusy bool ...true if this instance is busy at all.
issexing bool ...true if instance is sexing.
isfapping bool ...true if instance is fapping
arousal float Returns the level of arousal this instance has at the moment. Goes from 0.0 to 1.0
cumming bool ...true if, during a sex scene, the instance is orgasming
afterglowing bool ...true if the instance is afterglowing right after orgasming during a sex scene.
perfectglowing bool ...true after the instance has achieved a perfect synchronized orgasm during a sex scene.
orcname string The name of the character.
More to come later!

Stepping up: Advanced Lua execution (for 0.36.0)

So far we've read on how to use Lua from within a macro or dialogue structure. However, if your wish is to directly use Lua and advanced iterators without needing to wrap everything using an old school macro and timed console tricks, a more advanced implementation is available.

Inventory injection

Raw Lua scripts written and saved in the game's %appdata%/Prasetto/Bonfire//Mods/lua can be directly injected into the console @target character's inventory as an item that will be saved within their data, much like the classic macros, using the following command:

oluainj luaScriptName

...where "luaScriptName" is the name of the script file that is saved on the aforementioned %appdata% location in your computer. The name has to be provided as is, without a directory path nor a file extension. If successful, a new item in the form of a Lua parchment will be visible on the character's inventory. It will attempt to initialize and execute any code in your script that isn't wrapped inside a function scope upon first injection.

Iterated execution

Once a Lua script is injected, it will remain in the character's inventory and active process memory for actual execution. The idea is to allow you to either call any of the script's functions directly at any given time, or to create a timed iterator that will execute any of its functions repeatedly for a given amount of time.

Immediate and single execution of an injected Lua script function can be achieved by writing:

oluacf luaScriptName,functionName

While iterated execution can be achieved by writing:

oluaiifr luaScriptName,functionName,executionTime

Additionally, if you wish to stop execution of any previously invoked function iterators from a script, use:

oluaria luaScriptName,functionName

...Or simply write "oluaria" with no commands and it will remove all iterators currently running in the character.

Invoked iterators will also create an inventory entry on the character that represents their ongoing process, meaning that they save with the character and will automatically resume their process upon spawning on the scene. Iterators will also remember their elapsed execution time, unless they were set to run for an "Infinity" amount of seconds, in which case they will last forever unless manually removed.