Page 1 of 3
Making magical melee weapons
Posted: Sun Nov 04, 2012 5:31 pm
by LordGarth
Hello all
Why does the champ spawn fireburst all the time with this code and not just with the fblong_sword?
defineObject{
name = "party",
class = "Party",
editorIcon = 32,
onAttack = function(champ, fblong_sword)
if party.facing == 0 then
spawn("fireburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("fireburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("fireburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("fireburst", party.level, party.x-1, party.y, party.facing)
end
end
}
Re: Making magical melee weapons
Posted: Sun Nov 04, 2012 5:48 pm
by Xanathar
First of all, I would avoid using defineObject with party.. it's one of those cases where I would follow the cloneObject good-practice closely since party is not a trivial object.
That said, the "words" in the function declaration aren't "filters" are just symbolic names given to the parameters.
You have to do something like (not-tested):
Code: Select all
onAttack = function(champ, weapon)
if (weapon.name == "fblong_sword") then
if party.facing == 0 then
spawn("fireburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("fireburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("fireburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("fireburst", party.level, party.x-1, party.y, party.facing)
end
end
end
Re: Making magical melee weapons
Posted: Sun Nov 04, 2012 6:07 pm
by LordGarth
The game crashes with no error report when unarmed attack.
LG
Re: Making magical melee weapons
Posted: Sun Nov 04, 2012 6:15 pm
by Xanathar
if (weapon ~= nil) and (weapon.name == "fblong_sword") then
Re: Making magical melee weapons
Posted: Sun Nov 04, 2012 6:22 pm
by LordGarth
Great now I can make lots of magical melee weapons that will do melee and magical damage at the same time. And I can make enchantment potions to turn regular melee weapons to magical ones.
The enchantment does not run out though. I wonder how to put in charges if that is possible.
Thx a bunch,
LG
Re: Making magical melee weapons
Posted: Sun Nov 04, 2012 8:55 pm
by LordGarth
Great now the Ice longsword, Ice warhammer, Ice battleaxe cast frostburst on attack and the magma longsword, battleaxe and warhammer cast fireburst on attack.
Torch casts fireburst on attack as well.
LG
Re: Making magical melee weapons
Posted: Tue Nov 06, 2012 3:08 pm
by akroma222
Hey guys,
I'm trying to get your code to work, but nothing happens when I swing 'ice_sabre' in any direction...
I have used this code (yours I think, if I pieced it together correctly):
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champ, weapon)
if (weapon ~= nil) and (weapon.name == "fblong_sword") then
if party.facing == 0 then
spawn("frostburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("frostburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("frostburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("frostburst", party.level, party.x-1, party.y, party.facing)
end
end
end,
}
I have pasted this script into init.lua.....
Is there anything I am doing different/incorrect??
Re: Making magical melee weapons
Posted: Tue Nov 06, 2012 4:32 pm
by Decayer
akroma222 wrote:I have pasted this script into init.lua.....
Is there anything I am doing different/incorrect??
You need to replace "fblong_sword" with "ice_sabre" (and you might want to put it in objects.lua for clarity's sake).
Re: Making magical melee weapons
Posted: Tue Nov 06, 2012 6:01 pm
by LordGarth
I put this into the items folder.
defineObject{
name = "party",
class = "Party",
editorIcon = 32,
onAttack = function(champ, weapon)
if (weapon ~= nil) and (weapon.name == "fblong_sword") then
if party.facing == 0 then
spawn("fireburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("fireburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("fireburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("fireburst", party.level, party.x-1, party.y, party.facing)
end
end
if (weapon ~= nil) and (weapon.name == "torch") then
if party.facing == 0 then
spawn("fireburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("fireburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("fireburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("fireburst", party.level, party.x-1, party.y, party.facing)
end
end
end
}
defineObject{
name = "fblong_sword",
class = "Item",
uiName = "Longsword of FireBurst",
model = "assets/models/items/long_sword.fbx",
skill = "swords",
gfxIndex = 84,
attackPower = 14,
accuracy = 0,
coolDownTime = 1.5,
attackMethod = "meleeAttack",
attackSwipe = "horizontal",
attackSound = "swipe",
impactSound = "impact_blade",
weight = 3.2,
}
Re: Making magical melee weapons
Posted: Tue Nov 06, 2012 7:17 pm
by akroma222
Oh dear, I can not believe I overlooked changing fblong sword to my weapon (terrible!!!!) ... I think it might be time for some sleep
Thanks for replying guys