Sanctuary of Gorgim: Scripting Help

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Duncan_B
Posts: 31
Joined: Wed Dec 19, 2012 8:43 pm
Location: Santa Cruz, Calif.-- USA

Sanctuary of Gorgim: Scripting Help

Post by Duncan_B »

Hello, all. My first adventure, Sanctuary of Gorgim, has been coming along nicely. I hope to have a first release out soon. However, there are a few things (6, actually) I've been scratching my head at. While I'm still trying to solve them, I thought I'd ask around and see if you guys could point me to threads where similar ideas have already been discussed. Or, if you'd like to offer me some code, I will make sure you are properly credited for your contribution.

Least essential, and probably easiest questions: is it possible to make a weapon do more damage/always hit against a particular type of enemy (say, a sword of snail slaying or something?). How do I get an item to destroy itself after being used (clicked on)?

Slightly more important, is there a way to restrict the use of healing crystals so that if the player is in light (e.g., holding a torch) they are not usable? After a certain point in the game, holding a torch should cause disease and drain health, but I'm not sure how to do that either.

Two more things I need that I haven't yet figured out... how can I write a script that will only execute if the party is facing a certain direction? I'm also looking for a way to automatically deactivate or prevent from activating any torch holder that has a burnt out torch in it.

Thanks in advance for your help. I'm sure I'll be back in a bit with questions about how to end the game properly!
User avatar
pferguso
Posts: 40
Joined: Tue Nov 06, 2012 6:09 pm

Re: Sanctuary of Gorgim: Scripting Help

Post by pferguso »

Duncan_B wrote: is it possible to make a weapon do more damage/always hit against a particular type of enemy (say, a sword of snail slaying or something?).
This is sort of how I tackled a problem like this.
First, create a script_entity on your dungeon, and call it "super_weapon_script." put the following in it:
SpoilerShow

Code: Select all

lastWeaponUsed = "none"
function getLastWeaponUsed()
	return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
	lastWeaponUsed = theWeapon.name
end
create a custom party object in your objects.lua, and put something like this:
SpoilerShow

Code: Select all

cloneObject{
       name = "party",
       baseObject = "party",
	onAttack = function(champion, weapon)
		local super_weapon_script = findEntity("super_weapon_script")
		if weapon == nil then
			return true
		end
		if super_weapon_script then
			super_weapon_script:setLastWeaponUsed(weapon)
                 end
        end,
  }
You can do a clone of a monster in your monsters.lua, and add a damage hook, like this:
SpoilerShow

Code: Select all

cloneObject{
	name = "my_spider",
	baseObject = "spider",
	health = 70,
	immunities = { "poison" },
	onDamage = function(monster, amount, damageType)
		if damageType == "physical" then
			local super_weapon_script = findEntity("super_weapon_script")
			if super_weapon_script then
				local my_weapon = "spiders_bane"
				if super_weapon_script:getLastWeaponUsed() == my_weapon then
					monster:setHealth(0)
				end
			end
		end
		return true
	end,
}
I hope this helps. on the last piece for the monster clone, make sure where it says "spiders_bane" that you use the name property of whatever your custom weapon us.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Sanctuary of Gorgim: Scripting Help

Post by Komag »

for the party direction, you can use party.facing, such as

Code: Select all

if party.facing == 0 then
   blah blah blah
end
(0 is north)
Finished Dungeons - complete mods to play
User avatar
Duncan_B
Posts: 31
Joined: Wed Dec 19, 2012 8:43 pm
Location: Santa Cruz, Calif.-- USA

Re: Sanctuary of Gorgim: Scripting Help

Post by Duncan_B »

Thanks for your replies. I've got the super_weapon_script and the item, monster, and party clones in, but spiders don't die when a character hits them with spider_knife (though I did make sure to specify the spider_knife in the monster.lua). Any thoughts on where it might be going wrong? I've copied and pasted my scripts in case one of them is messed up. Could having another party clone somehow be a problem?

