New Spells >> show them off here

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: New Spells >> show them off here

Post by Grimwold »

@soaponarope

as a long-time DM fan I did wonder about the see through walls spell, but could not think of a way to do it with the current Grimrock tools. I think flatline's suggestions are the best way to go.


Hmmm. I should have a think about how to do the footprints spell from DM... that should be possible in Grimrock by using the party onMove hook and spawning an object or particle system.
flatline

Re: New Spells >> show them off here

Post by flatline »

Quick update of my magic pack: Fixed a mixup for two spells and their required spell schools.
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: New Spells >> show them off here

Post by SpiderFighter »

Bucnasti wrote:I created a replacement for the light spell. It creates a stationary light object in the player square which lasts for 30 seconds, if the spell is recast it deletes the existing object and creates a new one. Makes the light spell useful but not a permanent solution.

Mage Light
SpoilerShow

Code: Select all

defineSpell{
   name = "light",
   uiName = "Magic Light",
   skill = "spellcraft",
   level = 5,
   runes = "BE",
   manaCost = 15,
   onCast = function()
		if findEntity("spell_light") then
			print("spell light exists, destroying")
			spell_light:destroy()
			spell_light_timer:destroy()
		end
	print("spawning a new spell_light")
	spawn("spell_torchlight", party.level, party.x, party.y, party.facing, "spell_light")
	spawn("timer", party.level, party.x, party.y, party.facing, "spell_light_timer")
	playSound("generic_spell")
	spell_light_timer:setTimerInterval(30)
	spell_light_timer:addConnector("activate", "spell_light", "deactivate") 
	spell_light_timer:activate()
	end,
}
Gah. I've been trying to come up with diffrent spells on my own, but it always turn out that they're already here and done better than I can. I'm having a problem with this one, though. I have to assume this worked at one time, but now it crashes the game with an "undefined object: spell_torchlight" error. Does anyone know if this has been changed (or what's going on)? Full error.log below:
SpoilerShow
mod_assets/scripts/spells.lua:67: undefined object: spell_torchlight
stack traceback:
[C]: in function 'error'
[string "ScriptEntity.lua"]: in function 'spawn'
mod_assets/scripts/spells.lua:67: in function 'onCast'
[string "Spells.lua"]: in function 'castSpell'
[string "Champion.lua"]: in function 'castSpell'
[string "AttackPanel.lua"]: in function 'update'
[string "AttackPanel.lua"]: in function 'update'
[string "Gui.lua"]: in function 'draw'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk

OS Version 6.1

OEM ID: 0
Number of processors: 2
Page size: 4096
Processor type: 586

Total memory: 6050 MB
Free memory: 1097 MB

Display device 0:
Device name: \\.\DISPLAY1
Device string: Intel(R) HD Graphics Family
State flags: 00000005

Display device 1:
Device name: \\.\DISPLAY2
Device string: Intel(R) HD Graphics Family
State flags: 08000000

Display device 2:
Device name: \\.\DISPLAYV1
Device string: RDPDD Chained DD
State flags: 00000008

Display device 3:
Device name: \\.\DISPLAYV2
Device string: RDP Encoder Mirror Driver
State flags: 00200008

Display device 4:
Device name: \\.\DISPLAYV3
Device string: RDP Reflector Display Driver
State flags: 00200008
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: New Spells >> show them off here

Post by akroma222 »

