Page 2 of 16
Re: Advanced scripting: a scripting framework
Posted: Thu Sep 27, 2012 10:14 pm
by djoldgames
@JKos: No problem, updated
I see, you're not deactivate the timer in illusion_walls entity and I added it, but much simpler: illusion_walls_timer:deactivate()
Yours, by using findEntity("illusion_walls_timer") is obviously better. Thanks!
Question: in framework.lua you (and I too) use clone cutom objects. Is there any reason for that? Can I clone these specified object in extra file myobjects.lua, and added it to init.lua before framework.lua?
Re: Advanced scripting: a scripting framework
Posted: Fri Sep 28, 2012 9:29 pm
by JKos
You can clone (or override) objects multiple times, it doesn't really matter if you clone your objects before or after my framework, at least if you don't modify the hooks in lua files. My framework just adds those hook-functions to original assets.
NEWS
I found an undocumented function script_entity:setSource() and was able to move all my scripts to single lua-file
I edited documentation to the first post of this thread. But basically you just need to include framework.lua to you init.lua and add few lines of code to script entity. It is now really easy to add this framework to existing mods.
Re: Advanced scripting: a scripting framework
Posted: Fri Sep 28, 2012 9:44 pm
by JKos
Sorry, I accidentally uploaded a non working version but now it should work.
EDIT:
BTW: You have to remove or rename script entities named: fw,help,data,monsters_can_open_doors,illusion_walls or damage_dealing_doors from you dungeon if you want to use this new version. Those are generated in runtime now.
Re: Advanced scripting: a scripting framework
Posted: Sat Sep 29, 2012 10:07 am
by JKos
There was a fatal bug: it wasn't working in game but only in editor, but now it's fixed and it should be safe to use. I also tested that it is savegame compatible.
Re: Advanced scripting: a scripting framework
Posted: Sat Sep 29, 2012 2:04 pm
by djoldgames
Thanks for updates.
For now I have a lot of new hooks using your framework.
Savegame compatibility: you're right, I need some refactoring my scripts, and defining all temporary function variables as "local"
In the entity "logfw_init" there is debug toggler: options.debug = true, but not working. Only way to enable/disable is in the framework.lua ?
Advanced script: Fake portcullis
Posted: Sat Sep 29, 2012 2:16 pm
by djoldgames
For my EOB mod, I need to create some portcullis, through that can player throwing items.
I created the fake portcullis (portcullis model as decoration) and on the party hook (onMove) block player move through them by spawning real portcullis for the short time period and destroy it after.
Working beautifull.
Code: Select all
activeThrowablePortcullis = {}
function activate()
fw.hooks.party.throwable_portcullis = {
onMove = function(self,dir)
for e in help.entitiesAtDir(self,dir) do
if ( (e.name == 'portcullis_throwable') and
e.facing == (dir + 2)%4) then
throwable_portcullis.doTheMagic(e)
end
end
for e in help.entitiesAtSameTile(self) do
if ( (e.name == 'portcullis_throwable') and
e.facing == dir) then
throwable_portcullis.doTheMagic(e)
end
end
end
}
fw.debugPrint("Throwable portcullis activated")
end
function doTheMagic(door)
local tmp = findEntity("throwable_portcullis_door")
if tmp then
tmp:destroy()
end
local portcullis = spawn("portcullis_secret_door", door.level, door.x, door.y, door.facing, "throwable_portcullis_door")
portcullis:setDoorState('closed')
local timer = findEntity("throwable_portcullis_door_timer")
if (not timer) then
timer = spawn("timer", door.level, door.x, door.y, door.facing, "throwable_portcullis_door_timer")
timer:setTimerInterval(0.5)
timer:addConnector('activate','throwable_portcullis','removeDoor')
end
timer:activate()
throwable_portcullis.activeThrowablePortcullis[portcullis.id] = portcullis
fw.debugPrint("Door spawned - "..portcullis.id)
end
function removeDoor()
for id,door in pairs(throwable_portcullis.activeThrowablePortcullis) do
-- fw.debugPrint("Door destroyed - "..door.id)
door:destroy()
throwable_portcullis.activeThrowablePortcullis[id] = nil
end
local timer = findEntity("throwable_portcullis_door_timer")
timer:deactivate()
end
Re: Advanced scripting: a scripting framework
Posted: Sat Sep 29, 2012 4:13 pm
by JKos
Yeah I tried to make it possible to enable debug in options table, but it was not so easy as tought it would be
so that option was left there accidentally. But you can enable debug mode by setting fw.debug.enabled = true inside any function, it doesn't work if you try to set it in initialize time, because fw-script entity is available only in runtime.
Example:
logfw_init
Code: Select all
options = {}
options.modules = {
monsters_can_open_doors = false,
damage_dealing_doors = false,
illusion_walls = true,
}
spawn("LoGFramework", 1,1,1,0,'fwInit')
fwInit:open()
fwInit:destroy()
-- call this to enable debug
function main()
fw.debug.enabled = true
-- add your code here
end
Can I ask how you did the fake portcullis? I think that would be perfect solution for illusion walls, much better than my scripting solution.
edit: Ah I got it, but it doesn't show on map as a wall, but i got an idea from your script how i could make illusion walls to be passable by monsters. I could just replace the illusion wall with fake illusion wall when monster is standing next to it and facing towards it. So walls would be revealed on map only if monster is next to wall and facing it. So thanks, I will try it.
A tip: I think you could just return false from fw.hooks.party.throwable_portcullis.onMove - function when party is trying to go trough portcullis_throwable and party movement will be cancelled, so you don't have to replace it with real portcullis.
Re: Advanced scripting: a scripting framework
Posted: Sat Sep 29, 2012 8:44 pm
by JKos
YES it works beautifully, monsters can now walk though illusion walls and you can attack through them. Wall will be opened if a monster comes close to it and stays open for 2 seconds, but graphically it just seems to be a solid wall all the time.
You can't shoot through them yet (if the wall is not already open), but it's totally doable.
It's possible to make pretty nasty jump scare scenes with this
a spider suddenly jumping through wall will scare a shit out of you.
just update framework.lua and you are good to go.
Re: Advanced scripting: a scripting framework
Posted: Sun Sep 30, 2012 12:18 am
by JKos
I added talk-script entity to demo-dungeon. Basically it adds a timed conversations to events. I think it's a good example what can be done with dynamic hooks.
I will add it to framework, but it's not ready yet, and it's easier to develop in script entities and then copy-paste to framework.lua.
Try it
It's updated to my google drive (link can be found from 1st post).
example
Code: Select all
talk.addTalkHook('spider_1','onDie','Die you 8 legged ugly bastard!',2)
it will print
Code: Select all
Random champion name: Die you 8 legged ugly bastard!
2 seconds after the death of the spider_1.
Re: LoG Framework (update: experimental turn based combat)
Posted: Sat Oct 06, 2012 10:07 pm
by JKos
Pretty big update this time, updated documentation to first post. I also renamed this thread.
Sorry djoldgames, this is not fully compatible with old version, you have to use fw.addHooks-function, so you can't add hooks directly anymore (fw.hooks.monster.etc={...}).