Hello OTland community,
I'm trying to create a Lua script with the help of ChatGPT, which is supposed to grant an imbued armor when a player steps on a specific tile with a given action ID. The goal is for the script to give a "Soulshroud" armor with fire and energy resistance. However, despite multiple attempts, the script doesn't seem to work as expected, and I'm not sure what I'm missing.
Here's the script I'm currently using:
If anyone could provide insight or suggest changes to make this work, I'd greatly appreciate it!
Thank you in advance for your help!
I'm trying to create a Lua script with the help of ChatGPT, which is supposed to grant an imbued armor when a player steps on a specific tile with a given action ID. The goal is for the script to give a "Soulshroud" armor with fire and energy resistance. However, despite multiple attempts, the script doesn't seem to work as expected, and I'm not sure what I'm missing.
Here's the script I'm currently using:
The script seems to execute without errors, but the armor is not applying the desired imbuements (fire and energy resistance). I'm not sure if the issue lies with the setAttribute function, or if there's a different approach required to apply imbuements directly to an item in this way.local actionId = 58426
local itemId = 34096 -- Soulshroud
local armorSlot = CONST_SLOT_ARMOR
local movement = MoveEvent()
function movement.onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end
-- Check if the player already has an item in the armor slot
if player:getSlotItem(armorSlot) then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You must remove your current armor to receive the Soulshroud.")
return true
end
-- Create the Soulshroud and set resistances
local armor = Game.createItem(itemId, 1)
if armor then
-- Set fire and energy resistance on the item
armor:setAttribute(ITEM_ATTRIBUTE_FIRE_RESISTANCE, 3) -- 3% fire damage reduction (level 1 "Dragon Hide")
armor:setAttribute(ITEM_ATTRIBUTE_ENERGY_RESISTANCE, 3) -- 3% energy damage reduction (level 1 "Cloud Fabric")
-- Add the item to the player's inventory
player:addItemEx(armor, true)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received the Soulshroud with fire and energy protection.")
else
player:sendTextMessage(MESSAGE_STATUS_WARNING, "An error occurred while giving you the Soulshroud.")
end
return true
end
-- Register the action ID
movement:aid(actionId)
movement:register()
If anyone could provide insight or suggest changes to make this work, I'd greatly appreciate it!
Thank you in advance for your help!