Page 1 of 16
LoG Framework (dynamic hooks etc.)
Posted: Sun Sep 23, 2012 12:18 am
by JKos
Re: Advanced scripting: a scripting framework
Posted: Sun Sep 23, 2012 1:15 am
by Neikun
You're going to go a long way in this community. I can tell.
Re: Advanced scripting: a scripting framework
Posted: Sun Sep 23, 2012 11:00 pm
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
Re: Advanced scripting: a scripting framework
Posted: Mon Sep 24, 2012 10:26 pm
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",
}
Re: Advanced scripting: a scripting framework
Posted: Tue Sep 25, 2012 8:14 pm
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.
Re: Advanced scripting: a scripting framework
Posted: Tue Sep 25, 2012 8:22 pm
by HaunterV
This stuff is brilliant.
Re: Advanced scripting: a scripting framework
Posted: Wed Sep 26, 2012 1:33 am
by Neikun
Your thread is in the EDITINg SUPER THREAD.
I'd post feedback, but this level of scripting currently goes over my head.
Re: Advanced scripting: a scripting framework
Posted: Wed Sep 26, 2012 11:18 pm
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.
Re: Advanced scripting: a scripting framework
Posted: Thu Sep 27, 2012 12:51 pm
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()
Re: Advanced scripting: a scripting framework
Posted: Thu Sep 27, 2012 7:36 pm
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.