Re: Forcing the players to learn spells before using them.
Posted: Tue Dec 25, 2012 9:16 pm
That's a pretty cool idea.
Official Legend of Grimrock Forums
http://grimrock.net/forum/
Code: Select all
spellbook = {darkness = 0, enchant_fire_arrow = 0, enchant_frost_arrow = 0, enchant_shock_arrow = 0,
enchant_poison_arrow = 0, fire_shield = 0, fireball = 0, fireburst = 0, frost_shield = 0, frostbolt = 0,
ice_shards = 0, invisibility = 0, light = 0, lightning_bolt = 0, poison_bolt = 0, poison_cloud = 0,
poison_shield = 0, shock = 0, shock_shield = 0}
spellNames = {darkness = "Darkness", enchant_fire_arrow = "Enchant Fire Arrow",
enchant_frost_arrow = "Enchant Frost Arrow", enchant_shock_arrow = "Enchant Lightning Arrow",
enchant_poison_arrow = "Enchant Poison Arrow", fire_shield = "Fire Shield", fireball = "Fireball",
fireburst = "Fireburst", frost_shield = "Frost Shield", frostbolt = "Frostbolt",
ice_shards = "Ice Shards", invisibility = "Invisibility", light = "Light",
lightning_bolt = "Lightning Bolt", poison_bolt = "Poison Bolt", poison_cloud = "Poison Cloud",
poison_shield = "Poison Shield", shock="Shock", shock_shield = "Shock Shield"}
function checkSpellbook(caster, spell)
if spellbook[spell] == 1 then
return true
elseif spellbook[spell] == 0 then
hudPrint(caster:getName() .. " must learn that spell before casting it.")
return false
end
end
function learnSpell(champ, spell, skill, reqSkill)
if champ:getSkillLevel(skill) >= reqSkill then
if (spellbook[spell] == 0) then
if spellNames[spell] ~= nil then
spellbook[spell] = 1
-- playSound("scribble")
hudPrint(champ:getName() .. " scribes the spell \"" .. spellNames[spell] .. ".\"")
else
hudPrint(champ:getName() .. " does not know what the spell " .. spell .. " is.")
end
else
hudPrint(champ:getName() .. " already knows that spell.")
end
else
hudPrint(champ:getName() .. " isn't skilled enough to learn that spell.")
end
end
Code: Select all
cloneObject {
name = "scroll_darkness",
baseObject = "scroll_darkness",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "darkness", "spellcraft", 5)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Darkness.\""
}
cloneObject {
name = "scroll_enchant_fire_arrow",
baseObject = "scroll_enchant_fire_arrow",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "enchant_fire_arrow", "fire_magic", 7)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Enchant Fire Arrow.\""
}
defineObject {
name = "scroll_enchant_frost_arrow",
class = "Item",
uiName = "Scroll of Enchant Frost Arrow",
model = "assets/models/items/scroll_spell.fbx",
gfxIndex = 113,
scroll = true,
spell = "enchant_frost_arrow",
weight = 0.3,
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "enchant_frost_arrow", "ice_magic", 7)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Enchant Frost Arrow.\""
}
defineObject {
name = "scroll_enchant_lightning_arrow",
class = "Item",
uiName = "Scroll of Enchant Lightning Arrow",
model = "assets/models/items/scroll_spell.fbx",
gfxIndex = 113,
scroll = true,
spell = "enchant_shock_arrow",
weight = 0.3,
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "enchant_shock_arrow", "air_magic", 9)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Enchant Lightning Arrow.\""
}
defineObject {
name = "scroll_enchant_poison_arrow",
class = "Item",
uiName = "Scroll of Enchant Poison Arrow",
model = "assets/models/items/scroll_spell.fbx",
gfxIndex = 113,
scroll = true,
spell = "enchant_poison_arrow",
weight = 0.3,
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "enchant_poison_arrow", "earth_magic", 11)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Enchant Poison Arrow.\""
}
cloneObject {
name = "scroll_fire_shield",
baseObject = "scroll_fire_shield",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "fire_shield", "fire_magic", 16)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Fire Shield.\""
}
cloneObject {
name = "scroll_fireball",
baseObject = "scroll_fireball",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "fireball", "fire_magic", 13)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Fireball.\""
}
cloneObject {
name = "scroll_fireburst",
baseObject = "scroll_fireburst",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "fireburst", "fire_magic", 2)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Fireburst.\""
}
cloneObject {
name = "scroll_frost_shield",
baseObject = "scroll_frost_shield",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "frost_shield", "ice_magic", 19)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Frost Shield.\""
}
cloneObject {
name = "scroll_frostbolt",
baseObject = "scroll_frostbolt",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "frostbolt", "ice_magic", 13)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Frostbolt.\""
}
cloneObject {
name = "scroll_ice_shards",
baseObject = "scroll_ice_shards",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "ice_shards", "ice_magic", 3)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Ice Shards.\""
}
cloneObject {
name = "scroll_invisibility",
baseObject = "scroll_invisibility",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "invisibility", "air_magic", 19)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Invisibility.\""
}
cloneObject {
name = "scroll_light",
baseObject = "scroll_light",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "light", "spellcraft", 5)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Light.\""
}
cloneObject {
name = "scroll_lightning_bolt",
baseObject = "scroll_lightning_bolt",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "lightning_bolt", "air_magic", 14)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Lightning Bolt.\""
}
cloneObject {
name = "scroll_poison_bolt",
baseObject = "scroll_poison_bolt",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "poison_bolt", "earth_magic", 7)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Poison Bolt.\""
}
cloneObject {
name = "scroll_poison_cloud",
baseObject = "scroll_poison_cloud",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "poison_cloud", "earth_magic", 3)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Poison Cloud.\""
}
cloneObject {
name = "scroll_poison_shield",
baseObject = "scroll_poison_shield",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "poison_shield", "earth_magic", 13)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Poison Shield.\""
}
cloneObject {
name = "scroll_shock",
baseObject = "scroll_shock",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "shock", "air_magic", 4)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Shock.\""
}
cloneObject {
name = "scroll_shock_shield",
baseObject = "scroll_shock_shield",
onUseItem = function(self, champion)
return spellbook_script.learnSpell(champion, "shock_shield", "air_magic", 22)
end,
description = "A properly trained mage may scribe spells for personal use by copying the inscriptions written upon magic scrolls. This particular scroll contains a spell called \"Shock Shield.\""
}
Code: Select all
defineSound {
name = "scribble",
filename = "mod_assets/sounds/scribble.wav",
loop = false,
volume = 1,
minDistance = 1,
maxDistance = 4
}
Code: Select all
local spellName = {darkness = "Darkness",enchant_fire_arrow = "Enchant Fire Arrow",enchant_frost_arrow="Enchant Frost Arrow",enchant_shock_arrow="Enchant Lightning Arrow", enchant_poison_arrow="Enchant Poison Arrow",fire_shield="Fire Shield",fireball="Fireball",fireburst="Fireburst",frost_shield="Frost Shield",frostbolt="Frostbolt",ice_shards="Ice Shards", invisibility="Invisibility",light="Light",lightning_bolt="Lightning Bolt",poison_bolt="Poison Bolt",poison_cloud="Poison Cloud",poison_shield="Poison Shield",shock="Shock", shock_shield="Shock Shield"}
if spellName[spell] ~= nil then
hudPrint(champ:getName() .. " scribes the spell " .. spellName .. ".")
else
hudPrint(champ:getName() .. " does not know what the spell " .. spell .. " is.")
end
Exactly what I just did. I also tested it on all scrolls it looks like it's working perfectly. Post updated.Diarmuid wrote:Why should it be local and initialized every time? just put the whole spellName array out of checkSpellBook...
Great stuff. And I agree it really didn't need to be local.Ixnatifual wrote:Exactly what I just did. I also tested it on all scrolls it looks like it's working perfectly. Post updated.Diarmuid wrote:Why should it be local and initialized every time? just put the whole spellName array out of checkSpellBook...