Hey Spider,
At the risk of asking the stupidest question ever... do you have spell_torchlight defined properly?
Less stupid question - are you using Diarmuid's exsp framework for your spells yet??
Let me know, I am currently converting about 60-70 spells over to the new exsp framework, and that 'magelight' spell is going to be one of them...
I have two dungeons, a test using the framework and the main one that is not, I will retry the spell in both...
--------------------EDIT
Non exsp mage light version-
For Spells.lua-
SpoilerShow
defineSpell{
name = "light",
uiName = "Mage Light",
skill = "fire_magic",
level = 0,
runes = "AF",
manaCost = 1,
onCast = function()
return torch_script.torchlight(caster,x,y,dir,skill)
end,
}
For objects.lua-
SpoilerShow
defineObject{
name = "spell_torchlight",
class = "LightSource",
lightPosition = vec(0, 2.58, 0),
lightRange = 12,
lightColor = vec(0.7, 0.5, 0.5),
brightness = 12,
castShadow = true,
particleSystem = "torch",
placement = "floor",
editorIcon = 88,
}
and the script (torch_script) in dungeon-
SpoilerShow
function torchlight()
if findEntity("spell_light") then
print("spell light exists, destroying")
spell_light:destroy()
spell_light_timer:destroy()
end
print("spawning a new spell_light")
spawn("spell_torchlight", party.level, party.x, party.y, party.facing, "spell_light")
spawn("timer", party.level, party.x, party.y, party.facing, "spell_light_timer")
playSound("generic_spell")
spell_light_timer:setTimerInterval(240)
spell_light_timer:addConnector("activate", "spell_light", "deactivate")
spell_light_timer:activate()
end
works fine for me in my non-exsp dungeon... let me convert to exsp and test... (tomorrow though, sleep now)
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: New Spells >> show them off here

Post by SpiderFighter »

akroma222 wrote:Hey Spider,
At the risk of asking the stupidest question ever... do you have spell_torchlight defined properly?
Less stupid question - are you using Diarmuid's exsp framework for your spells yet??
Let me know, I am currently converting about 60-70 spells over to the new exsp framework, and that 'magelight' spell is going to be one of them...
I have two dungeons, a test using the framework and the main one that is not, I will retry the spell in both...
--------------------EDIT
Non exsp mage light version-
For Spells.lua-
SpoilerShow
defineSpell{
name = "light",
uiName = "Mage Light",
skill = "fire_magic",
level = 0,
runes = "AF",
manaCost = 1,
onCast = function()
return torch_script.torchlight(caster,x,y,dir,skill)
end,
}
For objects.lua-
SpoilerShow
defineObject{
name = "spell_torchlight",
class = "LightSource",
lightPosition = vec(0, 2.58, 0),
lightRange = 12,
lightColor = vec(0.7, 0.5, 0.5),
brightness = 12,
castShadow = true,
particleSystem = "torch",
placement = "floor",
editorIcon = 88,
}
and the script (torch_script) in dungeon-
SpoilerShow
function torchlight()
if findEntity("spell_light") then
print("spell light exists, destroying")
spell_light:destroy()
spell_light_timer:destroy()
end
print("spawning a new spell_light")
spawn("spell_torchlight", party.level, party.x, party.y, party.facing, "spell_light")
spawn("timer", party.level, party.x, party.y, party.facing, "spell_light_timer")
playSound("generic_spell")
spell_light_timer:setTimerInterval(240)
spell_light_timer:addConnector("activate", "spell_light", "deactivate")
spell_light_timer:activate()
end
works fine for me in my non-exsp dungeon... let me convert to exsp and test... (tomorrow though, sleep now)
Thanks for replying! I'm not using Diarmuid's exsp framework...honestly, I'd forgotten about it, as I'm just really getting into them. I assumed that "spell_torchlight" was already in the original game's assets, so that's completely me, as I didn't define it. The gf has the computer this weekend, so I'll have to give it another go tomorrow morning (and I'll look at Diarmuid's framework). Thanks again!!
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: New Spells >> show them off here

Post by akroma222 »

Ahh good good! Glad to help Spider :)

Diarmuid's EXSP spell framework really opens up many doors for spell creation...
Follow the installation instructions here - viewtopic.php?f=14&t=4848
Check out the spells that come with the framework, they show case a few very cool spells...
Grimwold's spell pack has been converted over already...
just the tip of the iceberg though, I suspect ;)
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: New Spells >> show them off here

Post by SpiderFighter »

akroma222 wrote:Ahh good good! Glad to help Spider :)

Diarmuid's EXSP spell framework really opens up many doors for spell creation...
Follow the installation instructions here - viewtopic.php?f=14&t=4848
Check out the spells that come with the framework, they show case a few very cool spells...
Grimwold's spell pack has been converted over already...
just the tip of the iceberg though, I suspect ;)
Wow, that's intense stuff. Thanks for pointing me in the right direction!
acolade
Posts: 3
Joined: Sat Mar 23, 2013 10:44 pm

