• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

CreatureEvent [TFS 1.1] Advanced Alchemy System - ModalWindows

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,015
Solutions
3
Reaction score
629
Location
Canada
Hello, it's me again o:

By further popular demand, and in an effort to support custom servers, I've decided to release my alchemy system. Inspired by Skyrim, it's the most advanced system I've created so far. All code in this release was written by me, and this system does not exist elsewhere.

Features:
Alchemy features
- Recipes option
- List of recipes player has learned
- List of ingredients needed to brew the recipe into a potion
- Brew the potion
- Continue to quickly brew more potions if requirements are still met
- Ingredient list option
- List of ingredients that can be used, only if the player has the ingredients in inventory - won't display usable ingredients that the player is not carrying - adds mystery!
- View info of each ingredient
- Effects that can be added to the potion
- Potency of the ingredient
- Add individual ingredients to the bowl
- View the contents of the bowl in the ingredient window and in the bowl window
- Remove unwanted ingredients from the bowl
- Brew the ingredients in the bowl
- Potion's effect is decided by the number of instances of that effect in the bowl, ties are decided randomly between the highest counts
- Example: ingredient x has increase max hp and increase max mp, ingredient y has increase max mp and restore hp, ingredient z has increase max hp and restore mana
- there is one of each ingredient in the bowl. That means there is 2x increase max hp, 2x increase max mp, 1x restore hp, 1x restore mana
- the potions effect will be either increase max hp or increase max mp, decided randomly. if there had been 3x increase max hp and only 2x increase max mp, then the effect would be increase max hp guaranteed
- Potion's potency is decided by two factors: The average potency of all ingredients in the bowl, and +1 potency for each ingredient that has the effect "Increase Potency". Potency cannot be higher than 10 or lower than 1 (configurable)
- Potions duration is decided by the base duration of a potion (60 seconds) + 15 seconds for each ingredient in the bowl that has the effect "Increase Duration" up to a maximum of 2 minutes total (configurable)
- Different effects receive different bonuses from potency. the amount of health restored by a potion may increase by 10 for each potency. the amount of mana may only increase by 5 or another amount (configurable)
- Potency and Duration cannot be the effect of a potion, even if they are the highest count, they only affect the other effects of the potion
- If the ingredients in the bowl would be used to produce a pre-learned recipe, the player creates that recipe. the player also learns it to be brewed easily and quickly from the recipe list if they do not know the recipe
- Ingredient-made potions only produce one effect with varying durations (if applicable) and potencies.
- Recipe-made potions produce the same potion every time with the same duration and no potency factor, but can support multiple effects at once
- Created potion will display its effect, potency, duration, name, etc.
- Recipe-made potions will display each effect individually with individual durations/values as well as its name, etc.

Ingredient subsystem features
- Looking at an item that can be used as an ingredient will display its effects - if you've learned them
- each ingredient has two effects. the first is learned by eating the ingredient, the second is learned by using the ingredient in a potion
- each ingredient has a configurable potency and two effects. each effect has a storage to store whether the player has learned it

Potion subsystem features
- Looking at the potion will display customized name, effect(s), duration(s), value(s), etc.
- Using the potion will activate the effect on you (either instant or condition)
- Convenient and easy function to store all information about a potion for access in another script or functionality - returns a table containing all effects, values, durations, the name of the potion and any other important info about it
- Potion can be transferred between vials and other containers and still works properly

Effects
Healing Potions - Instantly restore stat
Health
Mana
Soul
Regeneration Potions - Regenerate stat faster
Health
Mana
Soul
Resistance Potions - Resist, Absorb, Reflect, Deflect single damage type or all damage types
Fire
Energy
Earth
Ice
Holy
Death
Physical
All
Speed Potions - Faster walk speed
Duh
Immunity Potions - Immune to damage type
Drown
Skill Potions - Increase skill by x
Fist
Melee
Distance
Shielding
Fishing
Fortification Potions - Increased max stats
Health
Mana
To use the system, currently you use an empty vial on a bowl with sacred water (id 12289), but this can easily be changed.

Lots of code, so just as my last release, there will be a lot of pastebin going on here.
So let's get started.
As always, I highly recommend this little feature by @zbizu for easier operation: [TFS 1.x] lib folder in "data" like 0.4

Actions
actions.xml:
add any ingredients you want to use here. If there is any conflict, you'll have to add the code from alchemy.lua to whatever script uses the ingredient you're trying to use.
XML:
<action itemid="5881" script="custom/alchemy.lua"/>
    <action itemid="5898" script="custom/alchemy.lua"/>
    <action itemid="5902" script="custom/alchemy.lua"/>
    <action itemid="5920" script="custom/alchemy.lua"/>
custom/alchemy.lua:
[Lua] alchemy.lua - Pastebin.com

