LoG Framework (dynamic hooks etc.)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 9 EoB spel

Post by JKos »

Ok, new update.

- Added light effects to spell projectiles (fireball,flame arrow, acid arrow and magic missile currently). It was pretty tricky, but solution was to spawn fx entity which moves at the same speed as the shot projectile. It works and it is not performance killer, as I thought it would be.
- added fireball spell
- added fw_fx script entity
- function fw_fx.addProjectileEffect(projectile,effectName,speed,onHitEffectName)
projectile = projectile entity
effectName = particle effect (eg. fireball)
speed = speed of the effect(must be same as the projectile)
onHitEffectName = particle effect which is played when projectile hits the target (or wall)
- added eob_spells.addSpellsToMonsters(monsterNamespace,spellName,amount,targets)
usage example: eob_spells.addSpellsToMonsters('snail','magic_missile',10,{'party','crowern'})
adds 10 magic missiles to each snail, and snails will use it against party and crowerns
- probably some other changes/fixes that I can't remeber

source of fw_fx, it can be used without the framework, so I thought I'd post it here.

Code: Select all

effects = {}
function addProjectileEffect(projectile,effectName,speed,onHitEffectName)
	local timer = spawn('timer',projectile.level,projectile.x,projectile.y,projectile.facing)
	local effect = spawn('fx',projectile.level,projectile.x,projectile.y,projectile.facing)
	effects[timer.id] = {}
	effects[timer.id].projectile_id = projectile.id
	effects[timer.id].effect_id =  effect.id
	effects[timer.id].x = 0
	effects[timer.id].y = 0
	effects[timer.id].onHitEffect= onHitEffectName
	
	local dx,dy = getForward(projectile.facing)
	dy = -1 * dy

	effects[timer.id].x = dx * 0.5
	effects[timer.id].y = dy * 0.5

	timer:addConnector('activate','fw_fx','move_effect')
	timer:setTimerInterval(0.5/speed)
	local light = getLightPreset(effectName)
	if light then
		effect:setLight(unpack(light))
	end
	
	effect:translate(0.5*dx,1,0.5*dy)
	effect:setParticleSystem(effectName)
	timer:activate()	
	return effect
end

function getLightPreset(preset)
	--FX:setLight(red, green, blue, brightness, range, time, castShadow)
	local s = {}
	s['fireball'] = {1, 0.5, 0.25,15,7,200,true} 
	s['fireball_hit'] = {1, 0.5, 0.25,40,7,1,true}
	s['magic_missile'] = {1, 1, 1,15,7,200,true}
	s['poison_bolt'] = {0.25, 0.6, 0.2,4,4,200,true}
	s['lightning_bolt_hit'] = {0.25, 0.5, 1,40,10,1,true}
	s['magic_missile_hit'] = {1, 1, 1,40,10,1,true}
	
	return s[preset]

end


function move_effect(timer)
	local e = effects[timer.id]
	local p = findEntity(e.projectile_id)

	local fx = findEntity(e.effect_id)
	if not p then
		if e.onHitEffect then
			local ohfx = spawn('fx',fx.level,e.px,e.py,fx.facing)
			ohfx:setParticleSystem(e.onHitEffect)
			ohfx:translate(0,1,0)
			local light = getLightPreset(e.onHitEffect)
			if light then
				ohfx:setLight(unpack(light))
			end			
		end
		effects[timer.id] = nil
		timer:deactivate()
		timer:destroy()
		fx:destroy()
		return
	end
	e.px = p.x
	e.py = p.y	
	fx:translate(e.x,0,e.y)	
end
You can add particle effects to any projectile in run time with it.

Updated demo dungeon to google drive: https://docs.google.com/open?id=0B7cR7s ... UN4SGZGNEk
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 10 EoB spe

Post by JKos »

Pretty big update this time.

- Added spell: haste (can select multiple targets)
- Added spell: lighning bolt (does damage to 2 tiles)
- Added spell: ice storm (does damage to cross-shaped area of 3x3 tiles)
- Added spell: cone of cold (does damage to 3 tiles in front of caster)
- Added fw_magic.defineSpell function. usage example:

Code: Select all

	fw_magic.defineSpell{
		name='lightning_bolt',
		level=3,
		projectile='spell_projectile',
		sound='lightning_bolt_launch',
		onHitSound='lightning_bolt_hit',
		particleEffect='lightning_bolt',
		onHitParticleEffect='lightning_bolt_hit',
		speed=14,
		area = {from={0,0},to={1,0}},
		damageType = 'shock',
		calculateDamage=function(caster)
			local damage = 6
			if caster.getOrdinal then
				damage = math.random(caster:getLevel(),caster:getLevel()*damage)	
			end	
			return damage
		end		
	}		
- Improved fw_magic.addSpellsToMonsters. You can now add multiple spells to monsters and can define cool down time and cast probability for each spell. Monster can't move or attack when cool down is active.
function addSpellsToMonsters(monsterNamespace,spellName,amount,targets,range,propability,cooldown)

Usage example:

Code: Select all