Re: New Spells >> show them off here: Create Healing Potion

Post by acolade »

Hi there,
this spell checks hands of the caster for the empty flask and exchange it with healing one.
This code may help with the enchant arrow spell mentioned before. Also it is used as a base for this, so the credits for all of the users presenting the spell and discusing it.
Have a nice day.
SpoilerShow

Code: Select all


defineSpell {
  name = "create_healing_potion",
  uiName = "Create Healing Potion",
  skill = "spellcraft",
  level = 1,
  runes = "B",
  manaCost = 15,
  onCast = 
    function(caster, x, y, direction, skill)
    
      local slot = nil   -- define variable outside "if" blocks to be useable later
        
        -- check hand for flask
        if (caster:getItem(7) ~= nil) and (caster:getItem(7).name == "flask") then
          
          slot = 7
        
        -- check other hand for flask
        elseif (caster:getItem(8) ~= nil) and (caster:getItem(8).name == "flask") then
          
          slot = 8
          
        -- no flask found
        else
        
          hudPrint("You have to cast this spell while holding an empty flask in your hand.")
          return false  -- this ends the function, so there is no need for other "if" checking empty hands
        
        end
        
        -- exchange the healing for empty flask
        caster:removeItem(slot)
        caster:insertItem(slot, spawn("potion_healing"))
        playSound("generic_spell")
        hudPrint(caster:getName().." filled flask with Healing Potion")
                    
        return true
    end,
}

Marble Mouth
Posts: 52
Joined: Sun Feb 10, 2013 12:46 am
Location: Dorchester, MA, USA

Re: New Spells >> show them off here

Post by Marble Mouth »

Edit: I was responding to a post that has now been deleted...

Hi akroma222. I would hardcode a table containing the names of all the ammunition types, in the order that you want to cycle through them, for example:

Code: Select all

ammoCycle = { "rock" , "throwing_knife" , "arrow" , }
Since we haven't specified keys for the table, lua starts at 1 and counts upwards to assign the keys, so this is equivalent to:

Code: Select all

ammoCycle = { [1] = "rock" , [2] = "throwing_knife" , [3] = "arrow" , }
This table allows us to easily convert a number into the name of an ammunition. Then, we'll also want a way to convert the name of an ammunition into the appropriate number. We could loop through the whole table every time looking for a match, but I prefer this method:

Code: Select all

ammoNumbers = {}
--build inverse table
for i , v in ipairs( ammoCycle ) do
	ammoNumbers[v] = i
end
This code builds a table ammoNumbers which is the "inverse" of ammoCycle. When building inverse tables, it only makes sense if all of the entries in the original table are unique. So based on this example, ammoNumbers could have been defined this way:

Code: Select all

ammoNumbers = { rock = 1 , throwing_knife = 2 , arrow = 3 }
except that we haven't hardcoded it. This makes it very easy to add a new entry to ammoCycle (at the beginning, middle, or end), and rely on the code to keep ammoNumbers up-to-date automatically. With these tables built, you can easily identify which items are valid ammunition for switching:

Code: Select all

local item
local slot
for i = 7,8 do
	item = caster:getItem(i)
	if item and ammoNumbers[item.name] then
		slot = i
		break
	end
end
if not slot then
	return
end
If the item's name is used as a key in ammoNumbers, then it's valid. Now that we have these tables built and the slot determined, we can do the switch as:

Code: Select all

local oldAmmoName = item.name
local stackSize = item:getStackSize()
caster:removeItem(slot)
local newAmmoNumber = ( ammoNumbers[oldAmmoName] % ( table.getn( ammoCycle ) ) ) + 1
local newAmmo = spawn( ammoCycle[newAmmoNumber] )
newAmmo:setStackSize( stackSize )
caster:insertItem( slot , newAmmo )
playSound("generic_spell")
hudPrint( caster:getName() .. " trasmuted ammunition." )
The critical line for the switch is:

Code: Select all

