Page 1 of 1

Need Help on open doors with my Zo-Spell

Posted: Sat Mar 12, 2016 4:01 pm
by Illidan
I am new to modding and I am not that high level in lua scripting, although I learned already a bit about scripting.

Now to my problem.
I successfully created a Zo-spell to open doors in Grimrock 2.
I am already able to open with it a special named door with the id "zo".
But I want to be able to open doors with more than one "zo"-id. I want to open doors with id-numbers from 1 to 500 (so on projectile hit, one door with the id zo_1 or zo_2 or zo_3 etc. shall open).
That's because I need many ids to place up to 500 doors with a "zo"-id in my custom dungeon which are openable by my spell.
The problematic spript part is written in yellow and I need it modified to my needs.
Please help!

Here is my script.
My Zo Spell:

defineSpell{
name = "zo_spell",
uiName = "Zo Spell",
skill = "concentration",
gesture = 8,
manaCost = 20,
icon = 100,
spellIcon = 20,
requirements = { "concentration", 1 },
description = "A bolt of magical negative energy which can open a door from a distance.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local s = spawn("zo_spell",party.level,party.x,party.y,party.facing)
s.projectile:setIgnoreEntity(party)
s.projectile:setAttackPower(0)
end
}

defineObject{
name = "zo_spell",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "zo_spell",
},
{
class = "Light",
color = vec(0.6, 0.6, 0.6),
brightness = 10,
range = 4,
castShadow = true,
},
{
class = "Projectile",
spawnOffsetY = 1.35,
velocity = 10,
radius = 0.1,
hitEffect = "zo_spell_blast",
onProjectileHit = function(self, what, entity)
self.go:playSound("zo_spell_hit")
if what == "entity" and entity.id == "zo" then
entity.door:toggle()
end
end,

},
{
class = "Sound",
sound = "blob",
},
{
class = "Sound",
name = "launchSound",
sound = "silence",
},
},
}

defineObject{
name = "zo_spell_blast",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "zo_spell_hit",
destroyObject = false,
},
{
class = "Light",
color = vec(0.6, 0.6, 0.6),
brightness = 12,
range = 7,
fadeOut = 0.5,
disableSelf = true,
},
{
class = "TileDamager",
attackPower = 0,
damageType = "shock",
sound = "blob_hit",
},
},
}

defineSound{
name = "blob",
filename = "assets/samples/magic/blob_01.wav",
loop = true,
volume = 0.1,
minDistance = 1,
maxDistance = 10,
}

defineSound{
name = "silence",
filename = "assets/samples/magic/dark_bolt_launch_01.wav",
loop = false,
volume = 1,
minDistance = 1,
maxDistance = 10,
}

defineSound{
name = "zo_spell_hit",
filename = "assets/samples/magic/dark_bolt_hit_01.wav",
loop = false,
volume = 1,
minDistance = 2,
maxDistance = 10,
}


defineParticleSystem{
name = "zo_spell",
emitters = {
{
emissionRate = 15,
emissionTime = 0,
maxParticles = 1000,
boxMin = { 0,0,0 },
boxMax = { 0,0,0 },
sprayAngle = {0,360},
velocity = {0,0},
objectSpace = true,
texture = "mod_assets/dmcsb_pack/textures/particles/exsp_zo_spell.tga",
frameRate = 4,
frameSize = 256,
frameCount = 4,
lifetime = {0.1,0.3},
color0 = {1.5,1.5,1.5},
opacity = 0.1,
fadeIn = 0.1,
fadeOut = 0.1,
size = {0.125, 0.5},
gravity = {0,0,0},
airResistance = 5,
rotationSpeed = 1,
blendMode = "Additive",
},

-- core
{
emissionRate = 10,
emissionTime = 0,
maxParticles = 1000,
boxMin = { 0,0,0 },
boxMax = { 0,0,0 },
sprayAngle = {0,360},
velocity = {0,0},
objectSpace = true,
texture = "mod_assets/dmcsb_pack/textures/particles/exsp_zo_spell.tga",
frameRate = 4,
frameSize = 256,
frameCount = 4,
lifetime = {0.1,0.3},
color0 = {1.5,1.5,1.5},
opacity = 0.8,
fadeIn = 0.1,
fadeOut = 0.1,
size = {0.15, 0.6},
gravity = {0,0,0},
airResistance = 5,
rotationSpeed = 1,
blendMode = "Additive",
},

-- glow
{
spawnBurst = true,
emissionRate = 1,
emissionTime = 0,
maxParticles = 1,
boxMin = {0,0,0.0},
boxMax = {0,0,0.0},
sprayAngle = {0,30},
velocity = {0,0},
texture = "assets/textures/particles/glow.tga",
lifetime = {1000000, 1000000},
colorAnimation = true,
color0 = {1,0.5,0.5},
color1 = {0.5,1.,0.5},
color2 = {0.5,0.5,0.1},
color3 = {1,1,0.5},
opacity = 0.1,
fadeIn = 0.1,
fadeOut = 0.1,
size = {0.4, 0.6},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 2,
blendMode = "Additive",
objectSpace = true,
}
}
}

