Healing spell code
Healing spell code
Healing spell code but only heals caster not the whole party.
Log 2 does not like party:getchampion(i)
Any ideas how to make this heal all party members
defineSpell{
name = "earthheal",
uiName = "Earth Heal",
skill = "earth_magic",
requirements = { "earth_magic", 2 },
icon = 71,
spellIcon = 4,
gesture = 2547,
manaCost = 40,
description = "Conjures a wave of Earth energy that heals the party.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
--spell cast and tagged for the champion who cast it.
spawn("earthheal", party.level, party.x, party.y, party.facing, party.elevation)
local heal_amount = math.random(20,25)
for i=1,4 do
champion:modifyBaseStat("health", heal_amount)
end
hudPrint(champion:getName() .. " Healed the party by " .. heal_amount .. " points")
playSound("heal_party")
end,
}
defineObject{
name = "earthheal",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "teleport_screen",
offset = vec(0, 1.5, 0),
},
{
class = "Light",
offset = vec(1.5, 1.0, 0),
color = vec(0.5, 0.5, 0.25),
brightness = 7,
range = 5,
fadeOut = 13,
disableSelf = true,
},
{
class = "CloudSpell",
attackPower = 0,
damageInterval = 2,
damageType = "fire",
duration = 1,
},
},
}
Log 2 does not like party:getchampion(i)
Any ideas how to make this heal all party members
defineSpell{
name = "earthheal",
uiName = "Earth Heal",
skill = "earth_magic",
requirements = { "earth_magic", 2 },
icon = 71,
spellIcon = 4,
gesture = 2547,
manaCost = 40,
description = "Conjures a wave of Earth energy that heals the party.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
--spell cast and tagged for the champion who cast it.
spawn("earthheal", party.level, party.x, party.y, party.facing, party.elevation)
local heal_amount = math.random(20,25)
for i=1,4 do
champion:modifyBaseStat("health", heal_amount)
end
hudPrint(champion:getName() .. " Healed the party by " .. heal_amount .. " points")
playSound("heal_party")
end,
}
defineObject{
name = "earthheal",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "teleport_screen",
offset = vec(0, 1.5, 0),
},
{
class = "Light",
offset = vec(1.5, 1.0, 0),
color = vec(0.5, 0.5, 0.25),
brightness = 7,
range = 5,
fadeOut = 13,
disableSelf = true,
},
{
class = "CloudSpell",
attackPower = 0,
damageInterval = 2,
damageType = "fire",
duration = 1,
},
},
}
Last edited by LordGarth on Sat Dec 03, 2016 2:01 am, edited 1 time in total.
Dungeon Master and DOOM will live forever.
Re: Healing spell code
Try party.party:getChampion(i)
Alois
Alois
- zimberzimber
- Posts: 432
- Joined: Fri Feb 08, 2013 8:06 pm
Re: Healing spell code
You seem to be really lost.
You don't have to spawn anything to heal the party or to interact with champions in any way, so you don't have to use
In the following code...
you're not calling for each champion individually, and you're not healing the champion.
Instead, you're modifying the base health of the champion which casts the spell. Four times.
That happens because the variable 'champion' is never changed, it still holds the data for the champion who casted the spell, because its one of the variables received in the onCast() function.
What you have to do fix this is create a new variable (so you could still get later which champion casted the spell in case you need it) and modify it inside the 'for' loop.
You can move 'local heal_amount' into the 'for' loop so that every champion receives different healing.
You don't need to define a new object for particle effects. You can either spawn a 'particle_system' object and change its particle component via scripts.
Or if it's something like the teleport screen effect you can use
You should really learn some basics :/
You don't have to spawn anything to heal the party or to interact with champions in any way, so you don't have to use
Code: Select all
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
spawn("earthheal", party.level, party.x, party.y, party.facing, party.elevation)
Code: Select all
for i=1,4 do
champion:modifyBaseStat("health", heal_amount)
end
Instead, you're modifying the base health of the champion which casts the spell. Four times.
That happens because the variable 'champion' is never changed, it still holds the data for the champion who casted the spell, because its one of the variables received in the onCast() function.
What you have to do fix this is create a new variable (so you could still get later which champion casted the spell in case you need it) and modify it inside the 'for' loop.
Code: Select all
local heal_amount = math.random(20,30)
for i = 1,4 do
local c = party.party:getChampion(i)
c:regainHealth(heal_amount)
end
You don't need to define a new object for particle effects. You can either spawn a 'particle_system' object and change its particle component via scripts.
Code: Select all
local p = party:spawn("particle_system")
p.particle:setParticleSystem("myparticlesystem")
p.particle:setOffset(vec(x,y,z))
Code: Select all
party.party.playScreenEffect("myparticlesystem")
My asset pack [v1.10]
Features a bit of everything!
Features a bit of everything!
Re: Healing spell code
...well - he is asking for to learn what to learn...
Re: Healing spell code
Indeed.THOM wrote:...well - he is asking for to learn what to learn...
Reading the scripts here on the forum is not the best place to learn (the basics); they are not always commented, and often use confusing shorthand [syntactic sugar]... worse, some of it only works in context, where rote copying could give unintended (certainly confusing) results when pasted elsewhere verbatim or with minor alterations.
Best [IMO] to first learn to read Lua scripts for basic comprehension of the terms, and afterwards read the Grimrock scripting reference(s) for the available utility functions and object properties; and after that, skim through the asset pack's object examples [especially those with hooks]. All the while, experimenting with either the Grimrock console, and/or a dedicated Lua console to test what you've learned (or suspect). It shouldn't take too long to pick it up, and one certainly doesn't have to memorize ALL of it before gaining a reasonable understanding of what's being done in a script. The references are just that ~references. We all use them.
http://lua-users.org/wiki/LuaDirectory
https://www.lua.org/manual/5.1/manual.html
https://www.lua.org/demo.html
http://www.grimrock.net/modding/scripting-reference/
https://github.com/JKos/log2doc/wiki << More up to date
http://www.grimrock.net/modding/grimrock-2-asset-pack/
Re: Healing spell code
Works great with the above codealois wrote:Try party.party:getChampion(i)
Alois
and there should be no sound command in the object code
I am also gonna try to see if I can put in remove wounds in the healing spell as well.
thanks again
LordGarth
Dungeon Master and DOOM will live forever.
Re: Healing spell code
Previous healing codes healed dead champions
Here is a new code
numbers after math.random can be changed to desired healing range amount
defineSpell{
name = "earthheal",
uiName = "Earth Heal",
skill = "earth_magic",
requirements = { "earth_magic", 2 },
icon = 71,
spellIcon = 4,
gesture = 2547,
manaCost = 40,
description = "Conjures a wave of Earth energy that heals the party.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
--spell cast and tagged for the champion who cast it.
spawn("earthheal", party.level, party.x, party.y, party.facing, party.elevation)
local heal_amount = math.random(5,10)
for i=1,4 do
local c = party.party:getChampion(i)
if (c:getBaseStat("health") > 0) then
party.party:getChampion(i):modifyBaseStat("health", heal_amount)
else
party.party:getChampion(i):modifyBaseStat("health", 0)
end
hudPrint(champion:getName() .. " Healed the party by " .. heal_amount .. " points")
playSound("heal_party")
end
end
}
defineObject{
name = "earthheal",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "teleport_screen",
offset = vec(0, 1.5, 0),
},
{
class = "Light",
offset = vec(1.5, 1.0, 0),
color = vec(0.5, 0.5, 0.25),
brightness = 7,
range = 5,
fadeOut = 13,
disableSelf = true,
},
{
class = "CloudSpell",
attackPower = 0,
damageInterval = 2,
damageType = "fire",
duration = 1,
},
},
}
LordGarth
Here is a new code
numbers after math.random can be changed to desired healing range amount
defineSpell{
name = "earthheal",
uiName = "Earth Heal",
skill = "earth_magic",
requirements = { "earth_magic", 2 },
icon = 71,
spellIcon = 4,
gesture = 2547,
manaCost = 40,
description = "Conjures a wave of Earth energy that heals the party.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
--spell cast and tagged for the champion who cast it.
spawn("earthheal", party.level, party.x, party.y, party.facing, party.elevation)
local heal_amount = math.random(5,10)
for i=1,4 do
local c = party.party:getChampion(i)
if (c:getBaseStat("health") > 0) then
party.party:getChampion(i):modifyBaseStat("health", heal_amount)
else
party.party:getChampion(i):modifyBaseStat("health", 0)
end
hudPrint(champion:getName() .. " Healed the party by " .. heal_amount .. " points")
playSound("heal_party")
end
end
}
defineObject{
name = "earthheal",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "teleport_screen",
offset = vec(0, 1.5, 0),
},
{
class = "Light",
offset = vec(1.5, 1.0, 0),
color = vec(0.5, 0.5, 0.25),
brightness = 7,
range = 5,
fadeOut = 13,
disableSelf = true,
},
{
class = "CloudSpell",
attackPower = 0,
damageInterval = 2,
damageType = "fire",
duration = 1,
},
},
}
LordGarth
Dungeon Master and DOOM will live forever.
Re: Healing spell code
Why was this part kept? This bit of script checks for wall obstructions for burst and cloud attack spells. This targeted the party (for damage) if the player casts the spell at an adjacent wall. The dX and dY variables aren't even used further on in the script.LordGarth wrote:Code: Select all
local dX,dY = getForward(party.facing) --Directional offsets if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then dX,dY = 0,0 --Targets Party's cell if cast on a wall end
-
- Posts: 73
- Joined: Sun Apr 12, 2015 2:57 pm
Re: Healing spell code
Also wouldn't this also prevent the player from cancelling the spell because the code will see it instead being cast on a wall if you click on a blank space in the window?Isaac wrote:Why was this part kept? This bit of script checks for wall obstructions for burst and cloud attack spells. This targeted the party (for damage) if the player casts the spell at an adjacent wall. The dX and dY variables aren't even used further on in the script.LordGarth wrote:Code: Select all
local dX,dY = getForward(party.facing) --Directional offsets if party.map:isWall(party.x+dX, party.y+dY, party.elevation) then dX,dY = 0,0 --Targets Party's cell if cast on a wall end