other/fluids.lua:
I don't believe the default fluids.lua works properly with transferring of fluids and drinking of fluids. My version works correctly, so it is recommended that you use the whole script in place of the existing one.
[Lua] fluids.lua - Pastebin.com

Creaturescripts
creaturescripts.xml:
XML:
<event type="modalwindow" name="alchemy" script="alchemy.lua"/>
<event type="healthchange" name="PotRes" script="potionResist.lua"/>
login.lua:
Lua:
player:registerEvent("alchemy")
player:registerEvent("PotRes")
alchemy.lua:
Lua:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:ingredientWindowChoice(modalWindowId, buttonId, choiceId)
    player:alchemyWindowChoice(modalWindowId, buttonId, choiceId)
    player:potionWindowChoice(modalWindowId, buttonId, choiceId)
    player:potionRecipeWindowChoice(modalWindowId, buttonId, choiceId)
    player:infoWindowChoice(modalWindowId, buttonId, choiceId)
    player:bowlWindowChoice(modalWindowId, buttonId, choiceId)
    return true
end
potionResist.lua:
[Lua] potionResist.lua - Pastebin.com

Events
events.xml:
ensure the following are enabled (set to 1)
XML:
<event class="Player" method="onLook" enabled="1" />
<event class="Player" method="onLookInTrade" enabled="1" />
inside player.lua, find onLook and onLookInTrade.
in onLook, after
Lua:
local description = "You see " .. thing:getDescription(distance)
place this:
[Lua] player.lua - Pastebin.com

in onLookInTrade, you should see this:
Lua:
self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))
change it to this:
[Lua] onLookInTrade - Pastebin.com

Lastly, the main system.
The following two scripts will be placed in data/lib/ to be loaded by global.lua. If you do not wish to use the little system at the top to use the lib folder, you can throw these scripts in data/ and then in global.lua, add:
Lua:
dofile('data/alchemy.lua')
dofile('data/func.lua')
or you can place them in the lib folder and simply add
Lua:
dofile('data/lib/alchemy.lua')
dofile('data/lib/func.lua')
Whatever you find most convenient.
Now for the scripts.
alchemy.lua:
[Lua] alchemy - Pastebin.com

func.lua:
[Lua] func.lua - Pastebin.com

I believe that should be everything you'll need to experience this awesome system ;)

If there are any problems, or if you have any questions about the use, configuration or installation of this system, please post them here so that others can see the solutions.

This was tested on a fresh copy of TFS 1.1 release, so it should work with no additional changes after downloading the datapack and exe.

Please don't be afraid to request additional features. If they fit nicely into the system, I may add them here. If you would like something that doesn't fit so well into the public version, I can add it privately for you.

-----
I know you guys have been actively interested in my work @beastn @Colors @Codinablack @samco ;)



Thanks, and enjoy!
If you like this, please check out my other systems (found in my signature)

Edit2:
-small bug fix to creating existing recipes in lib/alchemy.lua. Please update your copy from the pastebin link to ensure proper functionality

Edit3:
-small bug fix to onLookInTrade in events/scripts/player.lua. Please update onLookInTrade with the updated version here [Lua] onLookInTrade - Pastebin.com

Edit4:
-small bug fix to onLookInTrade again, please update from the pastebin link above.

Edit5:
-fixed a bug that allowed removal of items from inventory and added a check in brewing so otclient users cannot brew for free by removing items from inventory. Update lib/alchemy.lua from [Lua] alchemy - Pastebin.com
 

Attachments

Last edited:
You did it again. I didnt check all the code, cause im currently at work, but i must say this looks soooo good. I'll modify to fit my customs, and use it for sure at my server, adding an enchanting sys with modal windows too ill have a full 3 systems for my 3 main classes on the server.

Razor, im glad you release this kind of code, i though the OTComunnity was kinda death, i see i was wrong.
 
Could someone post a video? Never played skyrim. But this release looks awesome.
 
Ill integrate the sys to my server this weekend. Thenn ill feedback you.
 
You did it again. I didnt check all the code, cause im currently at work, but i must say this looks soooo good. I'll modify to fit my customs, and use it for sure at my server, adding an enchanting sys with modal windows too ill have a full 3 systems for my 3 main classes on the server.

Razor, im glad you release this kind of code, i though the OTComunnity was kinda death, i see i was wrong.
Hoping to revive it, one modalwindow system at a time :p

Sweet! Thanks again for another great release!
Glad you like it ;)
 
Holy sh*T, I love you man. It works properly on TFS 1.2 and ORTS too.
 
Last edited:
I allready have it working. Here a sample:
8191a5c08b07f27fbe58518a06feffbf.png


Ill test more things in a minutes, im doing my lunch now :p. By the way, i have to look at the onLook thing, cause i cant look any object now.


Gonna tell you later, and maybe post a video.


EDIT:: Small video.
 
Last edited:
Back
Top