New Spells >> show them off here

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Grimwold
Posts: 508
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 » Thu Mar 06, 2014 9:38 pm

I think you might need to use the onAttack party hook to run a script that checks if the weapon being used is the one associated with the spell (I used a similar one for my return axe script). If that is true, then you would run the script grimwold_spell_script.pushbackSpell(caster,x,y,direction,skill) but you'd need a way to find who the 'caster' (i.e. weapon user) is, their co-ordinates, direction and what 'skill' value to use.

User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: New Spells >> show them off here

Post by LocalFire » Fri Mar 07, 2014 12:43 pm

Ok so heres what I've got so far

In my init.lua

Code: Select all

cloneObject {
	name == "party",
	baseObject = "party",
	onDrawGui = function(ctx)
		mdConversationList.onDraw(ctx)

	end,
 onAttack = function(champion, weapon)
      return attackingWeaponScripts.specialWeaponAttacks(champion, weapon, skill) 
         
   end,
 
}
(the onDraw for Msyblades journal)

in a SE called attackingWeaponScripts

Code: Select all

function specialWeaponAttacks(champion, weapon, skill)
 if (weapon ~= nil) and (weapon.name == "dm_wind_sword") then
      return attackingWeaponScripts.burstSpellAttacks(champion,weapon,skill)
   end
return true end

function burstSpellAttacks(champion, weapon, skill)
 if (weapon ~= nil) and (weapon.name == "dm_wind_sword") then
      if party.facing == 0 then
local skill = champion:getSkillLevel("swords")
caster = champion
          pushback_spell_script.pushbackSpell(caster,x,y,direction,skill) 
      end
      if party.facing == 1 then
local skill = champion:getSkillLevel("swords")
caster = champion
        pushback_spell_script.pushbackSpell(caster,x,y,direction,skill)
      end
      if party.facing == 2 then
local skill = champion:getSkillLevel("swords")
caster = champion
         pushback_spell_script.pushbackSpell(caster,x,y,direction,skill)
      end
      if party.facing == 3 then
local skill = champion:getSkillLevel("swords")
caster = champion
          pushback_spell_script.pushbackSpell(caster,x,y,direction,skill)
      end
   end
end
The spell works if cast by a mage or from an item, and it seem to be calling on the correct script when I use the Wind cutter sword I made but in this section of the spells script

Code: Select all

function pushbackSpell(caster,x,y,direction,skill)
  local dx,dy = getForward(direction)
  if monsterThere(party.level,x+dx,y+dy)
  then
    -- hudPrint("Monster!")
    if isValidTarget(party.level,x+2*dx,y+2*dy)
    then
      hudPrint("PUSH!!!!")
          spawn("fx", party.level, x+dx, y+dy, direction, "push_smoke")
            :setParticleSystem("push_spell")
           :translate(0, 0.5, 0)
      playSoundAt("fireball_launch",party.level,x+dx,y+dy)
      spawn("teleporter", party.level, x+dx,y+dy,direction, "push_teleport")
        :setTeleportTarget(x+2*dx,y+2*dy, direction)
        :setTriggeredByParty(false)
        :setTriggeredByMonster(true)
        :setTriggeredByItem(false)
        :setChangeFacing(true)
        :setInvisible(true)
        :setSilent(true)
        :setHideLight(true)
        :setScreenFlash(false)
      spawn("timer",party.level,x,y,direction,"push_timer")
        :setTimerInterval(0.1)
        :addConnector("activate", "pushback_spell_script", "pushDestroy")
        :activate()
    else
      hudPrint("The spell fails because there is something in the way.")
    end
  else
    hudPrint("The spell fails because there is no monster to push")  
  end
end
Specifically local dx,dy = getForward(direction) I get the error "bad argument #1 to "getForward" number expected got nil

Any ideas on what to do here?
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443

User avatar
Grimwold
Posts: 508
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 » Fri Mar 07, 2014 2:44 pm

LocalFire wrote:Any ideas on what to do here?
In your burstSpellAttacks script you will need to define x,y and direction to pass to the pushback script. I think this normally comes from the onCast hook. It's been a long time since I wrote lua script, but I think there's a way to determine the party's co-ords... such as party.x party.y and party.facing.

so you would write something like:

Code: Select all