Super weapon script:
SpoilerShow
lastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
Party clone:
SpoilerShow
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champion, weapon)
local super_weapon_script = findEntity("super_weapon_script")
if weapon == nil then
return true
end
if super_weapon_script then
super_weapon_script:setLastWeaponUsed(weapon)
end
end,
}
Item:
SpoilerShow
cloneObject{
name = "spider_knife",
baseObject = "knife",
uiName = "Spider Killing Knife",
model = "assets/models/items/knife.fbx",
description = "Not much of a weapon, but it can get rid of a spider, harr...",
skill = "daggers",
gfxIndex = 47,
attackPower = 5,
accuracy = -3,
coolDownTime = 3,
attackMethod = "meleeAttack",
attackSwipe = "vertical",
attackSound = "swipe_light",
impactSound = "impact_blade",
weight = 0.8,
}
Monster:
SpoilerShow
cloneObject{
name = "my_spider",
baseObject = "spider",
health = 70,
immunities = { "poison" },
onDamage = function(monster, amount, damageType)
if damageType == "physical" then
local super_weapon_script = findEntity("super_weapon_script")
if super_weapon_script then
local my_weapon = "spider_knife"
if super_weapon_script:getLastWeaponUsed() == my_weapon then
monster:setHealth(0)
end
end
end
return true
end,
}
Thanks for the tip on party facing. Unfortunately, grabbing a character name from the script eludes me.

Here's what I have:
SpoilerShow
function readsName1()
if party.facing == 0 then
party:getChampion(1)
-- hudPrint(champion:getName().." feels a chill at sensing the ancient engraving on this tomb reads...")
-- hudPrint(champion:getName().."!")
end end
User avatar
Asteroth
Posts: 471
Joined: Wed Oct 24, 2012 10:41 am
Location: Eastern U.S.

Re: Sanctuary of Gorgim: Scripting Help

Post by Asteroth »

Duncan_B wrote:Thanks for your replies. I've got the super_weapon_script and the item, monster, and party clones in, but spiders don't die when a character hits them with spider_knife (though I did make sure to specify the spider_knife in the monster.lua). Any thoughts on where it might be going wrong? I've copied and pasted my scripts in case one of them is messed up. Could having another party clone somehow be a problem?

Super weapon script:
SpoilerShow
lastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
Party clone:
SpoilerShow
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champion, weapon)
local super_weapon_script = findEntity("super_weapon_script")
if weapon == nil then
return true
end
if super_weapon_script then
super_weapon_script:setLastWeaponUsed(weapon)
end
end,
}
Item:
SpoilerShow
cloneObject{
name = "spider_knife",
baseObject = "knife",
uiName = "Spider Killing Knife",
model = "assets/models/items/knife.fbx",
description = "Not much of a weapon, but it can get rid of a spider, harr...",
skill = "daggers",
gfxIndex = 47,
attackPower = 5,
accuracy = -3,
coolDownTime = 3,
attackMethod = "meleeAttack",
attackSwipe = "vertical",
attackSound = "swipe_light",
impactSound = "impact_blade",
weight = 0.8,
}
Monster:
SpoilerShow
cloneObject{
name = "my_spider",
baseObject = "spider",
health = 70,
immunities = { "poison" },
onDamage = function(monster, amount, damageType)
if damageType == "physical" then
local super_weapon_script = findEntity("super_weapon_script")
if super_weapon_script then
local my_weapon = "spider_knife"
if super_weapon_script:getLastWeaponUsed() == my_weapon then
monster:setHealth(0)
end
end
end
return true
end,
}
Thanks for the tip on party facing. Unfortunately, grabbing a character name from the script eludes me.