local newAmmoNumber = ( ammoNumbers[oldAmmoName] % ( table.getn( ammoCycle ) ) ) + 1
ammoNumbers[oldAmmoName] - This gives us the number which is the key in ammoCycle corresponding to the old ammo.
table.getn( ammoCycle ) - This is the size of ammoCycle. In this example, it is 3.
% - modulo. The reason we do this, is so that if ammoNumbers[oldAmmoName] is equal to table.getn( ammoCycle ) , then we wrap around to 0. Otherwise, the result of ammoNumbers[oldAmmoName] % ( table.getn( ammoCycle ) ) will just be equal to ammoNumbers[oldAmmoName] .
Then we add 1. The final result will always be a number between 1 and table.getn( ammoCycle ) inclusive. This will always be a valid key for the table ammoCycle .

The tables won't change after initialization, so I think it makes sense to build them just once, as non-locals. Putting everything together, we have:

Code: Select all

ammoCycle = { "rock" , "throwing_knife" , "arrow" , }

ammoNumbers = {}
--build inverse table
for i , v in ipairs( ammoCycle ) do
	ammoNumbers[v] = i
end

onCastTransmuteAmmo = function( caster )

	local item
	local slot
	for i = 7,8 do
		item = caster:getItem(i)
		if item and ammoNumbers[item.name] then
			slot = i
			break
		end
	end
	if not slot then
		return
	end

	local oldAmmoName = item.name
	local stackSize = item:getStackSize()
	caster:removeItem(slot)
	local newAmmoNumber = ( ammoNumbers[oldAmmoName] % ( table.getn( ammoCycle ) ) ) + 1
	local newAmmo = spawn( ammoCycle[newAmmoNumber] )
	newAmmo:setStackSize( stackSize )
	caster:insertItem( slot , newAmmo )
	playSound("generic_spell")
	hudPrint( caster:getName() .. " transmuted ammunition." )
end
Edited for spelling
acolade
Posts: 3
Joined: Sat Mar 23, 2013 10:44 pm

Re: New Spells >> show them off here: Create Healing Potion

Post by acolade »

Hi,
I have updated my script for easier use with other transmute spells.
SpoilerShow
This part insert as a lua script_entity in your dungeon.

Code: Select all

  transmute_item = function (caster, item1, item2)
  
      local slot = nil
      local item1_obj = spawn(item1)
      local item2_obj = spawn(item2)

      -- check hands for item1 (position 7 and 8)
      for i = 7,8 do
      
        if (caster:getItem(i) ~= nil) and (caster:getItem(i).name == item1) then
        
          slot = i
          break
          
        end
        
      end
      if slot == nil then
      
        hudPrint("You have to cast this spell while holding " .. item1_obj:getUIName() .. " in your hand.")
        return false
        
      end
      
      -- exchange the item1 for item2
      caster:removeItem(slot)
      caster:insertItem(slot, item2_obj)
      playSound("generic_spell")
      hudPrint(caster:getName() .. " transmuted " .. item1_obj:getUIName() .. " into " .. item2_obj:getUIName() .. ".")
                  
      return true
  end
  
This part should be in your spells.lua.

Code: Select all


defineSpell {

  name = "create_healing_potion",
  uiName = "Create Healing Potion",
  skill = "spellcraft",
  level = 1,
  runes = "B",
  manaCost = 15,
  
  onCast = function(caster, x, y, direction, skill) 
  
    transmute_item(caster, "flask", "potion_healing")
  
  end,
}
The only thing you need to change is this line:

Code: Select all

transmute_item(caster, "flask", "potion_healing")
You need to add "some_name." before and change flask and potion_healing for other items (except nil) to transmute from and to.
"some_name" is the ID of the lua script_entity you have created in your dungeon.

Code: Select all

some_name.transmute_item(caster, "random_item1", "random_item2")
And at the end I have some questions:
Is there any possibility to put the function, that is used in onCast hook, to some external text file instead of lua script_entity in the dungeon?
Will the lua script_entity be working in the whole dungeon or only in the level where is inserted?

Thank you and have a nice day.
Post Reply