pushback_spell_script.pushbackSpell(caster,party.x,party.y,party.facing,skill)
since you have already defined caster and skill.

User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: New Spells >> show them off here

Post by LocalFire » Sat Mar 08, 2014 1:49 am

Yes thats it, Many thanks!
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443

User avatar
Chimera005ao
Posts: 187
Joined: Sun Jun 29, 2014 8:34 am

Re: New Spells >> show them off here

Post by Chimera005ao » Sun Jun 29, 2014 8:44 am

Hello, got Grimrock recently due to the summer sale on steam.
First spell I made.
It teleports the party in the direction you are facing, two spaces forward or as far as you can go before going into a wall.
Note: Currently allows teleportation into monsters, and other non-wall objects. Can be used to jump over single square pits.

Code: Select all

defineSpell{
	name = "leap",
	uiName = "leap",
	skill = "fire",
	level = 0,
	runes = "F",
	manaCost = 0,
	onCast = function(caster, x, y, direction, skill)
     		local target_y = party.y
		local target_x = party.x
		if direction == 0 then
			if not isWall(party.level, party.x, party.y - 1) then
				target_y = party.y - 1
				if not isWall(party.level, party.x, party.y - 2) then
					target_y = party.y - 2
				end
			end
		elseif direction == 1 then
			if not isWall(party.level, party.x + 1, party.y) then
				target_x = party.x + 1
				if not isWall(party.level, party.x + 2, party.y) then
					target_x = party.x + 2
				end
			end
			
		elseif direction == 2 then
			if not isWall(party.level, party.x, party.y + 1) then
				target_y = party.y + 1
				if not isWall(party.level, party.x, party.y + 2) then
					target_y = party.y + 2
				end
			end
		elseif direction == 3 then
			if not isWall(party.level, party.x - 1, party.y) then
				target_x = party.x - 1
				if not isWall(party.level, party.x - 2, party.y) then
					target_x = party.x - 2
				end
			end
		end
	party:setPosition(target_x, target_y, direction, party.level)
   	end
}

zzaxe
Posts: 1
Joined: Thu Dec 29, 2016 9:26 pm

Re: New Spells >> show them off here

Post by zzaxe » Thu Dec 29, 2016 9:30 pm

For some reason it says "attempt to call global 'defineSpell' (a nil value)" and i don't know how to fix it. could anyone help?

User avatar
Isaac
Posts: 2865
Joined: Fri Mar 02, 2012 10:02 pm

Re: New Spells >> show them off here

Post by Isaac » Thu Dec 29, 2016 9:36 pm

zzaxe wrote:For some reason it says "attempt to call global 'defineSpell' (a nil value)" and i don't know how to fix it. could anyone help?
Definitions do not get placed in script_entities on the map. These are put in the init.lua script, in the scripts folder of your mod. Here they get loaded first, and create/define the various objects available to the user scripts.

User avatar
HypnoToad
Posts: 70
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: New Spells >> show them off here

Post by HypnoToad » Mon Feb 04, 2019 10:00 pm

Blichew wrote:
Fri Oct 05, 2012 10:01 pm
Fan of Knives

Credits go to JohnWordsworth who had a problem with this one :P
spellcraft level and/or mana cost need to be adjusted
SpoilerShow

Code: Select all

defineSpell{
	name = "knives",
	uiName = "Fan of Knives",
	skill = "spellcraft",
	level = 1,
	runes = "AC",
	manaCost = 5,
	onCast = function(champ, x, y, direction, skill)
		local dx,dy = getForward(party.facing)
		local x,y = party.x + dx, party.y + dy
		if party.facing == 0 or party.facing == 2 then
			for modif = -0.5,0.5,0.1 do
				shootProjectile("throwing_knife", party.level, x+modif, y, party.facing, 12+(modif*2), 1.5, 1, 0, 0, 0, 1, false, true)
			end
		else
			for modif = -0.5,0.5,0.1 do
				shootProjectile("throwing_knife", party.level, x, y+modif, party.facing, 12+(modif*2), 1.5, 1, 0, 0, 0, 1, false, true)
			end
		end
	end
}

What if you just wanted a spell to shoot one projectile like a throwing axe that disappears afterwards? Can this be done?

Never mind I worked it out, I played around with the modif numbers.
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription

Post Reply