Here's what I have:
SpoilerShow
function readsName1()
if party.facing == 0 then
party:getChampion(1)
-- hudPrint(champion:getName().." feels a chill at sensing the ancient engraving on this tomb reads...")
-- hudPrint(champion:getName().."!")
end end
Did he mean 'theWeapon.name' or should you have put in spider_knife(or whatever name)? See first script.
I am the God of darkness and corruption.
viewtopic.php?f=14&t=4250
User avatar
slackmg
Posts: 20
Joined: Fri Nov 09, 2012 12:21 am
Location: Here I am.

Re: Sanctuary of Gorgim: Scripting Help

Post by slackmg »

The dot notation needs to be used for calling functions in a script entity instead of ':'. Look at them as not really objects with functions, but objects with function properties.

Code: Select all

local super_weapon_script = findEntity("super_weapon_script")
 ...
super_weapon_script.setLastWeaponUsed(weapon)
  or
if super_weapon_script.getLastWeaponUsed() == my_weapon then
User avatar
Duncan_B
Posts: 31
Joined: Wed Dec 19, 2012 8:43 pm
Location: Santa Cruz, Calif.-- USA

Re: Sanctuary of Gorgim: Scripting Help

Post by Duncan_B »

I've changed the : to a . in the monster script, but still no dice. Perhaps I messed something up.
spider:
SpoilerShow
cloneObject{
name = "my_spider",
baseObject = "spider",
health = 70,
immunities = { "poison" },
onDamage = function(monster, amount, damageType)
if damageType == "physical" then
local super_weapon_script = findEntity("super_weapon_script")
if super_weapon_script then
local my_weapon = "spider_knife"
if super_weapon_script.getLastWeaponUsed() == my_weapon then
monster:setHealth(0)
end
end
end
return true
end,
}
super_weapon_script:
SpoilerShow
lastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
I'm also getting something strange from the knife now that I tried to change its model to a dagger. It looks like a dagger lying on the ground, but looks like a knife when I pick it up.
SpoilerShow
cloneObject{
name = "spider_knife",
baseObject = "dagger",
uiName = "Spider Killing Knife",
model = "assets/models/items/dagger.fbx",
description = "DEATH TO SPIDERS!",
skill = "daggers",
gfxIndex = 47,
attackPower = 5,
accuracy = -2,
coolDownTime = 3,
attackMethod = "meleeAttack",
attackSwipe = "vertical",
attackSound = "swipe_light",
impactSound = "impact_blade",
weight = 0.8,
}
Also, torches causing disease when held (not by default, but after some event) will be pretty important to the design of the dungeon. As compensation for the moment, I
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Sanctuary of Gorgim: Scripting Help

Post by msyblade »

On the dagger/knife, change the "gfxIndex" string to match the dagger.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
User avatar
Duncan_B
Posts: 31
Joined: Wed Dec 19, 2012 8:43 pm
Location: Santa Cruz, Calif.-- USA

Re: Sanctuary of Gorgim: Scripting Help

Post by Duncan_B »

msyblade wrote:On the dagger/knife, change the "gfxIndex" string to match the dagger.
Aha! Thank you.
User avatar
Duncan_B
Posts: 31
Joined: Wed Dec 19, 2012 8:43 pm
Location: Santa Cruz, Calif.-- USA

Re: Sanctuary of Gorgim: Scripting Help

Post by Duncan_B »

The spider killing knife shows up right, but still strikes spiders without killing. It's not an essential feature for the first release, so I don't want to get hung up on it. The more important things at the moment are printing a message that reports a character name (beyond starting a string with it) and a final torch puzzle which I'll explain.

(note: decided to go with disease causing torches as a rule rather than after an event, so consider it solved!)

The torch puzzle is a room with three torch holder objects. When the player puts a torch in a torch holder, report "[name of character in slot X] put in the [first/second/third] torch. It (still has fuel or burnt out)." Come to think of it, the character name from slot X should have to be called from the beginning of the game or else the names would change with the party formation, wouldn't they? I'm still not sure how to reference that or call on it. Same for whether or not torches have fuel.
Post Reply