You can make it so that if the item in the champions inventory is a container (By name/id, or if getComponent("containeritem") or however) then it goes through that item slot by slot for the scroll.TSotP wrote:that's awesome, thanks guys.
i do have another related question.
would that script return true if the spell scroll was in a container? The reason i ask, is i wonder if i could make a modified 'wooden box' or 'sack' as a spellbook for the scrolls Nevermind, the answer is no.
Thank you for this! It got me started on something I was wanting to get around to. Here is the first version of a staff that will only let the wielder cast the spells they have placed into it.
Runewand:
Code: Select all
defineObject{
name = "runewand_sk",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/acolyte_staff.fbx",
},
{
class ="Item",
uiName = "Runewand",
gfxIndex = 340,
weight = 2.7,
impactSound = "impact_blunt",
traits = { "stave", "light_weapon" },
secondaryAction = "castPrimaryRune",
description = "A simple Runewand once used by an apprentice mage."
},
{
class = "RunePanel",
},
{
class = "EquipmentItem",
slot = 1,
},
{
class = "ContainerItem",
containerType = "sack",
},
}
}
Code: Select all
defineObject{
name = "party",
baseObject = "party",
components = {
{
class = "Party",
onCastSpell =
function(party,champion,spellName)
local allRunecasters = { "runewand_sk" }
local itmName = ""
local spellUiName = ""
local equippedRunecaster = ""
if spellName == "water_breathing" then
itmName = "scroll_water_breathing"
spellUiName = "Water Breathing"
end
if spellName == "resurrection" then
itmName = "scroll_resurrection"
spellUiName = "Resurrection"
end
if spellName == "antidote" then
itmName = "scroll_antidote"
spellUiName = "Antidote"
end
if spellName == "recovery" then
itmName = "scroll_recovery"
spellUiName = "Recovery"
end
if spellName == "antivenom" then
itmName = "scroll_antivenom"
spellUiName = "Antivenom"
end
if spellName == "enchant_arrow" then
itmName = "scroll_enchant_arrow"
spellUiName = "Enchant Arrow"
end
if spellName == "heal" then
itmName = "scroll_heal"
spellUiName = "Healing"
end
if spellName == "mass_heal" then
itmName = "scroll_mass_heal"
spellUiName = "Mass Healing"
end
if spellName == "shield" then
itmName = "scroll_shield"
spellUiName = "Shield"
end
if spellName == "force_field" then
itmName = "scroll_force_field"
spellUiName = "Force Field"
end
if spellName == "fireburst" then
itmName = "scroll_fireburst"
spellUiName = "Fireburst"
end
if spellName == "light" then
itmName = "scroll_light"
spellUiName = "Light"
end
if spellName == "darkness" then
itmName = "scroll_darkness"
spellUiName = "Darkness"
end
if spellName == "darkbolt" then
itmName = "scroll_darkbolt"
spellUiName = "Darkbolt"
end
if spellName == "fireball" then
itmName = "scroll_fireball"
spellUiName = "Fireball"
end
if spellName == "meteor_storm" then
itmName = "scroll_meteor_storm"
spellUiName = "Meteor Storm"
end
if spellName == "shock" then
itmName = "scroll_shock"
spellUiName = "Shock"
end
if spellName == "invisibility" then
itmName = "scroll_invisibility"
spellUiName = "Invisibility"
end
if spellName == "lightning_bolt" then
itmName = "scroll_lightning_bolt"
spellUiName = "Lightning Bolt"
end
if spellName == "poison_cloud" then
itmName = "scroll_poison_cloud"
spellUiName = "Poison Cloud"
end
if spellName == "poison_bolt" then
itmName = "scroll_poison_bolt"
spellUiName = "Poison Bolt"
end
if spellName == "ice_shards" then
itmName = "scroll_ice_shards"
spellUiName = "Ice Shards"
end
if spellName == "dispel" then
itmName = "scroll_dispel"
spellUiName = "Dispel"
end
if spellName == "frostbolt" then
itmName = "scroll_frostbolt"
spellUiName = "Frostbolt"
end
if spellName == "fire_shield" then
itmName = "scroll_fire_shield"
spellUiName = "Fire Shield"
end
if spellName == "shock_shield" then
itmName = "scroll_shock_shield"
spellUiName = "Shock Shield"
end
if spellName == "poison_shield" then
itmName = "scroll_poison_shield"
spellUiName = "Poison Shield"
end
if spellName == "frost_shield" then
itmName = "scroll_frost_shield"
spellUiName = "Frost Shield"
end
if champion:getItem(1) == nil then
hudPrint("You must have a Runecaster equipped.")
return false
end
for i = 1, #allRunecasters do
if champion:getItem(1).go.name == allRunecasters[i] then
local runeCapacity = champion:getItem(1).go.containeritem:getCapacity()
for j = 1, runeCapacity do
local checkItem = champion:getItem(1).go.containeritem:getItem(j)
if checkItem ~= nil then
if checkItem.go.name == itmName then
return true
end
end
end
end
end
hudPrint("That rune is not slotted into your caster.")
return false
end
},
},
}
The code as is works 99% of the time. If you take an item from the staff and try to throw out into the world, the editor seems to crash. You have to place it in your inventory and then throw/drop it.
I tried integrating the streamlined code jkos wrote but kept getting an error I hadn't seen before ("bad self" I believe it was). I also tried to make it check if the item in slot 1 was ANY containeritem and also got an error, so I'm not sure how I managed to piece even this mostly working staff together given that any time I try to simplify it I make things crash. I hope to have it become a fairly versatile system, where spells and spell modifiers can be placed into a wand (Ideally with less/different slots than 9 or 16) to determine what spells a champion is able to cast.
Something like this is part of a collection of spells I'm in the middle of working on and Jhaelen's code gave me a nice starting point.