Healing spell code

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Healing spell code

Post 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,



},

},
}
Last edited by LordGarth on Sat Dec 03, 2016 2:01 am, edited 1 time in total.
Dungeon Master and DOOM will live forever.
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Healing spell code

Post by alois »

Try party.party:getChampion(i) :)

Alois :)
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Healing spell code

Post by LordGarth »

will try thankyou

LordGarth
Dungeon Master and DOOM will live forever.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Healing spell code

Post 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 :/
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Healing spell code

Post by THOM »

...well - he is asking for to learn what to learn... 8-)
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Healing spell code

Post 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/
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Healing spell code

Post 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
Dungeon Master and DOOM will live forever.
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Healing spell code

Post 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
Dungeon Master and DOOM will live forever.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Healing spell code

Post 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.
Killcannon
Posts: 73
Joined: Sun Apr 12, 2015 2:57 pm

Re: Healing spell code

Post 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?
Post Reply