Page 1 of 2

Healing spell code

Posted: Fri Dec 02, 2016 4:07 pm
by LordGarth
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,



},

},
}

Re: Healing spell code

Posted: Fri Dec 02, 2016 4:41 pm
by alois
Try party.party:getChampion(i) :)

Alois :)

Re: Healing spell code

Posted: Fri Dec 02, 2016 4:43 pm
by LordGarth
will try thankyou

LordGarth

Re: Healing spell code

Posted: Fri Dec 02, 2016 5:02 pm
by zimberzimber
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

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)
In the following code...

Code: Select all

for i=1,4 do
champion:modifyBaseStat("health", heal_amount)
end
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.

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 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.

Code: Select all

local p = party:spawn("particle_system")
p.particle:setParticleSystem("myparticlesystem")
p.particle:setOffset(vec(x,y,z))
Or if it's something like the teleport screen effect you can use

Code: Select all

party.party.playScreenEffect("myparticlesystem")
You should really learn some basics :/

Re: Healing spell code

Posted: Fri Dec 02, 2016 5:22 pm
by THOM
...well - he is asking for to learn what to learn... 8-)

Re: Healing spell code

Posted: Fri Dec 02, 2016 6:19 pm
by Isaac
THOM wrote:...well - he is asking for to learn what to learn... 8-)
Indeed.

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

Posted: Sat Dec 03, 2016 1:58 am
by LordGarth
alois wrote:Try party.party:getChampion(i) :)

Alois :)
Works great with the above code

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

Re: Healing spell code

Posted: Sat Dec 03, 2016 5:45 am
by LordGarth
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

Re: Healing spell code

Posted: Sat Dec 03, 2016 5:56 am
by Isaac
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 
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.

Re: Healing spell code

Posted: Sat Dec 03, 2016 8:21 am
by Killcannon
Isaac wrote:
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 
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.
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?