Page 1 of 1

Summon spell, specify location syntax?

Posted: Mon Oct 15, 2012 11:59 pm
by msyblade
Makin a new summon spell, got it all except the placement of the spawn, (ie. location) I'd like it to just appear 1 square in front of you, here's what I got and it all works/no errors,even says "discovered new spell "Summon". Snail simply doesnt appear cause i havent specified where to spawn it.

defineSpell{
name = "summon",
uiName = "Summon",
skill = "spellcraft",
level = 16,
runes = "ACD",
manaCost = 35,
onCast = function(caster, x, y, direction, skill)
spawn("crab")
end
}
I know its pretty simple, just need the syntax at spawn("crab") for location. Thanx!

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 12:44 am
by Decayer
Untested, but it probably works.

Code: Select all

onCast = function(caster, x, y, direction, skill)
local dx, dy = getForward(direction)
spawn("crab", caster.level, x + dx, y + dy, direction)
end
Replace 'direction' in the spawn statement with '(direction + 2) % 4' if you want it to face away from the party.

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 12:59 am
by msyblade
Thank u decayer, It is not giving any errors on export or casting, but nothing appears on succesful cast. Heres what I have now (thanx again)

defineSpell{
name = "summon",
uiName = "Summon",
skill = "spellcraft",
level = 16,
runes = "ACD",
manaCost = 35,
onCast = function(caster, x, y, direction, skill)
local dx, dy = getForward(direction)
spawn("snail", caster.level, x + dx, y + dy,(direction + 2) % 4)
end
}

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 1:02 am
by Lmaoboat
Never noticed that getForward thing before. Here I was manually checking for facing and changing the coords.

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 5:41 am
by Decayer
Whoops, it should be:
spawn("snail", party.level, x + dx, y + dy, (direction + 2) % 4)

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 6:06 am
by Grimorial
Decayer wrote:Whoops, it should be:
spawn("snail", party.level, x + dx, y + dy, (direction + 2) % 4)
I tried this with on use for an item without the (direction +2)%4. I did swap caster.level for party.level and it just kept crashing the editor. Any thoughts?

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 6:16 am
by Decayer
What did you replace the '(direction + 2) % 4' part with?

Re: Summon spell, specify location syntax?

Posted: Tue Oct 16, 2012 10:08 am
by Lollgramoth
Call a function in a LUA script_entity. That will not solve your problem, but it will prevent the game from crashing if the error occures. And it will give you an error message.

spells.lua
SpoilerShow

Code: Select all

defineSpell{
name = "summon",
uiName = "Summon",
skill = "spellcraft",
level = 16,
runes = "ACD",
manaCost = 35,
onCast = function(caster, x, y, direction, skill) 
 mySpells.summon(direction, caster)
end
}
In the Grimrock-Editor, a Lua script_entity(i.e. named "mySpells")
SpoilerShow

Code: Select all

function summon(direction, caster)
local dx, dy = getForward(direction)
spawn("snail", caster.level, x + dx, y + dy,(direction + 2) % 4)