Party scripting hooks

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Jgwman
Posts: 144
Joined: Thu Jun 28, 2012 10:14 pm

Party scripting hooks

Post by Jgwman »

I never messed with the scripting hooks for the party in LoG 1; can someone explain to me in which lua file you defined the callbacks for party hooks in LoG 1, and an example?
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Party scripting hooks

Post by SnowyOwl47 »

Jgwman wrote:I never messed with the scripting hooks for the party in LoG 1; can someone explain to me in which lua file you defined the callbacks for party hooks in LoG 1, and an example?
party_hooks.lua we created our own file then imported it in the init.lua

But in the party_hooks.lua we had to define the party and add somethings:

viewtopic.php?f=14&t=5803&hilit=+hook

But that is just for LOG1 we'd have to port it over to LOG2
User avatar
Jgwman
Posts: 144
Joined: Thu Jun 28, 2012 10:14 pm

Re: Party scripting hooks

Post by Jgwman »

Cool. I'll look into it tonight. Thanks.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Party scripting hooks

Post by JKos »

I made some quick testing with old party hook-names and here are the results (and an example of defining party-hooks):
Main difference to LoG1 is that all hooks receive party-object as a first argument.
(And you can define objects in any .lua file which is imported to init.lua)

Code: Select all

defineObject{
   name = "party",
   baseObject = "party",
   components = {
      {
        class = "Party",
		-- WORKS
		onMove = function(party,dir,arg1) 
			print(party.go.id,"moving to",dir) 
		end,
		-- WORKS
		onTurn = function(party,dir,arg1) 
			print(party.go.id,"turning to",dir) 
		end,
		-- WORKS (NOT with bare hands)
		onAttack = function(party,champion,weapon) 
			print(champion:getName(),'is attacking with',weapon.go.id) 
		end,
		-- WORKS
		onDamage = function(party, champion,damage,damageType) 
			print(party.go.id, champion:getName(), 'received damage', damage,damageType) 
		end,
		-- WORKS
		onProjectileHit = function(party,champion,projectile,damage,damageType) 
			print(party.go.id,champion:getName(),'is hit by a',projectile.go.name,damage,damageType) 
		end,				
		-- WORKS
		onDie = function(party,champion) 
			print(party.go.id,champion:getName(),'died') 
		end,
		-- WORKS
		onRest = function(party) 
			print(party.go.id,'is resting') 
		end,
		-- WORKS
		onWakeUp = function(party) 
			print(party.go.id,'woke up') 
		end,
		-- NOT WORKING (Also tested onDrawUI,onDrawGUI,onDraw,onDrawAll but no luck)
		onDrawGui = function(g) print('gui') end, 
		-- WORKS
		onDrawInventory = function(g,champion) 
			--print('inventory') 
		end, 
		-- WORKS
		onDrawStats = function(g,champion) print('stats') end, 
		-- NOT WORKING
		onDrawSkills = function(g,champion) print('skills') end, 
		-- NOT WORKING
		onDrawTraits = function(g,champion) print('traits') end, 
		
		-- UNTESTED

		onUseItem = function(party,champion,item,slot) 
			print(party.go.id,champion:getName(),'is using',item,slot) 
		end,		
		onReceiveCondition = function(party,champ,condition,condNumber) end, 
		onCastSpell = function(party,champion,spellName) end,
		onLevelUp = function(party,champion) end,
		onPickUpItem = function(party,item) end
      }
   },
}

- 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
Jgwman
Posts: 144
Joined: Thu Jun 28, 2012 10:14 pm

Re: Party scripting hooks

Post by Jgwman »

JKos wrote:I made some quick testing with old party hook-names and here are the results (and an example of defining party-hooks):
Main difference to LoG1 is that all hooks receive party-object as a first argument.
(And you can define objects in any .lua file which is imported to init.lua)

Code: Select all

defineObject{
   name = "party",
   baseObject = "party",
   components = {
      {
        class = "Party",
		-- WORKS
		onMove = function(party,dir,arg1) 
			print(party.go.id,"moving to",dir) 
		end,
		-- WORKS
		onTurn = function(party,dir,arg1) 
			print(party.go.id,"turning to",dir) 
		end,
		-- WORKS (NOT with bare hands)
		onAttack = function(party,champion,weapon) 
			print(champion:getName(),'is attacking with',weapon.go.id) 
		end,
		-- WORKS
		onDamage = function(party, champion,damage,damageType) 
			print(party.go.id, champion:getName(), 'received damage', damage,damageType) 
		end,
		-- WORKS
		onProjectileHit = function(party,champion,projectile,damage,damageType) 
			print(party.go.id,champion:getName(),'is hit by a',projectile.go.name,damage,damageType) 
		end,				
		-- WORKS
		onDie = function(party,champion) 
			print(party.go.id,champion:getName(),'died') 
		end,
		-- WORKS
		onRest = function(party) 
			print(party.go.id,'is resting') 
		end,
		-- WORKS
		onWakeUp = function(party) 
			print(party.go.id,'woke up') 
		end,
		-- NOT WORKING (Also tested onDrawUI,onDrawGUI,onDraw,onDrawAll but no luck)
		onDrawGui = function(g) print('gui') end, 
		-- WORKS
		onDrawInventory = function(g,champion) 
			--print('inventory') 
		end, 
		-- WORKS
		onDrawStats = function(g,champion) print('stats') end, 
		-- NOT WORKING
		onDrawSkills = function(g,champion) print('skills') end, 
		-- NOT WORKING
		onDrawTraits = function(g,champion) print('traits') end, 
		
		-- UNTESTED

		onUseItem = function(party,champion,item,slot) 
			print(party.go.id,champion:getName(),'is using',item,slot) 
		end,		
		onReceiveCondition = function(party,champ,condition,condNumber) end, 
		onCastSpell = function(party,champion,spellName) end,
		onLevelUp = function(party,champion) end,
		onPickUpItem = function(party,item) end
      }
   },
}

Thanks JKos! That's great!
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Party scripting hooks

Post by cromcrom »

Yep, thanks a lot JKos
A trip of a thousand leagues starts with a step.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Party scripting hooks

Post by NutJob »

Fantastic! Appreciation Station!

Is anyone aware of an event that's triggered by putting an item into inventory? event(p,champ,item)

I've tried quite a few now: onDropItem, onDropItemInventory, onSetDownItem, onAquireItem plus a few more embarrassing ones. =)
Post Reply