defineParticleSystem{
name = "zo_spell_hit",
emitters = {
-- sparks
{
emissionRate = 80,
emissionTime = 0.3,
maxParticles = 30,
boxMin = {-0.5, -0.5, -0.5},
boxMax = { 0.5, 0.5, 0.5},
sprayAngle = {0,360},
velocity = {0,0},
objectSpace = false,
texture = "mod_assets/dmcsb_pack/textures/particles/exsp_zo_spell.tga",
frameRate = 4,
frameSize = 256,
frameCount = 4,
lifetime = {0.2,0.5},
color0 = {2.5,2.5,2.5},
opacity = 1,
fadeIn = 0.1,
fadeOut = 0.3,
size = {0.3, 1.4},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 0,
blendMode = "Additive",
},

-- glow
{
spawnBurst = true,
emissionRate = 1,
emissionTime = 0,
maxParticles = 1,
boxMin = {0,0,-0.1},
boxMax = {0,0,-0.1},
sprayAngle = {0,30},
velocity = {0,0},
texture = "assets/textures/particles/glow.tga",
lifetime = {0.5, 0.5},
colorAnimation = false,
color0 = {1, 1, 1},
opacity = 0.5,
fadeIn = 0.01,
fadeOut = 0.5,
size = {1, 1},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 2,
blendMode = "Additive",
}
}
}

Re: Need Help on open doors with my Zo-Spell

Posted: Sat Mar 12, 2016 4:39 pm
by Dr.Disaster
err .. if you want a Zo Spell then why aren't you modifying the LoG 2 "Open Door" spell listed inside the 1st Asset Pack to your liking?

Re: Need Help on open doors with my Zo-Spell

Posted: Sat Mar 12, 2016 7:40 pm
by Illidan
@Dr. Disaster

That hint isn't helpfull.
I know that an "OpenDoor" spell exists in the 1st Asset Pack, but there stands the same in the open_door.lua as in my zo_spell script.
The following is written in the open_door.lua of the 1st Asset Pack:

class = "Projectile",
spawnOffsetY = 1.35,
velocity = 10,
radius = 0.1,
hitEffect = "open_door_blast",
onProjectileHit = function(self, what, entity)
self.go:playSound("serpent_staff_blast")
if what == "entity" and entity.name == "tomb_door_serpent" then
entity.door:toggle()
end
end,


So, this doesn't help me with my problem with more than one zo-id for the doors.
Again: I need a correct script to open a door not for one entity.name like "tomb_door_serpent", but for opening doors with the entity.ids "zo1"..."zo500".
This I don't know how to script correctly because my lua scripting is not that good.

Can you tell me how to scipt it correctly? Any help would be welcome.

Re: Need Help on open doors with my Zo-Spell

Posted: Sat Mar 12, 2016 8:35 pm
by Dr.Disaster
If i want a spell to open one specific door then i might use entity.id i.e. entity.id == "zo_door_1"
but if i want a spell to open several doors, maybe even hundreds of them, then entity.id is off the table

Re: Need Help on open doors with my Zo-Spell

Posted: Sat Mar 12, 2016 8:42 pm
by Zo Kath Ra
You need to use string.find
http://lua-users.org/wiki/StringLibraryTutorial

Replace:
if what == "entity" and entity.id == "zo" then
With:
if what == "entity" and (string.find(entity.id, "zo") == 1) then

This code searches for the string "zo" in "zo500" (or whatever the entity's ID happens to be).
Position 1 is the first character of the string.

Re: Need Help on open doors with my Zo-Spell

Posted: Sat Mar 12, 2016 9:48 pm
by Illidan
Thank you so much Zo Kath Ra!
That did it! That was exactly what I needed!
The StringLibraryTutorial will also help me in the near future, thanx for the link.

And thank you, too, Dr. Disaster!
Thank you all for the fast help.

At the moment, I am creating a new Dungeon Master Clone (I hope nobody else is making one, or has it already done? :mrgreen: ), but this time for Grimrock 2.
It is 70% finished. The Spell was important for the DM-Experience. :D
I am trying to make some new monsters like a Giant Rat and a Giant Skorpion, because in modelling and Photoshop I am better than in scripting. ;)
But, sadly, it depends on my little spare time. :x