LoG Framework (dynamic hooks etc.)

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

LoG Framework (dynamic hooks etc.)

Post by JKos »

Last edited by JKos on Mon Mar 25, 2013 9:35 pm, edited 40 times in total.
- 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
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Advanced scripting: a scripting framework

Post by Neikun »

You're going to go a long way in this community. I can tell. :D
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Advanced scripting: a scripting framework

Post by JKos »

Almost completely rewrote the framework today (i'm still learning lua...and grimrock scripting), but idea is the same.

Just quick examples, have to go to sleep :)

It's now possible register common hooks for all monsters or doors and a class-specific hooks (by entity.name) and even entity-specific hooks (by entity.id)

Code: Select all

-- Common hook for all monsters
fw.hooks.monsters.mod_name = {
   onMove = function(self,dir)
     fw.debugPrint("All monsters get this")
   end
} 
-- class specific hook
fw.hooks.snail.mod_name = {
   onMove = function(self,dir)
       fw.debugPrint("All snails get this")
   end
} 

-- entity specific hook
fw.hooks.snail_1.mod_name = {
   onMove = function(self,dir)
fw.debugPrint("Only snail_1 get this")
   end
} 

Updated my demo and now there is example how to enable and disable hooks on the fly . You can toggle "damage-dealing doors" and/or "monsters can open doors"-mods by pressing buttons on wall. The code is much better now IMO.

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: Advanced scripting: a scripting framework

Post by JKos »

Added dungeon_illusion_wall-asset to framework. Pure scripting solution so you can use it like any other door in editor, just select and place to right position, no hidden plates or anything.

updated to google drive.

illusion_walls-script entity (uses framework, won't work without it)

Code: Select all

activeWalls = {}

function activate()

	fw.hooks.party.illusion_walls = {
		onMove = function(self,dir)
			if dir ~= self.facing then return end
			for e in help.entitiesAtAhead(self) do
				if (e.name == 'dungeon_illusion_wall' and e.facing == help.getOppositeFacing(self)) then
					illusion_walls.doTheMagic(e)
				end
			end
			for e in help.entitiesAtSameTile(self) do
				if (e.name == 'dungeon_illusion_wall' and e.facing == e.facing) then
					illusion_walls.doTheMagic(e)
				end
			end			
			
		end
	}
	fw.debugPrint("illuson walls activated")
end

function doTheMagic(wall)
	wall:setDoorState('open')
					
	timer = findEntity("illusion_walls_timer")
	if (not timer) then
		timer = spawn("timer", wall.level, wall.x, wall.y, wall.facing, "illusion_walls_timer")
		timer:setTimerInterval(0.4)
		timer:addConnector('activate','illusion_walls','closeWalls')		
	end

	timer:activate()
	illusion_walls.activeWalls[wall.id] = wall

end

function closeWalls()
	for id,wall in pairs(illusion_walls.activeWalls) do
		wall:setDoorState('closed')
		illusion_walls.activeWalls[id] = nil
	end

end
framework.lua

Code: Select all

cloneObject{
	name = "dungeon_illusion_wall",
	baseObject = "dungeon_secret_door",
}

- 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: Advanced scripting: a scripting framework

Post by JKos »

I'm not sure if anyone is interested (based on the enormous amount of replies :) ) but I improved illusion walls, and now they are almost perfect. You can move through them sideways or backwards and the effect is much better now, they don't seem to disappear any more, it really looks that you are walking through them (trick was to set closing timer to 0.01s).

Updated to google drive. Just try it.
- 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
HaunterV
Posts: 676
Joined: Mon Apr 16, 2012 9:54 pm
Location: Barrie, Ontario, Canada

Re: Advanced scripting: a scripting framework

Post by HaunterV »

This stuff is brilliant.
Grimrock Community 'FrankenDungeon 2012. Submit your entry now!: http://tinyurl.com/cnupr7h
SUBMIT YOUR ASSETS! Community Asset Pack (C.A.P.): http://tinyurl.com/bqvykrp
Behold! The HeroQuest Revival!: http://tinyurl.com/cu52ksc
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Advanced scripting: a scripting framework

Post by Neikun »

Your thread is in the EDITINg SUPER THREAD.
I'd post feedback, but this level of scripting currently goes over my head.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
HaunterV
Posts: 676
Joined: Mon Apr 16, 2012 9:54 pm
Location: Barrie, Ontario, Canada

Re: Advanced scripting: a scripting framework

Post by HaunterV »

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.
Grimrock Community 'FrankenDungeon 2012. Submit your entry now!: http://tinyurl.com/cnupr7h
SUBMIT YOUR ASSETS! Community Asset Pack (C.A.P.): http://tinyurl.com/bqvykrp
Behold! The HeroQuest Revival!: http://tinyurl.com/cu52ksc
User avatar
djoldgames
Posts: 107
Joined: Fri Mar 23, 2012 11:28 pm
Contact:

Re: Advanced scripting: a scripting framework

Post by djoldgames »

Your framework is awsome. Thank you, especialy for the dungeon.lua script to download. You open my eyes in grimrock scripting structure.

With it I create some new and much clearer rotators (for my EOB Mod):
New entities (cloned teleports) for the party rotation on same title in 90/180/270 degres:

added to framework.lua

Code: Select all

cloneObject{
	name = "teleporter_rotator90",
	baseObject = "teleporter",
}
cloneObject{
	name = "teleporter_rotator180",
	baseObject = "teleporter",
}
cloneObject{
	name = "teleporter_rotator270",
	baseObject = "teleporter",
}
added to script entity with ID = party_rotators

Code: Select all

function activate()

	fw.hooks.party.party_rotator = {
		onMove = function(self,dir)
			for e in help.entitiesAtDir(self,dir) do
				if e.name == 'teleporter_rotator90' then					
					e:setTeleportTarget(e.x, e.y, (self.facing + 1)%4)
					fw.debugPrint("Party rotated by 90")
				end
				if e.name == 'teleporter_rotator180' then					
					e:setTeleportTarget(e.x, e.y, (self.facing + 2)%4)
					fw.debugPrint("Party rotated by 180")
				end
				if e.name == 'teleporter_rotator270' then					
					e:setTeleportTarget(e.x, e.y, (self.facing + 3)%4)
					fw.debugPrint("Party rotated by 270")
				end
			end
			
		end
	}
	fw.debugPrint("Teleporter rotators activated")
end
party_rotators.activate()
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Advanced scripting: a scripting framework

Post by JKos »

Thanks guys, I did't notice that this was in the Superthred, I guess at least somebody is reading what i'm typing here :).
It's just nice to know that I'm not just blabbering by myself.

djoldgames: Great if you think it's helpful to you, but I have bad news for you: you have to update it :)
I forgot to put return-statements to all those hooks in framework.lua and illusion wall timer was running all the time in 0.01 seconds interwall (which eats cpu cycles in vain).
Those are fixed.
And I also copy-pasted original monster-hooks from asset-pack to fw-script entity. Those were of course overridden by my framework, so for example spiders didn't do poison attacks.

So you have to update at least framework.lua and script-entities: fw and illusion_walls

And I suggest that you do your own lua file for your own modifications and include it to init.lua after framework.lua. And if possible don't modify my script-entites either, updating to new version would be much easier that way. I wish I could write all core framework-code to lua-files, for easier integration to other mods, but It's not possible.

I think I'm going to take a look on spells next, and see if I can do something nice and useful with them.
- 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