Sanctuary of Gorgim: Scripting Help
Sanctuary of Gorgim: Scripting Help
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!
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!
Re: Sanctuary of Gorgim: Scripting Help
This is sort of how I tackled a problem like this.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?).
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
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,
}
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,
}
Re: Sanctuary of Gorgim: Scripting Help
for the party direction, you can use party.facing, such as
(0 is north)
Code: Select all
if party.facing == 0 then
blah blah blah
end
Finished Dungeons - complete mods to play
Re: Sanctuary of Gorgim: Scripting Help
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:
Party clone:
Item:
Monster:
Thanks for the tip on party facing. Unfortunately, grabbing a character name from the script eludes me.
Here's what I have:
Super weapon script:
SpoilerShow
lastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
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,
}
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,
}
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,
}
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,
}
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,
}
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,
}
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
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
Re: Sanctuary of Gorgim: Scripting Help
Did he mean 'theWeapon.name' or should you have put in spider_knife(or whatever name)? See first script.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:Party clone:SpoilerShowlastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
endItem:SpoilerShowcloneObject{
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,
}Monster:SpoilerShowcloneObject{
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,
}Thanks for the tip on party facing. Unfortunately, grabbing a character name from the script eludes me.SpoilerShowcloneObject{
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,
}
Here's what I have:SpoilerShowfunction 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
I am the God of darkness and corruption.
viewtopic.php?f=14&t=4250
viewtopic.php?f=14&t=4250
Re: Sanctuary of Gorgim: Scripting Help
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
Re: Sanctuary of Gorgim: Scripting Help
I've changed the : to a . in the monster script, but still no dice. Perhaps I messed something up.
spider:
super_weapon_script:
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.
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
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,
}
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,
}
SpoilerShow
lastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
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,
}
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,
}
Re: Sanctuary of Gorgim: Scripting Help
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
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Re: Sanctuary of Gorgim: Scripting Help
Aha! Thank you.msyblade wrote:On the dagger/knife, change the "gfxIndex" string to match the dagger.
Re: Sanctuary of Gorgim: Scripting Help
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.
(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.