--snails have 20 lightning bolts and 20 magic_missiles and they will use them against party and crowerns.
		eob_spells.addSpellsToMonsters('snail','lightning_bolt',20,{'crowern','party'},5,0.3,3)	
		eob_spells.addSpellsToMonsters('snail','magic_missile',20,'{'crowern','party'},5,0.5,2)	
--crowerns have 20 acid arrows and 20 flame arrows and they will use them against party and snails.
		eob_spells.addSpellsToMonsters('crowern','melfs_acid_arrow',20,{'snail,'party'},5,0.2,3)	
		eob_spells.addSpellsToMonsters('crowern','flame_arrow',20,{'snail,'party'},5,0.6,2)	

--herders have 20 hold monster spells and they use it against crowerns and snails.
		eob_spells.addSpellsToMonsters('herder','hold_monster',20,{'crowern','snail'})	
Updated to google drive.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
8kin
Posts: 5
Joined: Wed Nov 07, 2012 1:04 pm

Re: Advanced scripting: a scripting framework

Post by 8kin »

HaunterV wrote:I wish I could understand what I'm looking at as well... I am still at the point of where I'm not sure I can just cut n paste or Do i have to modify what I'm seeing, if so what fields do i modify... this is all so terribly confusing.

But I shall try and hopefully this time next year it'll be second nature.

Don't worry I am with you on that one! This is a great community!
--
When you're a hammer, everything looks like a nail.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Complete code structure overhaul and documentation moved here:
https://sites.google.com/site/jkosgrimrock2/home
Documentation is not perfect you but it should cover all important features.

framework.lua was growing too big so I had to figure out a way to include script entities from separate lua-files. Now it's much more modular. Installation is a bit harder now, but it's really just download -> unzip -> include to init lua -> copy paste script entity. See documentation.

Demo dungeon is currently offline, I started to develop my first serious dungeon which uses the framework but I don't want to publish it yet.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
StaticZ
Posts: 10
Joined: Thu Nov 22, 2012 10:46 pm
Location: Russia

LoG Framework BUG

Post by StaticZ »

there is little bug - as I notice LOG engine use very low preority for scripts that are in on other levels than player, so all code from other levels get large lug... For example i used "talk"module and my text messages orinted in 5 seconds, thow I set interval 1. When i change: spawn('timer',1,0,0,0,'talk_timer') to spawn('timer',party.level,0,0,0,'talk_timer') in recreateTimer() all works fine... But there are still problem with initing first timer. I think same problem can be related to other modules - we need to move log framework objects with player from level to level to make it work fine, but now i can't see nice way to do it.


PS also i advice to add such function to framework:

Code: Select all

function delayCall(interval,callback,callbackargs)
	if callbackargs == nill then callbackargs = {} end
	fw.repeatFunction(1, interval, callbackargs, callback, false)
end
as for me it's very simple and usefull
Game isn't a dream, it is the reality, reality which is coming while we dream...
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Hi, and thanks for the feedback, It's nice to see that someone uses this stuff. I'm aware of that problem and that's why I developed this: viewtopic.php?f=14&t=4350
It's a timer which stays in time regardless of the dungeon level. Next release will have that timer included and talk script will use it. Maybe I'll do the update today, no promises though :)

Edit: Hmm, I read your post again, and it seems that there could be other problems too, I have to test how it works with deep dungeons. I hope I don't have to throw everything in thrash bin. :shock:
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Ok, I tested it with 20 levels deep dungeon and it seems to work fine with the extended timer. So back to work :)
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
StaticZ
Posts: 10
Joined: Thu Nov 22, 2012 10:46 pm
Location: Russia

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by StaticZ »

Ok, I'm glad to hear that the work is in progress ))
For me your work was best quick tutorial to lua scripting, but i still cant understand difference beetween script_entry.foo() and script_entry:foo() all are working, thow the first variant ger error if there are arguments because it always make 1st argument as table type... Anyway thanks for work - very good and useful project, thow api not perfect, for example there are no function to clear "queue" in talk module, so it's impossible to interupt dialogue ))
Game isn't a dream, it is the reality, reality which is coming while we dream...
User avatar
StaticZ
Posts: 10
Joined: Thu Nov 22, 2012 10:46 pm
Location: Russia

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by StaticZ »

Also when using calback make calbackargs not mandatory argument. Very often we don't need functions with arguments )

By the way I think in setup manual you have to write some words about using it in multi level dungeon. As for me it was first quastion have I add LogFravwork object to each level or only for 1st? I think other people can also have such quastion ))

And one more thing - I creating little non classic dungeon and my advantage start at 8th level not 1st, and editor crashing if I put LoG Framework object from 1st to 8th level. It's not critical but I think you also need to write about it in "setup manual"
Game isn't a dream, it is the reality, reality which is coming while we dream...
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

For me your work was best quick tutorial to lua scripting, but i still cant understand difference beetween script_entry.foo() and script_entry:foo() all are working,
Thanks, I guess that's because I was a lua beginner when I started this project, so the first scripts are not that complicated or fancy :) I have many years of php and javascript experience though, so if you are familiar with those then maybe my scripts could be easy to understand for you. I would't say that it's the "best" because there probably is some really stupid solutions. Talk script for example could be written much better way, but it works, so I don't mind :)

About .foo() and :foo() see: http://lua-users.org/wiki/ObjectOrientationTutorial Method Delaration

and clearQueue is a good idea.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
Post Reply